Java Code Examples for com.mongodb.client.gridfs.model.GridFSFile#getLength()

The following examples show how to use com.mongodb.client.gridfs.model.GridFSFile#getLength() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MongoDbStore.java    From swellrt with Apache License 2.0 6 votes vote down vote up
private AttachmentData fileToAttachmentData(final GridFSFile attachmentFile) {
  if (attachmentFile == null) {
    return null;
  } else {
    return new AttachmentData() {

      @Override
      public InputStream getInputStream() throws IOException {
        return attachmentGrid.openDownloadStream(attachmentFile.getObjectId());
      }

      @Override
      public long getSize() {
        return attachmentFile.getLength();
      }
    };
  }
}
 
Example 2
Source File: GridFsStoreResource.java    From spring-content with Apache License 2.0 5 votes vote down vote up
public long contentLength() throws IOException {
	GridFSFile file = gridfs.findOne(query(whereFilename().is(location)));
	if (file == null) {
		return 0L;
	}
	return file.getLength();
}
 
Example 3
Source File: MongoDBArtifactStore.java    From hawkbit-extensions with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Maps a single {@link GridFSFile} to {@link GridFsArtifact}.
 *
 * @param file
 *            the {@link GridFSFile} object.
 * @param contentType
 *            the content type of the artifact
 * @param hashes
 *            the {@link DbArtifactHash} object of the artifact
 * @return a mapped artifact from the given file
 */
private GridFsArtifact createGridFsArtifact(final GridFSFile file, final String contentType,
        final DbArtifactHash hashes) {
    if (file == null) {
        return null;
    }
    return new GridFsArtifact(file.getId().toString(), hashes, file.getLength(), contentType, () -> {
        try {
            return gridFs.getResource(file).getInputStream();
        } catch (final IllegalStateException | IOException e) {
            throw new ArtifactStoreException(e.getMessage(), e);
        }
    });
}