下面列出了com.mongodb.client.gridfs.model.GridFSFile#getLength ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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();
}
};
}
}
public long contentLength() throws IOException {
GridFSFile file = gridfs.findOne(query(whereFilename().is(location)));
if (file == null) {
return 0L;
}
return file.getLength();
}
/**
* 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);
}
});
}