5224 |
27 Jan 10 |
nicklas |
1 |
/** |
5224 |
27 Jan 10 |
nicklas |
$Id$ |
5224 |
27 Jan 10 |
nicklas |
3 |
|
5224 |
27 Jan 10 |
nicklas |
Copyright (C) 2009 Nicklas Nordborg |
5224 |
27 Jan 10 |
nicklas |
5 |
|
5224 |
27 Jan 10 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
5224 |
27 Jan 10 |
nicklas |
Available at http://base.thep.lu.se/ |
5224 |
27 Jan 10 |
nicklas |
8 |
|
5224 |
27 Jan 10 |
nicklas |
BASE is free software; you can redistribute it and/or |
5224 |
27 Jan 10 |
nicklas |
modify it under the terms of the GNU General Public License |
5224 |
27 Jan 10 |
nicklas |
as published by the Free Software Foundation; either version 3 |
5224 |
27 Jan 10 |
nicklas |
of the License, or (at your option) any later version. |
5224 |
27 Jan 10 |
nicklas |
13 |
|
5224 |
27 Jan 10 |
nicklas |
BASE is distributed in the hope that it will be useful, |
5224 |
27 Jan 10 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
5224 |
27 Jan 10 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
5224 |
27 Jan 10 |
nicklas |
GNU General Public License for more details. |
5224 |
27 Jan 10 |
nicklas |
18 |
|
5224 |
27 Jan 10 |
nicklas |
You should have received a copy of the GNU General Public License |
5224 |
27 Jan 10 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
5224 |
27 Jan 10 |
nicklas |
21 |
*/ |
5224 |
27 Jan 10 |
nicklas |
22 |
package net.sf.basedb.util.bfs; |
5224 |
27 Jan 10 |
nicklas |
23 |
|
5224 |
27 Jan 10 |
nicklas |
24 |
import java.io.FileInputStream; |
5224 |
27 Jan 10 |
nicklas |
25 |
import java.io.FileNotFoundException; |
5224 |
27 Jan 10 |
nicklas |
26 |
import java.io.IOException; |
5224 |
27 Jan 10 |
nicklas |
27 |
import java.io.InputStream; |
5224 |
27 Jan 10 |
nicklas |
28 |
|
5224 |
27 Jan 10 |
nicklas |
29 |
|
5224 |
27 Jan 10 |
nicklas |
30 |
/** |
5224 |
27 Jan 10 |
nicklas |
Input stream locator implementation that works with files on the |
5224 |
27 Jan 10 |
nicklas |
local file system. The files must be located in the specified root |
5224 |
27 Jan 10 |
nicklas |
directory. Subdirectories or parent paths are not supported. |
5224 |
27 Jan 10 |
nicklas |
34 |
|
5224 |
27 Jan 10 |
nicklas |
@author Nicklas |
5224 |
27 Jan 10 |
nicklas |
@version 2.15 |
5224 |
27 Jan 10 |
nicklas |
@base.modified $Date$ |
5224 |
27 Jan 10 |
nicklas |
38 |
*/ |
5224 |
27 Jan 10 |
nicklas |
39 |
public class DiskInputStreamLocator |
5224 |
27 Jan 10 |
nicklas |
40 |
implements InputStreamLocator |
5224 |
27 Jan 10 |
nicklas |
41 |
{ |
5224 |
27 Jan 10 |
nicklas |
42 |
|
5224 |
27 Jan 10 |
nicklas |
43 |
private final java.io.File dir; |
5224 |
27 Jan 10 |
nicklas |
44 |
|
5224 |
27 Jan 10 |
nicklas |
45 |
/** |
5224 |
27 Jan 10 |
nicklas |
Create a new input stream locator. |
5224 |
27 Jan 10 |
nicklas |
@param dir The directory in the local file system in which the |
5224 |
27 Jan 10 |
nicklas |
files should be located |
5224 |
27 Jan 10 |
nicklas |
@throws NullPointerException If the dir parameter is null |
5224 |
27 Jan 10 |
nicklas |
@throws FileNotFoundException If the given path is not an existing directory |
5224 |
27 Jan 10 |
nicklas |
51 |
*/ |
5224 |
27 Jan 10 |
nicklas |
52 |
public DiskInputStreamLocator(java.io.File dir) |
5224 |
27 Jan 10 |
nicklas |
53 |
throws IOException |
5224 |
27 Jan 10 |
nicklas |
54 |
{ |
5224 |
27 Jan 10 |
nicklas |
55 |
if (dir == null) throw new NullPointerException("dir"); |
5224 |
27 Jan 10 |
nicklas |
56 |
if (!dir.isDirectory()) throw new FileNotFoundException(dir.toString()); |
5224 |
27 Jan 10 |
nicklas |
57 |
this.dir = dir; |
5224 |
27 Jan 10 |
nicklas |
58 |
} |
5224 |
27 Jan 10 |
nicklas |
59 |
|
5224 |
27 Jan 10 |
nicklas |
60 |
/** |
5224 |
27 Jan 10 |
nicklas |
Finds and opens an input stream to the file with the given filename. |
5224 |
27 Jan 10 |
nicklas |
62 |
*/ |
5224 |
27 Jan 10 |
nicklas |
63 |
@Override |
5224 |
27 Jan 10 |
nicklas |
64 |
public InputStream getInputStream(String filename) |
5224 |
27 Jan 10 |
nicklas |
65 |
throws IOException |
5224 |
27 Jan 10 |
nicklas |
66 |
{ |
5224 |
27 Jan 10 |
nicklas |
67 |
java.io.File file = new java.io.File(dir, filename); |
5224 |
27 Jan 10 |
nicklas |
68 |
if (!file.exists()) throw new FileNotFoundException("File not found: " + file); |
5224 |
27 Jan 10 |
nicklas |
69 |
return new FileInputStream(file); |
5224 |
27 Jan 10 |
nicklas |
70 |
} |
5224 |
27 Jan 10 |
nicklas |
71 |
|
5225 |
29 Jan 10 |
nicklas |
72 |
@Override |
5225 |
29 Jan 10 |
nicklas |
73 |
public long getSize(String filename) |
5225 |
29 Jan 10 |
nicklas |
74 |
{ |
5225 |
29 Jan 10 |
nicklas |
75 |
java.io.File file = new java.io.File(dir, filename); |
5225 |
29 Jan 10 |
nicklas |
76 |
return file.length(); |
5225 |
29 Jan 10 |
nicklas |
77 |
} |
5225 |
29 Jan 10 |
nicklas |
78 |
|
5224 |
27 Jan 10 |
nicklas |
79 |
} |