GridFSDBFile file = grid.findOne(new ObjectId(objectId)); if (file != null) { logger.trace("Caught file: {} - {}", file.getId(), file.getFilename()); object = file; } else {
DBObject query = new BasicDBObject("_id", outputFile.getId()); gfs.remove(query);
@Override public boolean advance() throws IOException { if (iterator != null && iterator.hasNext()) { current = iterator.next(); return true; } else if (cursor != null && cursor.hasNext()) { GridFSDBFile file = (GridFSDBFile) cursor.next(); current = (ObjectId) file.getId(); return true; } current = null; return false; }
public void rename(GridFSDBFile file, String newName){ ObjectId id = (ObjectId)file.getId(); DBObject query = new BasicDBObject(Operator.ID, id); DBObject dbo = files.findOne(query); dbo.put(FILENAME, newName); files.save(dbo); }
@Override public List<? extends BoundedSource<ObjectId>> split( long desiredBundleSizeBytes, PipelineOptions options) throws Exception { Mongo mongo = spec.connectionConfiguration().setupMongo(); try { GridFS gridfs = spec.connectionConfiguration().setupGridFS(mongo); DBCursor cursor = createCursor(gridfs); long size = 0; List<BoundedGridFSSource> list = new ArrayList<>(); List<ObjectId> objects = new ArrayList<>(); while (cursor.hasNext()) { GridFSDBFile file = (GridFSDBFile) cursor.next(); long len = file.getLength(); if ((size + len) > desiredBundleSizeBytes && !objects.isEmpty()) { list.add(new BoundedGridFSSource(spec, objects)); size = 0; objects = new ArrayList<>(); } objects.add((ObjectId) file.getId()); size += len; } if (!objects.isEmpty() || list.isEmpty()) { list.add(new BoundedGridFSSource(spec, objects)); } return list; } finally { mongo.close(); } }
if (usesAttribute) { file.put(endpoint.getFileAttributeName(), "processing"); DBObject q = BasicDBObjectBuilder.start("_id", file.getId()).append("camel-processed", null).get(); forig = (GridFSDBFile)endpoint.getFilesCollection().findAndModify(q, null, null, false, file, true, false); file = endpoint.getGridFs().findOne(new BasicDBObject("_id", file.getId()));
DBObject query = new BasicDBObject("_id", outputFile.getId()); gfs.remove(query);