use of annis.service.objects.AnnisBinaryMetaData in project ANNIS by korpling.
the class QueryDaoImpl method getBinary.
@Override
public InputStream getBinary(String toplevelCorpusName, String corpusName, String mimeType, String title, int offset, int length) {
AnnisBinaryMetaData binary = (AnnisBinaryMetaData) getJdbcTemplate().query(ByteHelper.SQL, byteHelper.getArgs(toplevelCorpusName, corpusName, mimeType, title, offset, length), ByteHelper.getArgTypes(), byteHelper);
try {
// retrieve the requested part of the file from the data directory
File dataFile = new File(getRealDataDir(), binary.getLocalFileName());
long fileSize = dataFile.length();
Preconditions.checkArgument(offset + length <= fileSize, "Range larger than the actual file size requested. Actual file size is %d bytes, %d bytes were requested.", fileSize, offset + length);
FileInputStream fInput = new FileInputStream(dataFile);
ByteStreams.skipFully(fInput, offset);
return ByteStreams.limit(fInput, length);
} catch (FileNotFoundException ex) {
log.warn("Media file from database not found in data directory", ex);
} catch (IOException ex) {
log.warn("Error when reading media file from the data directory", ex);
}
return new ByteArrayInputStream(new byte[0]);
}
Aggregations