com.mongodb.gridfs.GridFS.findOne()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(187)

本文整理了Java中com.mongodb.gridfs.GridFS.findOne()方法的一些代码示例,展示了GridFS.findOne()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。GridFS.findOne()方法的具体详情如下:
包路径:com.mongodb.gridfs.GridFS
类名称:GridFS
方法名:findOne

GridFS.findOne介绍

[英]Finds one file matching the given query.
[中]查找一个与给定查询匹配的文件。

代码示例

代码示例来源:origin: org.mongodb/mongo-java-driver

/**
 * 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);
}

代码示例来源:origin: org.mongodb/mongo-java-driver

/**
 * 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));
}

代码示例来源:origin: org.mongodb/mongo-java-driver

/**
 * 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));
}

代码示例来源:origin: org.mongodb/mongo-java-driver

GridFS fs = getGridFS();
String fn = args[i + 1];
GridFSDBFile f = fs.findOne(fn);
if (f == null) {
  System.err.println("can't find file: " + fn);
GridFS fs = getGridFS();
String fn = args[i + 1];
GridFSDBFile f = fs.findOne(fn);
if (f == null) {
  System.err.println("can't find file: " + fn);

代码示例来源:origin: richardwilly98/elasticsearch-river-mongodb

GridFSDBFile file = grid.findOne(new ObjectId(objectId));
if (file != null) {
  logger.trace("Caught file: {} - {}", file.getId(), file.getFilename());

代码示例来源:origin: richardwilly98/elasticsearch-river-mongodb

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);

代码示例来源:origin: org.mongodb/mongodb-driver

/**
 * 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);
}

代码示例来源:origin: org.mongodb/mongodb-driver

/**
 * 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));
}

代码示例来源:origin: org.mongodb/mongodb-driver

/**
 * 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));
}

代码示例来源:origin: org.craftercms/crafter-commons-mongo

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;
}

代码示例来源:origin: org.craftercms/crafter-commons-mongo

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;
}

代码示例来源:origin: org.apache.jackrabbit/oak-mongomk

@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();
  }
}

代码示例来源:origin: apache/incubator-wave

@Override
public AttachmentData getAttachment(AttachmentId attachmentId) {
 final GridFSDBFile attachment = attachmentGrid.findOne(attachmentId.serialise());
 return fileToAttachmentData(attachment);
}

代码示例来源:origin: pl.edu.icm.synat/synat-core-services-impl

@Override
public GridFSDBFile findBinary(DBRef ref) {
  if (ref.getId() instanceof ObjectId) {
    ObjectId objectId = (ObjectId) ref.getId();
    return gridfsAccessor.getGridFs().findOne(objectId);
  } else {
    return gridfsAccessor.getGridFs().findOne(ref.getId().toString());
  }
}

代码示例来源:origin: org.apache.jackrabbit/oak-mongomk

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();
}

代码示例来源:origin: stackoverflow.com

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

代码示例来源:origin: Cognifide/aet

@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;
}

代码示例来源:origin: com.cognifide.aet/datastorage

@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;
}

代码示例来源:origin: de.adorsys.cryptoutils/mongodbstoreconnection

@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);
}

代码示例来源:origin: Kurento/kurento-java

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());
}

相关文章