@Override public ByteArrayFileCache getBlob(final MD5 md5, final ByteArrayFileCacheManager bafcMan) throws NoSuchBlobException, BlobStoreCommunicationException, FileCacheIOException, FileCacheLimitExceededException { final GridFSDBFile out; try { out = getFile(md5); if (out == null) { throw new NoSuchBlobException( "Attempt to retrieve non-existant blob with chksum " + md5.getMD5()); } final boolean sorted; if (!out.containsField(Fields.GFS_SORTED)) { sorted = false; } else { sorted = (Boolean) out.get(Fields.GFS_SORTED); } final InputStream file = out.getInputStream(); try { return bafcMan.createBAFC(file, true, sorted); } finally { try { file.close(); } catch (IOException ioe) { throw new RuntimeException("Something is broken", ioe); } } } catch (MongoException me) { throw new BlobStoreCommunicationException("Could not read from the mongo database", me); } }