NIHVIVO-160 FileStorage.getInputStream returns an InputStream, instead of an array of bytes. Read it however you like.
This commit is contained in:
parent
b86ec9e7b2
commit
f40e2d1af7
3 changed files with 19 additions and 35 deletions
|
@ -17,7 +17,7 @@ public interface FileStorage {
|
|||
* {@link ConfigurationProperties} for the file storage base directory.
|
||||
*/
|
||||
String PROPERTY_FILE_STORAGE_BASE_DIR = "upload.directory";
|
||||
|
||||
|
||||
/**
|
||||
* The default implementation will use this key to ask
|
||||
* {@link ConfigurationProperties} for the default URI namespace.
|
||||
|
@ -28,7 +28,7 @@ public interface FileStorage {
|
|||
* How often to we insert path separator characters?
|
||||
*/
|
||||
int SHORTY_LENGTH = 3;
|
||||
|
||||
|
||||
/**
|
||||
* Store the bytes from this stream as a file with the specified ID and
|
||||
* filename. If the file already exists, it is over-written.
|
||||
|
@ -50,13 +50,15 @@ public interface FileStorage {
|
|||
String getFilename(String id) throws IOException;
|
||||
|
||||
/**
|
||||
* Get the contents of the file with this ID and this filename.
|
||||
* Get a stream that will provide the contents of the file that was stored
|
||||
* with this ID and this filename. Close the stream when you're finished
|
||||
* with it.
|
||||
*
|
||||
* @throws FileNotFoundException
|
||||
* if there is no file that matches this ID and filename.
|
||||
*/
|
||||
byte[] getFile(String id, String filename) throws FileNotFoundException,
|
||||
IOException;
|
||||
InputStream getInputStream(String id, String filename)
|
||||
throws FileNotFoundException, IOException;
|
||||
|
||||
/**
|
||||
* If a file exists with this ID, it will be deleted, regardless of the file
|
||||
|
|
|
@ -4,7 +4,6 @@ package edu.cornell.mannlib.vitro.webapp.utils.filestorage;
|
|||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.io.FileInputStream;
|
||||
|
@ -64,7 +63,8 @@ public class FileStorageImpl implements FileStorage {
|
|||
* if the configuration property doesn't point to an existing,
|
||||
* writeable directory.
|
||||
*/
|
||||
FileStorageImpl(File baseDir, Collection<String> namespaces) throws IOException {
|
||||
FileStorageImpl(File baseDir, Collection<String> namespaces)
|
||||
throws IOException {
|
||||
checkBaseDirValid(baseDir);
|
||||
checkNamespacesValid(namespaces);
|
||||
|
||||
|
@ -347,12 +347,10 @@ public class FileStorageImpl implements FileStorage {
|
|||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @throws IOException
|
||||
* if the file is larger than the maximum allowable size.
|
||||
*/
|
||||
@Override
|
||||
public byte[] getFile(String id, String filename) throws IOException {
|
||||
public InputStream getInputStream(String id, String filename)
|
||||
throws IOException {
|
||||
|
||||
File file = FileStorageHelper.getFullPath(this.rootDir, id, filename,
|
||||
this.namespacesMap);
|
||||
|
@ -362,25 +360,6 @@ public class FileStorageImpl implements FileStorage {
|
|||
+ "', file location '" + file + "'");
|
||||
}
|
||||
|
||||
InputStream in = null;
|
||||
try {
|
||||
in = new BufferedInputStream(new FileInputStream(file));
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
byte[] buffer = new byte[4096];
|
||||
int howMany;
|
||||
while (-1 != (howMany = in.read(buffer))) {
|
||||
bytes.write(buffer, 0, howMany);
|
||||
}
|
||||
bytes.close();
|
||||
return bytes.toByteArray();
|
||||
} finally {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return new FileInputStream(file);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue