* @param events
* @throws StorageServletException
*/
public void retrieveFile(String file, HttpServletResponse response)
throws StorageException {
IFile webStream = null;
InputStream in;
ServletOutputStream out;
byte[] buf;
int nread;
String mime;
try {
webStream = this.datasource.getRoot().getFileItem(file);
mime = getMime(file);
mime = (mime == null) ? mimeFactory.createMime(FileUtils
.getFileExtension(file)) : mime;
response.setContentType(mime);
response.setContentLength(webStream.getLength());
in = webStream.openRead();
try {
out = response.getOutputStream();
buf = new byte[BUFFER_2K];
while ((nread = in.read(buf)) > 0) {
out.write(buf, 0, nread);
out.flush();
}
} finally {
in.close();
}
} catch (NetfeverException e) {
throw new StorageException(e.getDetails(), e);
} catch (IOException e) {
UUID uuid = UUID.randomUUID();
throw new StorageException(
new FaultDetails(
uuid.toString(),
0,
"Streaming error. Contact administrator with id " + uuid,
"Error reading stream " +
webStream.getAbsoluteName() +
" with error " +
e.getMessage(),
null),
e);
}