/** * Finds one file matching the given objectId. Equivalent to findOne(objectId). * * @param objectId the objectId of the file stored on a server * @return a gridfs file * @throws com.mongodb.MongoException if the operation fails */ public GridFSDBFile find(final ObjectId objectId) { return findOne(objectId); }
/** * Finds one file matching the given filename. * * @param filename the name of the file stored on a server * @return the gridfs db file * @throws com.mongodb.MongoException if the operation fails */ public GridFSDBFile findOne(final String filename) { return findOne(new BasicDBObject("filename", filename)); }
/** * Finds one file matching the given objectId. * * @param objectId the objectId of the file stored on a server * @return a gridfs file * @throws com.mongodb.MongoException if the operation fails */ public GridFSDBFile findOne(final ObjectId objectId) { return findOne(new BasicDBObject("_id", objectId)); }
GridFSDBFile file = grid.findOne(new ObjectId(objectId)); if (file != null) { logger.trace("Caught file: {} - {}", file.getId(), file.getFilename());
DBObject object = cursor.next(); if (object instanceof GridFSDBFile) { GridFSDBFile file = grid.findOne(new ObjectId(object.get(MongoDBRiver.MONGODB_ID_FIELD).toString())); if (cursor.hasNext()) { lastId = addInsertToStream(null, file);
/** * Finds one file matching the given objectId. Equivalent to findOne(objectId). * * @param objectId the objectId of the file stored on a server * @return a gridfs file * @throws com.mongodb.MongoException if the operation fails */ public GridFSDBFile find(final ObjectId objectId) { return findOne(objectId); }
/** * Finds one file matching the given objectId. * * @param objectId the objectId of the file stored on a server * @return a gridfs file * @throws com.mongodb.MongoException if the operation fails */ public GridFSDBFile findOne(final ObjectId objectId) { return findOne(new BasicDBObject("_id", objectId)); }
/** * Finds one file matching the given filename. * * @param filename the name of the file stored on a server * @return the gridfs db file * @throws com.mongodb.MongoException if the operation fails */ public GridFSDBFile findOne(final String filename) { return findOne(new BasicDBObject("filename", filename)); }
protected GridFSDBFile validateObject(final String storeName) throws FileNotFoundException { GridFSDBFile file = gridfs.findOne(storeName); if (file == null) { log.error("A file with name {} does not exists", storeName); throw new FileNotFoundException("File with file name " + storeName + " does not exist"); } return file; }
protected GridFSDBFile validateObject(final ObjectId fileId) throws FileNotFoundException { GridFSDBFile file = gridfs.findOne(fileId); if (file == null) { log.error("A file with id {} does not exists", fileId); throw new FileNotFoundException("File with file name " + fileId + " does not exist"); } return file; }
@Override public Long execute() throws Exception { GridFSDBFile gridFSDBFile = gridFS.findOne(new BasicDBObject("md5", blobId)); if (gridFSDBFile == null) { throw new Exception("Blob does not exist"); } return gridFSDBFile.getLength(); } }
@Override public AttachmentData getAttachment(AttachmentId attachmentId) { final GridFSDBFile attachment = attachmentGrid.findOne(attachmentId.serialise()); return fileToAttachmentData(attachment); }
private String saveBlob() throws IOException { BufferedInputStream bis = new BufferedInputStream(is); String md5 = calculateMd5(bis); GridFSDBFile gridFile = gridFS.findOne(new BasicDBObject("md5", md5)); if (gridFile != null) { is.close(); return md5; } GridFSInputFile gridFSInputFile = gridFS.createFile(bis, true); gridFSInputFile.save(); return gridFSInputFile.getMD5(); }
MongoClient client = new MongoClient(); GridFS gridFS = new GridFS(client.getDB("test"); GridFSInputFile in = gridFS.createFile(<insert bytes here>); in.put("meta", 5); // insert extra metadata here in.save(); GridFSDBFile out = gridFS.findOne( new BasicDBObject( "_id" , in.getId() ) ); System.out.println(out.get("meta")); // this will print 5
@Override public Artifact getArtifact(DBKey dbKey, String objectID) { Artifact artifact = null; GridFS gfs = getGridFS(dbKey); BasicDBObject query = new BasicDBObject(); query.put(ID_FIELD_NAME, new ObjectId(objectID)); GridFSDBFile file = gfs.findOne(query); if (file != null) { artifact = new Artifact(file.getInputStream(), file.getContentType()); } return artifact; }
@Override public Artifact getArtifact(DBKey dbKey, String objectID) { Artifact artifact = null; GridFS gfs = getGridFS(dbKey); BasicDBObject query = new BasicDBObject(); query.put(ID_FIELD_NAME, new ObjectId(objectID)); GridFSDBFile file = gfs.findOne(query); if (file != null) { artifact = new Artifact(file.getInputStream(), file.getContentType()); } return artifact; }
@Override public StorageMetadata getStorageMetadata(BucketPath bucketPath) { SPECIAL_LOGGER.debug("readmetadata " + bucketPath); // Dies LogZeile ist fuer den JUNIT-Tests StorageMetaDataTest LOGGER.debug("readmetadata " + bucketPath); GridFSBucket bucket = getGridFSBucket(bucketPath); checkBucketExists(bucket); GridFS gridFS = new GridFS(databaseDeprecated, bucketPath.getObjectHandle().getContainer()); GridFSDBFile one = gridFS.findOne(bucketPath.getObjectHandle().getName()); String jsonString = (String) one.getMetaData().get(STORAGE_METADATA_KEY); return gsonHelper.fromJson(jsonString); }
protected void refreshAttributesOnClose() { dbFile = ((MongoRepository) repository).getGridFS().findOne(getId()); if (dbFile == null) { throw new KurentoException("Grid object not found for id " + getId()); } state = State.STORED; attributes.setContentLength(dbFile.getLength()); }