private void writeResponse(GridFSDBFile file, HttpServletResponse response) throws IOException {
   if (file != null) {
     byte[] data = IOUtils.toByteArray(file.getInputStream());
     response.setContentType(file.getContentType());
     response.setContentLength((int) file.getLength());
     response.getOutputStream().write(data);
     response.getOutputStream().flush();
   } else {
     response.setStatus(HttpStatus.NOT_FOUND.value());
   }
 }