4525 |
16 Sep 08 |
nicklas |
1 |
/** |
4525 |
16 Sep 08 |
nicklas |
$Id$ |
4525 |
16 Sep 08 |
nicklas |
3 |
|
4525 |
16 Sep 08 |
nicklas |
Copyright (C) 2006 Nicklas Nordborg |
4525 |
16 Sep 08 |
nicklas |
5 |
|
4525 |
16 Sep 08 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
4525 |
16 Sep 08 |
nicklas |
Available at http://base.thep.lu.se/ |
4525 |
16 Sep 08 |
nicklas |
8 |
|
4525 |
16 Sep 08 |
nicklas |
BASE is free software; you can redistribute it and/or |
4525 |
16 Sep 08 |
nicklas |
modify it under the terms of the GNU General Public License |
4525 |
16 Sep 08 |
nicklas |
as published by the Free Software Foundation; either version 3 |
4525 |
16 Sep 08 |
nicklas |
of the License, or (at your option) any later version. |
4525 |
16 Sep 08 |
nicklas |
13 |
|
4525 |
16 Sep 08 |
nicklas |
BASE is distributed in the hope that it will be useful, |
4525 |
16 Sep 08 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4525 |
16 Sep 08 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4525 |
16 Sep 08 |
nicklas |
GNU General Public License for more details. |
4525 |
16 Sep 08 |
nicklas |
18 |
|
4525 |
16 Sep 08 |
nicklas |
You should have received a copy of the GNU General Public License |
4525 |
16 Sep 08 |
nicklas |
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 |
An extension to the {@link ImportInputStream} class which |
4525 |
16 Sep 08 |
nicklas |
reads from a file on the BASE file system. |
4525 |
16 Sep 08 |
nicklas |
30 |
|
4525 |
16 Sep 08 |
nicklas |
@author nicklas |
4525 |
16 Sep 08 |
nicklas |
@version 2.9 |
4525 |
16 Sep 08 |
nicklas |
@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 |
Create a new import stream that reads data from |
4525 |
16 Sep 08 |
nicklas |
a file in the BASE filesystem. |
4525 |
16 Sep 08 |
nicklas |
@param file The file to read from |
4525 |
16 Sep 08 |
nicklas |
@param offset The offset (in bytes) to start reading from |
4525 |
16 Sep 08 |
nicklas |
@param charset The character set to use when reading the file, |
4525 |
16 Sep 08 |
nicklas |
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 |
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 |
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 |
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 |
Calls {@link File#getCharacterSet()}, unless a character set |
4525 |
16 Sep 08 |
nicklas |
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 |
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 |
} |