public Integer execute() throws Exception {
return fetchBlobFromMongo();
}
private int fetchBlobFromMongo() throws Exception {
GridFSDBFile gridFile = gridFS.findOne(new BasicDBObject("md5", blobId));
long fileLength = gridFile.getLength();
long start = blobOffset;
long end = blobOffset + length;
if (end > fileLength) {
end = fileLength;
}
length = (int) (end - start);
if (start < end) {
InputStream is = gridFile.getInputStream();
if (blobOffset > 0) {
IOUtils.skipFully(is, blobOffset);
}
IOUtils.readFully(is, buffer, bufferOffset, length);
is.close();