com.mongodb.client.gridfs.model.GridFSFile#getLength ( )源码实例Demo

下面列出了com.mongodb.client.gridfs.model.GridFSFile#getLength ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: swellrt   文件: MongoDbStore.java
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();
      }
    };
  }
}
 
源代码2 项目: spring-content   文件: GridFsStoreResource.java
public long contentLength() throws IOException {
	GridFSFile file = gridfs.findOne(query(whereFilename().is(location)));
	if (file == null) {
		return 0L;
	}
	return file.getLength();
}
 
源代码3 项目: hawkbit-extensions   文件: MongoDBArtifactStore.java
/**
 * 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);
        }
    });
}