src/core/net/sf/basedb/util/FileImportInputStream.java

Code
Comments
Other
Rev Date Author Line
4525 16 Sep 08 nicklas 1 /**
4525 16 Sep 08 nicklas 2   $Id$
4525 16 Sep 08 nicklas 3
4525 16 Sep 08 nicklas 4   Copyright (C) 2006 Nicklas Nordborg
4525 16 Sep 08 nicklas 5
4525 16 Sep 08 nicklas 6   This file is part of BASE - BioArray Software Environment.
4525 16 Sep 08 nicklas 7   Available at http://base.thep.lu.se/
4525 16 Sep 08 nicklas 8
4525 16 Sep 08 nicklas 9   BASE is free software; you can redistribute it and/or
4525 16 Sep 08 nicklas 10   modify it under the terms of the GNU General Public License
4525 16 Sep 08 nicklas 11   as published by the Free Software Foundation; either version 3
4525 16 Sep 08 nicklas 12   of the License, or (at your option) any later version.
4525 16 Sep 08 nicklas 13
4525 16 Sep 08 nicklas 14   BASE is distributed in the hope that it will be useful,
4525 16 Sep 08 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
4525 16 Sep 08 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4525 16 Sep 08 nicklas 17   GNU General Public License for more details.
4525 16 Sep 08 nicklas 18
4525 16 Sep 08 nicklas 19   You should have received a copy of the GNU General Public License
4525 16 Sep 08 nicklas 20   along with BASE. If not, see <http://www.gnu.org/licenses/>.
4525 16 Sep 08 nicklas 21 */
4525 16 Sep 08 nicklas 22 package net.sf.basedb.util;
4525 16 Sep 08 nicklas 23
4525 16 Sep 08 nicklas 24 import net.sf.basedb.core.File;
4525 16 Sep 08 nicklas 25 import net.sf.basedb.core.plugin.ImportInputStream;
4525 16 Sep 08 nicklas 26
4525 16 Sep 08 nicklas 27 /**
4525 16 Sep 08 nicklas 28    An extension to the {@link ImportInputStream} class which 
4525 16 Sep 08 nicklas 29    reads from a file on the BASE file system.
4525 16 Sep 08 nicklas 30
4525 16 Sep 08 nicklas 31   @author nicklas
4525 16 Sep 08 nicklas 32   @version 2.9
4525 16 Sep 08 nicklas 33   @base.modified $Date$
4525 16 Sep 08 nicklas 34 */
4525 16 Sep 08 nicklas 35 public class FileImportInputStream
4525 16 Sep 08 nicklas 36   extends ImportInputStream
4525 16 Sep 08 nicklas 37 {
4525 16 Sep 08 nicklas 38   private final File file;
4525 16 Sep 08 nicklas 39   private final String charset;
4525 16 Sep 08 nicklas 40
4525 16 Sep 08 nicklas 41   /**
4525 16 Sep 08 nicklas 42     Create a new import stream that reads data from 
4525 16 Sep 08 nicklas 43     a file in the BASE filesystem.
4525 16 Sep 08 nicklas 44     @param file The file to read from
4525 16 Sep 08 nicklas 45     @param offset The offset (in bytes) to start reading from
4525 16 Sep 08 nicklas 46     @param charset The character set to use when reading the file,
4525 16 Sep 08 nicklas 47       or null to use {@link File#getCharacterSet()}.
4525 16 Sep 08 nicklas 48   */
4525 16 Sep 08 nicklas 49   public FileImportInputStream(File file, long offset, String charset)
4525 16 Sep 08 nicklas 50   {
5353 27 May 10 nicklas 51     super(offset == 0 ? file.getCachedDownloadStream() : file.getDownloadStream(offset));
4525 16 Sep 08 nicklas 52     this.file = file;
4525 16 Sep 08 nicklas 53     this.charset = charset == null ? file.getCharacterSet() : charset;
4525 16 Sep 08 nicklas 54   }
4525 16 Sep 08 nicklas 55   
4525 16 Sep 08 nicklas 56   /*
4525 16 Sep 08 nicklas 57      From the ImportInputStream class
4525 16 Sep 08 nicklas 58      ---------------------------------
4525 16 Sep 08 nicklas 59   */
4525 16 Sep 08 nicklas 60   /**
4525 16 Sep 08 nicklas 61     Calls {@link File#getSize()} to get the file size.
4525 16 Sep 08 nicklas 62   */
4525 16 Sep 08 nicklas 63   @Override
4525 16 Sep 08 nicklas 64   public long getLength()
4525 16 Sep 08 nicklas 65   {
4525 16 Sep 08 nicklas 66     return file.getSize();
4525 16 Sep 08 nicklas 67   }
4525 16 Sep 08 nicklas 68   /**
4525 16 Sep 08 nicklas 69     Calls {@link File#getMimeType()}.
4525 16 Sep 08 nicklas 70   */
4525 16 Sep 08 nicklas 71   @Override
4525 16 Sep 08 nicklas 72   public String getMimeType()
4525 16 Sep 08 nicklas 73   {
4525 16 Sep 08 nicklas 74     return file.getMimeType();
4525 16 Sep 08 nicklas 75   }
4525 16 Sep 08 nicklas 76   /**
4525 16 Sep 08 nicklas 77     Calls {@link File#getCharacterSet()}, unless a character set
4525 16 Sep 08 nicklas 78     was specified in the constructor.
4525 16 Sep 08 nicklas 79   */
4525 16 Sep 08 nicklas 80   @Override
4525 16 Sep 08 nicklas 81   public String getCharacterSet()
4525 16 Sep 08 nicklas 82   {
4525 16 Sep 08 nicklas 83     return charset;
4525 16 Sep 08 nicklas 84   }
4525 16 Sep 08 nicklas 85   /**
4525 16 Sep 08 nicklas 86     Calls {@link File#getName()}.
4525 16 Sep 08 nicklas 87   */
4525 16 Sep 08 nicklas 88   @Override
4525 16 Sep 08 nicklas 89   public String getFilename()
4525 16 Sep 08 nicklas 90   {
4525 16 Sep 08 nicklas 91     return file.getName();
4525 16 Sep 08 nicklas 92   }
4525 16 Sep 08 nicklas 93   // -------------------------------------------
4525 16 Sep 08 nicklas 94 }