本文整理汇总了Java中com.mongodb.client.gridfs.model.GridFSFile类的典型用法代码示例。如果您正苦于以下问题:Java GridFSFile类的具体用法?Java GridFSFile怎么用?Java GridFSFile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GridFSFile类属于com.mongodb.client.gridfs.model包,在下文中一共展示了GridFSFile类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: validateAfterStoreAdd
import com.mongodb.client.gridfs.model.GridFSFile; //导入依赖的package包/类
@Override
protected void validateAfterStoreAdd(TestContext context, Vertx vertx,
String path, Handler<AsyncResult<Void>> handler) {
vertx.executeBlocking(f -> {
try (MongoClient client = new MongoClient(mongoConnector.serverAddress)) {
MongoDatabase db = client.getDatabase(MongoDBTestConnector.MONGODB_DBNAME);
GridFSBucket gridFS = GridFSBuckets.create(db);
GridFSFindIterable files = gridFS.find();
GridFSFile file = files.first();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
gridFS.downloadToStream(file.getFilename(), baos);
String contents = new String(baos.toByteArray(), StandardCharsets.UTF_8);
context.assertEquals(CHUNK_CONTENT, contents);
}
f.complete();
}, handler);
}
开发者ID:georocket,项目名称:georocket,代码行数:20,代码来源:MongoDBStoreTest.java
示例2: checkAndCleanup
import com.mongodb.client.gridfs.model.GridFSFile; //导入依赖的package包/类
public boolean checkAndCleanup(String userId, String fileName) {
List<Document> l = query(new Query().equals(USERID, userId).addSortCriteria(CREATION_TIME, false));
if (l.size() >= maxPersistedPagesPerUser) {
Document oldest = l.iterator().next();
if ((System.currentTimeMillis() - oldest.get(CREATION_TIME).getTime()) < minimumDelay) {
//there have been to many page persistences for this user in a short time, so don't persist
return false;
} else {
//clean up oldest to free space for new persisted page
gridFS.find(Filters.eq("filename", oldest.get(FILENAME))).forEach(new Block<GridFSFile>() {
@Override
public void apply(GridFSFile file) {
gridFS.delete(file.getObjectId());
}
});
oldest.delete();
}
}
//create new entry
Document newOne = createNew();
newOne.set(USERID, userId);
newOne.set(FILENAME, fileName);
newOne.set(CREATION_TIME, new Date());
newOne.writeToDatabase(false);
return true;
}
开发者ID:KAOREND,项目名称:reactive-hamster,代码行数:27,代码来源:PersistedPages.java
示例3: byPages
import com.mongodb.client.gridfs.model.GridFSFile; //导入依赖的package包/类
@Override
public void byPages(int pageSize, Callback callback) {
MongoCursor<GridFSFile> cursor = bucket.find().iterator();
boolean loop = true;
try {
while (loop) {
List<GridFSFile> files = new ArrayList<>(batchSize);
int i = 0;
while (cursor.hasNext() && i < batchSize) {
files.add(cursor.next());
i++;
}
loop = callback.on(files.stream().map(file -> bucket.openDownloadStream(file.getObjectId())).map(fromFile).collect(Collectors.toList()));
}
} finally {
cursor.close();
}
}
开发者ID:Treydone,项目名称:mandrel,代码行数:19,代码来源:MongoBlobStore.java
示例4: getAssociatedDocumentStream
import com.mongodb.client.gridfs.model.GridFSFile; //导入依赖的package包/类
@Override
public InputStream getAssociatedDocumentStream(String uniqueId, String fileName) {
GridFSBucket gridFS = createGridFSConnection();
GridFSFile file = gridFS.find(new Document(ASSOCIATED_METADATA + "." + FILE_UNIQUE_ID_KEY, getGridFsId(uniqueId, fileName))).first();
if (file == null) {
return null;
}
InputStream is = gridFS.openDownloadStream(file.getObjectId());
;
Document metadata = file.getMetadata();
if (metadata.containsKey(COMPRESSED_FLAG)) {
boolean compressed = (boolean) metadata.remove(COMPRESSED_FLAG);
if (compressed) {
is = new InflaterInputStream(is);
}
}
return is;
}
开发者ID:lumongo,项目名称:lumongo,代码行数:23,代码来源:MongoDocumentStorage.java
示例5: findMetadata
import com.mongodb.client.gridfs.model.GridFSFile; //导入依赖的package包/类
public Document findMetadata(String oid) {
GridFSFile first = fileStore.find(eq("_id", new ObjectId(oid))).first();
if(first == null) {
return null;
} else {
return first.getMetadata();
}
}
开发者ID:ccem-dev,项目名称:otus-api,代码行数:9,代码来源:FileStoreBucket.java
示例6: toSmofGridRef
import com.mongodb.client.gridfs.model.GridFSFile; //导入依赖的package包/类
private SmofGridRef toSmofGridRef(BsonDocument refBson) {
final String bucketName = refBson.getString("bucket").getValue();
final ObjectId id = refBson.getObjectId("id").getValue();
final SmofGridRef ref = SmofGridRefFactory.newFromDB(id, bucketName);
final GridFSFile file = dispatcher.loadMetadata(ref);
ref.putMetadata(file.getMetadata());
return ref;
}
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:9,代码来源:ObjectParser.java
示例7: testMetadata
import com.mongodb.client.gridfs.model.GridFSFile; //导入依赖的package包/类
@Test
public final void testMetadata() throws IOException {
final Document metadata = new Document("randomkey", 45);
ref.putMetadata(metadata);
streamManager.uploadFile(ref);
ref.putMetadata(new Document());
final GridFSFile file = streamManager.loadFileMetadata(ref);
assertEquals(metadata, file.getMetadata());
}
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:10,代码来源:SmofGridStreamManagerTest.java
示例8: deleteFile
import com.mongodb.client.gridfs.model.GridFSFile; //导入依赖的package包/类
public void deleteFile(Document mo) {
String filename = mo.get(this);
if (filename != null) {
fileSystemProvider.getFileSystem().find(Filters.eq("filename", filename)).forEach(new Block<GridFSFile>() {
@Override
public void apply(GridFSFile file) {
fileSystemProvider.getFileSystem().delete(file.getObjectId());
}
});
mo.getDataObject().remove(this.getName());
// mo.writeToDatabase(false);
}
}
开发者ID:KAOREND,项目名称:reactive-hamster,代码行数:14,代码来源:FileAttribute.java
示例9: first
import com.mongodb.client.gridfs.model.GridFSFile; //导入依赖的package包/类
@Override
public Observable<GridFSFile> first() {
return RxObservables.create(Observables.observe(new Block<SingleResultCallback<GridFSFile>>(){
@Override
public void apply(final SingleResultCallback<GridFSFile> callback) {
wrapped.first(callback);
}
}), observableAdapter);
}
开发者ID:mongodb,项目名称:mongo-java-driver-rx,代码行数:10,代码来源:GridFSFindObservableImpl.java
示例10: getGridFSFile
import com.mongodb.client.gridfs.model.GridFSFile; //导入依赖的package包/类
@Override
public Observable<GridFSFile> getGridFSFile() {
return RxObservables.create(Observables.observe(new Block<SingleResultCallback<GridFSFile>>() {
@Override
public void apply(final SingleResultCallback<GridFSFile> callback) {
wrapped.getGridFSFile(callback);
}
}), observableAdapter);
}
开发者ID:mongodb,项目名称:mongo-java-driver-rx,代码行数:10,代码来源:GridFSDownloadStreamImpl.java
示例11: getGridFSFile
import com.mongodb.client.gridfs.model.GridFSFile; //导入依赖的package包/类
@Override
public Publisher<GridFSFile> getGridFSFile() {
return new ObservableToPublisher<GridFSFile>(observe(new Block<SingleResultCallback<GridFSFile>>() {
@Override
public void apply(final SingleResultCallback<GridFSFile> callback) {
wrapped.getGridFSFile(callback);
}
}));
}
开发者ID:mongodb,项目名称:mongo-java-driver-reactivestreams,代码行数:10,代码来源:GridFSDownloadStreamImpl.java
示例12: first
import com.mongodb.client.gridfs.model.GridFSFile; //导入依赖的package包/类
@Override
public Publisher<GridFSFile> first() {
return new ObservableToPublisher<GridFSFile>(observe(new Block<SingleResultCallback<GridFSFile>>(){
@Override
public void apply(final SingleResultCallback<GridFSFile> callback) {
wrapped.first(callback);
}
}));
}
开发者ID:mongodb,项目名称:mongo-java-driver-reactivestreams,代码行数:10,代码来源:GridFSFindPublisherImpl.java
示例13: deleteFile
import com.mongodb.client.gridfs.model.GridFSFile; //导入依赖的package包/类
@Override
public OperationResult deleteFile(
final Database db,
final String dbName,
final String bucketName,
final BsonValue fileId,
final String requestEtag,
final boolean checkEtag) {
final String bucket = extractBucketName(bucketName);
GridFSBucket gridFSBucket = GridFSBuckets.create(
db.getDatabase(dbName),
bucket);
GridFSFile file = gridFSBucket
.find(eq("_id", fileId))
.limit(1).iterator().tryNext();
if (file == null) {
return new OperationResult(HttpStatus.SC_NOT_FOUND);
} else if (checkEtag) {
Object oldEtag = file.getMetadata().get("_etag");
if (oldEtag != null) {
if (requestEtag == null) {
return new OperationResult(HttpStatus.SC_CONFLICT, oldEtag);
} else if (!Objects.equals(oldEtag.toString(), requestEtag)) {
return new OperationResult(
HttpStatus.SC_PRECONDITION_FAILED, oldEtag);
}
}
}
gridFSBucket.delete(fileId);
return new OperationResult(HttpStatus.SC_NO_CONTENT);
}
开发者ID:SoftInstigate,项目名称:restheart,代码行数:38,代码来源:GridFsDAO.java
示例14: handleRequest
import com.mongodb.client.gridfs.model.GridFSFile; //导入依赖的package包/类
@Override
public void handleRequest(
HttpServerExchange exchange,
RequestContext context)
throws Exception {
if (context.isInError()) {
next(exchange, context);
return;
}
LOGGER.trace("GET " + exchange.getRequestURL());
final String bucket = extractBucketName(context.getCollectionName());
GridFSBucket gridFSBucket = GridFSBuckets.create(
MongoDBClientSingleton.getInstance().getClient()
.getDatabase(context.getDBName()),
bucket);
GridFSFile dbsfile = gridFSBucket
.find(eq("_id", context.getDocumentId()))
.limit(1).iterator().tryNext();
if (dbsfile == null) {
fileNotFound(context, exchange);
} else if (!checkEtag(exchange, dbsfile)) {
sendBinaryContent(context, gridFSBucket, dbsfile, exchange);
}
next(exchange, context);
}
开发者ID:SoftInstigate,项目名称:restheart,代码行数:31,代码来源:GetFileBinaryHandler.java
示例15: checkEtag
import com.mongodb.client.gridfs.model.GridFSFile; //导入依赖的package包/类
private boolean checkEtag(HttpServerExchange exchange, GridFSFile dbsfile) {
if (dbsfile != null) {
Object etag;
if (dbsfile.getMetadata() != null
&& dbsfile.getMetadata().containsKey("_etag")) {
etag = dbsfile.getMetadata().get("_etag");
} else {
etag = null;
}
if (etag != null && etag instanceof ObjectId) {
ObjectId _etag = (ObjectId) etag;
BsonObjectId __etag = new BsonObjectId(_etag);
// in case the request contains the IF_NONE_MATCH header with the current etag value,
// just return 304 NOT_MODIFIED code
if (RequestHelper.checkReadEtag(exchange, __etag)) {
exchange.setStatusCode(HttpStatus.SC_NOT_MODIFIED);
exchange.endExchange();
return true;
}
}
}
return false;
}
开发者ID:SoftInstigate,项目名称:restheart,代码行数:29,代码来源:GetFileBinaryHandler.java
示例16: getAssociatedDocuments
import com.mongodb.client.gridfs.model.GridFSFile; //导入依赖的package包/类
@Override
public List<AssociatedDocument> getAssociatedDocuments(String uniqueId, FetchType fetchType) throws Exception {
GridFSBucket gridFS = createGridFSConnection();
List<AssociatedDocument> assocDocs = new ArrayList<>();
if (!FetchType.NONE.equals(fetchType)) {
GridFSFindIterable files = gridFS.find(new Document(ASSOCIATED_METADATA + "." + DOCUMENT_UNIQUE_ID_KEY, uniqueId));
for (GridFSFile file : files) {
AssociatedDocument ad = loadGridFSToAssociatedDocument(gridFS, file, fetchType);
assocDocs.add(ad);
}
}
return assocDocs;
}
开发者ID:lumongo,项目名称:lumongo,代码行数:15,代码来源:MongoDocumentStorage.java
示例17: getAssociatedDocument
import com.mongodb.client.gridfs.model.GridFSFile; //导入依赖的package包/类
@Override
public AssociatedDocument getAssociatedDocument(String uniqueId, String fileName, FetchType fetchType) throws Exception {
GridFSBucket gridFS = createGridFSConnection();
if (!FetchType.NONE.equals(fetchType)) {
GridFSFile file = gridFS.find(new Document(ASSOCIATED_METADATA + "." + FILE_UNIQUE_ID_KEY, getGridFsId(uniqueId, fileName))).first();
if (null != file) {
return loadGridFSToAssociatedDocument(gridFS, file, fetchType);
}
}
return null;
}
开发者ID:lumongo,项目名称:lumongo,代码行数:12,代码来源:MongoDocumentStorage.java
示例18: loadGridFSToAssociatedDocument
import com.mongodb.client.gridfs.model.GridFSFile; //导入依赖的package包/类
private AssociatedDocument loadGridFSToAssociatedDocument(GridFSBucket gridFS, GridFSFile file, FetchType fetchType) throws IOException {
AssociatedDocument.Builder aBuilder = AssociatedDocument.newBuilder();
aBuilder.setFilename(file.getFilename());
Document metadata = file.getMetadata();
boolean compressed = false;
if (metadata.containsKey(COMPRESSED_FLAG)) {
compressed = (boolean) metadata.remove(COMPRESSED_FLAG);
}
long timestamp = (long) metadata.remove(TIMESTAMP);
aBuilder.setCompressed(compressed);
aBuilder.setTimestamp(timestamp);
aBuilder.setDocumentUniqueId((String) metadata.remove(DOCUMENT_UNIQUE_ID_KEY));
for (String field : metadata.keySet()) {
aBuilder.addMetadata(Metadata.newBuilder().setKey(field).setValue((String) metadata.get(field)));
}
if (FetchType.FULL.equals(fetchType)) {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
gridFS.downloadToStream(file.getObjectId(), byteArrayOutputStream);
byte[] bytes = byteArrayOutputStream.toByteArray();
if (null != bytes) {
if (compressed) {
bytes = CommonCompression.uncompressZlib(bytes);
}
aBuilder.setDocument(ByteString.copyFrom(bytes));
}
}
aBuilder.setIndexName(indexName);
return aBuilder.build();
}
开发者ID:lumongo,项目名称:lumongo,代码行数:36,代码来源:MongoDocumentStorage.java
示例19: getAssociatedFilenames
import com.mongodb.client.gridfs.model.GridFSFile; //导入依赖的package包/类
@Override
public List<String> getAssociatedFilenames(String uniqueId) throws Exception {
GridFSBucket gridFS = createGridFSConnection();
ArrayList<String> fileNames = new ArrayList<>();
gridFS.find(new Document(ASSOCIATED_METADATA + "." + DOCUMENT_UNIQUE_ID_KEY, uniqueId))
.forEach((Consumer<com.mongodb.client.gridfs.model.GridFSFile>) gridFSFile -> fileNames.add(gridFSFile.getFilename()));
return fileNames;
}
开发者ID:lumongo,项目名称:lumongo,代码行数:10,代码来源:MongoDocumentStorage.java
示例20: deleteAssociatedDocument
import com.mongodb.client.gridfs.model.GridFSFile; //导入依赖的package包/类
@Override
public void deleteAssociatedDocument(String uniqueId, String fileName) {
GridFSBucket gridFS = createGridFSConnection();
gridFS.find(new Document(ASSOCIATED_METADATA + "." + FILE_UNIQUE_ID_KEY, getGridFsId(uniqueId, fileName)))
.forEach((Block<com.mongodb.client.gridfs.model.GridFSFile>) gridFSFile -> gridFS.delete(gridFSFile.getObjectId()));
}
开发者ID:lumongo,项目名称:lumongo,代码行数:8,代码来源:MongoDocumentStorage.java
注:本文中的com.mongodb.client.gridfs.model.GridFSFile类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论