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

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

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

GridFS.createFile介绍

[英]This method creates an empty GridFSInputFile instance. On this instance an java.io.OutputStream can be obtained using the GridFSInputFile#getOutputStream() method. You can still call GridFSInputFile#setContentType(String) and GridFSInputFile#setFilename(String). The file will be completely written and closed after calling the java.io.OutputStream#close() method on the output stream.
[中]此方法创建一个空的GridFSInputFile实例。在这个例子中,一个java。木卫一。可以使用GridFSInputFile#getOutputStream()方法获取OutputStream。您仍然可以调用GridFSInputFile#setContentType(字符串)和GridFSInputFile#setFilename(字符串)。调用java后,文件将被完全写入并关闭。木卫一。输出流上的OutputStream#close()方法。

代码示例

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

/**
 * Creates a file entry. After calling this method, you have to call {@link com.mongodb.gridfs.GridFSInputFile#save()}.
 *
 * @param in an inputstream containing the file's data
 * @return a gridfs input file
 */
public GridFSInputFile createFile(final InputStream in) {
  return createFile(in, null);
}

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

/**
 * Creates a file entry. After calling this method, you have to call {@link com.mongodb.gridfs.GridFSInputFile#save()}.
 *
 * @param in                   an inputstream containing the file's data
 * @param closeStreamOnPersist indicate the passed in input stream should be closed once the data chunk persisted
 * @return a gridfs input file
 */
public GridFSInputFile createFile(final InputStream in, final boolean closeStreamOnPersist) {
  return createFile(in, null, closeStreamOnPersist);
}

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

/**
 * Creates a file entry. After calling this method, you have to call {@link com.mongodb.gridfs.GridFSInputFile#save()}.
 *
 * @param data the file's data
 * @return a gridfs input file
 */
public GridFSInputFile createFile(final byte[] data) {
  return createFile(new ByteArrayInputStream(data), true);
}

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

/**
 * Creates a file entry. After calling this method, you have to call {@link com.mongodb.gridfs.GridFSInputFile#save()}.
 *
 * @param file the file object
 * @return a GridFS input file
 * @throws IOException if there are problems reading {@code file}
 */
public GridFSInputFile createFile(final File file) throws IOException {
  return createFile(new FileInputStream(file), file.getName(), true);
}

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

GridFS fs = getGridFS();
String fn = args[i + 1];
GridFSInputFile f = fs.createFile(new File(fn));
f.save();
f.validate();

代码示例来源:origin: Impetus/Kundera

GridFSInputFile gridFSInputFile = null;
if (f.getType().isAssignableFrom(byte[].class))
  gridFSInputFile = gfs.createFile((byte[]) obj);
else if (f.getType().isAssignableFrom(File.class))
    gridFSInputFile = gfs.createFile((File) obj);

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

/**
 * Creates a file entry. After calling this method, you have to call {@link com.mongodb.gridfs.GridFSInputFile#save()}.
 *
 * @param file the file object
 * @return a GridFS input file
 * @throws IOException if there are problems reading {@code file}
 */
public GridFSInputFile createFile(final File file) throws IOException {
  return createFile(new FileInputStream(file), file.getName(), true);
}

代码示例来源:origin: Findwise/Hydra

@Override
public Object save(String fileName, InputStream file) {
  GridFSInputFile inputFile = pipelinefs.createFile(file, fileName);
  inputFile.save();
  return inputFile.getId();
}

代码示例来源: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: stackoverflow.com

GridFS gfs = new GridFS(db, "zips");
GridFSInputFile gfsFile = gfs.createFile(in);
gfsFile.setFilename("sample.zip");
gfsFile.setId(id);
gfsFile.save();

代码示例来源:origin: Findwise/Hydra

@Override
public boolean save(Object id, String fileName, InputStream file) {
  pipelinefs.remove(new BasicDBObject(MongoDocument.MONGO_ID_KEY, id));
  
  GridFSInputFile inputFile = pipelinefs.createFile(file, fileName);
  inputFile.put("_id", id);
  inputFile.save();
  return true;
}

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

@Override
public RepositoryItem createRepositoryItem() {
 GridFSInputFile dbFile = gridFS.createFile();
 dbFile.setFilename(dbFile.getId().toString());
 return createRepositoryItem(dbFile);
}

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

@Override
public String saveArtifact(DBKey dbKey, InputStream data, String contentType) {
 String resultObjectId = null;
 GridFS gfs = getGridFS(dbKey);
 GridFSInputFile file = gfs.createFile(data);
 if (file != null) {
  file.setContentType(contentType);
  file.save();
  resultObjectId = file.getId().toString();
 }
 return resultObjectId;
}

代码示例来源:origin: org.kurento/kurento-repository-internal

@Override
public RepositoryItem createRepositoryItem(String id) {
 // TODO The file is not written until outputstream is closed. There is a
 // potentially data race with this unique test
 if (!gridFS.find(id).isEmpty()) {
  throw new DuplicateItemException(id);
 }
 GridFSInputFile dbFile = gridFS.createFile(id);
 dbFile.setId(id);
 return createRepositoryItem(dbFile);
}

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

@Override
public void storeMetadata(AttachmentId attachmentId, AttachmentMetadata metaData)
  throws IOException {
 AttachmentMetadataProtoImpl proto = new AttachmentMetadataProtoImpl(metaData);
 byte[] bytes = proto.getPB().toByteArray();
 GridFSInputFile file =
   metadataGrid.createFile(new ByteArrayInputStream(bytes), attachmentId.serialise());
 saveFile(file);
}

代码示例来源:origin: lmco/streamflow

@Override
public FileContent save(FileContent entity) {
  GridFSInputFile inputFile = gridFs.createFile(entity.getData());
  inputFile.setId(entity.getId());
  inputFile.save();
  return entity;
}

代码示例来源:origin: lmco/streamflow

@Override
  public FileContent update(FileContent entity) {
    GridFSInputFile inputFile = gridFs.createFile(entity.getData());
    inputFile.setId(entity.getId());
    inputFile.save();

    return entity;
  }
}

代码示例来源:origin: BlackLabs/play-morphia

@Override
public void put(String key, ISObject stuff) throws UnexpectedIOException {
  GridFS gfs = gfs();
  gfs.remove(new BasicDBObject("name", key));
  GridFSInputFile inputFile = gfs.createFile(stuff.asByteArray());
  inputFile.setContentType(stuff.getAttribute(Blob.CONTENT_TYPE));
  inputFile.put("name", key);
  inputFile.put("filename", stuff.getAttribute(Blob.FILENAME));
  inputFile.save();
}

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

@Override
public MongoFileRef createFile(String id, InputStream content) {
  GridFSFile fsFile = gridfsAccessor.getGridFs().createFile(content, id, true);
  fsFile.save();
  try {
    content.close();
  } catch (final IOException e) {
    throw new GeneralServiceException(e, "Could not save binary data for path {}", id);
  }
  return new MongoFileRef(new DBRef(gridfsAccessor.getCollection().getName(), fsFile.getId()), fsFile.getLength());
}

相关文章