return getDocumentFile(d.getID(), filename);
}
private DocumentFile<MongoType> getDocumentFile(DocumentID<MongoType> id, String filename) {
DBObject query = QueryBuilder.start(DOCUMENT_KEY).is(id.getID()).and(FILENAME_KEY).is(filename).get();
GridFSDBFile file = documentfs.findOne(query);
if(file==null) {
return null;
}
DocumentFile<MongoType> df = new DocumentFile<MongoType>(id, file.getFilename(), file.getInputStream(), (String)file.get(STAGE_KEY), file.getUploadDate());
if(file.containsField(MIMETYPE_KEY)) {
df.setMimetype((String) file.get(MIMETYPE_KEY));
}
if(file.containsField(ENCODING_KEY)) {
df.setEncoding((String) file.get(ENCODING_KEY));
}
return df;
}