private void retrieveFile(String fileName, OutputStream out) {
GridFsFile file = findFile(fileName);
Query query = new Query();
query.field("n").orderAscending();
query.field("files_id").is(file.id());
Md5Writer writer = new Md5Writer(out);
for (GridFsChunk chunk : chunkCollection.query(query)) {
writer.write(chunk.data());
}
Assert.isTrue(writer.md5().equalsIgnoreCase(file.md5()), "Invalid checksum " + writer.md5() + "!=" + file.md5());