private void downloadToStream(final GridFSDownloadStream downloadStream, final OutputStream destination) { byte[] buffer = new byte[downloadStream.getGridFSFile().getChunkSize()]; int len; MongoGridFSException savedThrowable = null; try { while ((len = downloadStream.read(buffer)) != -1) { destination.write(buffer, 0, len); } } catch (IOException e) { savedThrowable = new MongoGridFSException("IOException when reading from the OutputStream", e); } catch (Exception e) { savedThrowable = new MongoGridFSException("Unexpected Exception when reading GridFS and writing to the Stream", e); } finally { try { downloadStream.close(); } catch (Exception e) { // Do nothing } if (savedThrowable != null) { throw savedThrowable; } } } }
public InputStream open() { ds = getBucket().openDownloadStream(mongoFileId); GridFSFile file = ds.getGridFSFile(); mongoFileId = file.getObjectId(); // setMetadataDoc(file.getMetadata()); return ds; }
public Long size() { if (ds == null) { ds = getBucket().openDownloadStream(mongoFileId); } return ds.getGridFSFile().getLength(); }
private void downloadToStream(final GridFSDownloadStream downloadStream, final OutputStream destination) { byte[] buffer = new byte[downloadStream.getGridFSFile().getChunkSize()]; int len; MongoGridFSException savedThrowable = null; try { while ((len = downloadStream.read(buffer)) != -1) { destination.write(buffer, 0, len); } } catch (IOException e) { savedThrowable = new MongoGridFSException("IOException when reading from the OutputStream", e); } catch (Exception e) { savedThrowable = new MongoGridFSException("Unexpected Exception when reading GridFS and writing to the Stream", e); } finally { try { downloadStream.close(); } catch (Exception e) { // Do nothing } if (savedThrowable != null) { throw savedThrowable; } } } }
private void downloadToStream(final GridFSDownloadStream downloadStream, final OutputStream destination) { byte[] buffer = new byte[downloadStream.getGridFSFile().getChunkSize()]; int len; MongoGridFSException savedThrowable = null; try { while ((len = downloadStream.read(buffer)) != -1) { destination.write(buffer, 0, len); } } catch (IOException e) { savedThrowable = new MongoGridFSException("IOException when reading from the OutputStream", e); } catch (Exception e) { savedThrowable = new MongoGridFSException("Unexpected Exception when reading GridFS and writing to the Stream", e); } finally { try { downloadStream.close(); } catch (Exception e) { // Do nothing } if (savedThrowable != null) { throw savedThrowable; } } } }