use of com.mongodb.client.gridfs.GridFSBucket in project georocket by georocket.
the class MongoDBChunkReadStreamTest method getChunkSize.
/**
* Connect to MongoDB and get the GridFS chunk size
* @param vertx the Vert.x instance
* @param handler a handler that will be called with the chunk size
*/
private void getChunkSize(Vertx vertx, Handler<AsyncResult<Integer>> handler) {
vertx.<Integer>executeBlocking(f -> {
try (MongoClient client = new MongoClient(mongoConnector.serverAddress)) {
MongoDatabase db = client.getDatabase(MongoDBTestConnector.MONGODB_DBNAME);
GridFSBucket gridFS = GridFSBuckets.create(db);
f.complete(gridFS.getChunkSizeBytes());
}
}, handler);
}
use of com.mongodb.client.gridfs.GridFSBucket in project georocket by georocket.
the class MongoDBChunkReadStreamTest method prepareData.
/**
* Create a file in GridFS with the given filename and write
* some random data to it.
* @param filename the name of the file to create
* @param size the number of random bytes to write
* @param vertx the Vert.x instance
* @param handler a handler that will be called when the file
* has been written
*/
private void prepareData(String filename, int size, Vertx vertx, Handler<AsyncResult<String>> handler) {
vertx.<String>executeBlocking(f -> {
try (MongoClient client = new MongoClient(mongoConnector.serverAddress)) {
MongoDatabase db = client.getDatabase(MongoDBTestConnector.MONGODB_DBNAME);
GridFSBucket gridFS = GridFSBuckets.create(db);
try (GridFSUploadStream os = gridFS.openUploadStream(filename)) {
for (int i = 0; i < size; ++i) {
os.write((byte) (i & 0xFF));
}
}
}
f.complete(filename);
}, handler);
}
use of com.mongodb.client.gridfs.GridFSBucket in project georocket by georocket.
the class MongoDBStoreTest method validateAfterStoreDelete.
@Override
protected void validateAfterStoreDelete(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();
context.assertTrue(Iterables.isEmpty(files));
}
f.complete();
}, handler);
}
use of com.mongodb.client.gridfs.GridFSBucket in project mongo-java-driver by mongodb.
the class UnifiedGridFSHelper method executeDelete.
OperationResult executeDelete(final BsonDocument operation) {
GridFSBucket bucket = entities.getBucket(operation.getString("object").getValue());
BsonDocument arguments = operation.getDocument("arguments");
BsonValue id = arguments.get("id");
if (arguments.size() > 1) {
throw new UnsupportedOperationException("Unexpected arguments");
}
requireNonNull(id);
try {
bucket.delete(id);
return OperationResult.NONE;
} catch (Exception e) {
return OperationResult.of(e);
}
}
use of com.mongodb.client.gridfs.GridFSBucket in project mongo-java-driver by mongodb.
the class UnifiedGridFSHelper method executeDownload.
public OperationResult executeDownload(final BsonDocument operation) {
GridFSBucket bucket = entities.getBucket(operation.getString("object").getValue());
BsonDocument arguments = operation.getDocument("arguments");
BsonValue id = arguments.get("id");
if (arguments.size() > 1) {
throw new UnsupportedOperationException("Unexpected arguments");
}
requireNonNull(id);
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bucket.downloadToStream(id, baos);
return OperationResult.of(new BsonString(HexUtils.toHex(baos.toByteArray())));
} catch (Exception e) {
return OperationResult.of(e);
}
}
Aggregations