当前位置: 首页>>代码示例>>Java>>正文


Java GridFSInputFile类代码示例

本文整理汇总了Java中com.mongodb.gridfs.GridFSInputFile的典型用法代码示例。如果您正苦于以下问题:Java GridFSInputFile类的具体用法?Java GridFSInputFile怎么用?Java GridFSInputFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GridFSInputFile类属于com.mongodb.gridfs包,在下文中一共展示了GridFSInputFile类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: uploadData

import com.mongodb.gridfs.GridFSInputFile; //导入依赖的package包/类
public DataAddress uploadData(String data, DataAddress dataAddress) throws UnknownHostException {
      ServerAddress server = new ServerAddress(dataAddress.hostname, dataAddress.port);
      GridFS database = connectToDatabase(server);

      logger.info("Database connected");

      GridFSInputFile file = database.createFile(data.getBytes());
      int newID = getNextId(database);
      logger.info("Got new id for uploaded file: " + newID);
file.setFilename(String.valueOf(newID));
      file.put("_id", newID);
      file.save();

      logger.info("after save");

      return new DataAddress(dataAddress.hostname, dataAddress.port, newID);
  }
 
开发者ID:roscisz,项目名称:KernelHive,代码行数:18,代码来源:DataManager.java

示例2: insertAnnexDocument

import com.mongodb.gridfs.GridFSInputFile; //导入依赖的package包/类
/**
 * Inserts publication annex document.
 */
public void insertAnnexDocument(BinaryFile bf, String dateString) throws ParseException {
    try {
        GridFS gfs = new GridFS(db, MongoCollectionsInterface.PUB_ANNEXES);
        BasicDBObject whereQuery = new BasicDBObject();
        whereQuery.put("repositoryDocId", bf.getRepositoryDocId());
        whereQuery.put("filename", bf.getFileName());
        gfs.remove(whereQuery);
        //version ?
        GridFSInputFile gfsFile = gfs.createFile(bf.getStream(), true);
        gfsFile.put("uploadDate", Utilities.parseStringDate(dateString));
        gfsFile.setFilename(bf.getFileName());
        gfsFile.put("source", bf.getSource());
        gfsFile.put("version", bf.getRepositoryDocVersion());
        gfsFile.put("repositoryDocId", bf.getRepositoryDocId());
        gfsFile.put("anhalyticsId", bf.getAnhalyticsId());
        gfsFile.save();
    } catch (ParseException e) {
        logger.error(e.getMessage(), e.getCause());
    }
}
 
开发者ID:anHALytics,项目名称:anhalytics-core,代码行数:24,代码来源:MongoFileManager.java

示例3: storeBlob

import com.mongodb.gridfs.GridFSInputFile; //导入依赖的package包/类
@Override
public Boolean storeBlob(CallingContext context, String docPath, InputStream newContent, Boolean append) {
    GridFS gridFS = getGridFS();
    GridFSInputFile file;
    if (!append) {
        gridFS.remove(docPath);
        file = createNewFile(docPath, newContent);
    } else {
        GridFSDBFile existing = gridFS.findOne(docPath);
        if (existing != null) {
            try {
                file = updateExisting(context, docPath, newContent, gridFS, existing);
            } catch (IOException e) {
                file = null;
                log.error(String.format("Error while appending to docPath %s: %s", docPath, ExceptionToString.format(e)));
            }

        } else {
            file = createNewFile(docPath, newContent);
        }
    }
    return file != null;
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:24,代码来源:GridFSBlobHandler.java

示例4: process

import com.mongodb.gridfs.GridFSInputFile; //导入依赖的package包/类
@Override
public void process(CAS aCAS) throws AnalysisEngineProcessException {
  Type documentIdType = aCAS.getTypeSystem()
      .getType("edu.umn.biomedicus.uima.type1_5.DocumentId");
  Feature docIdFeat = documentIdType.getFeatureByBaseName("documentId");

  String documentId = aCAS.getIndexRepository()
      .getAllIndexedFS(documentIdType)
      .get()
      .getStringValue(docIdFeat);

  if (documentId == null) {
    documentId = UUID.randomUUID().toString();
  }

  GridFSInputFile file = gridFS.createFile(documentId + ".xmi");

  try (OutputStream outputStream = file.getOutputStream()) {
    XmiCasSerializer.serialize(aCAS, outputStream);
  } catch (IOException | SAXException e) {
    throw new AnalysisEngineProcessException(e);
  }
}
 
开发者ID:nlpie,项目名称:biomedicus,代码行数:24,代码来源:MongoDbXmiWriter.java

示例5: storeAttachment

import com.mongodb.gridfs.GridFSInputFile; //导入依赖的package包/类
@Override
public void storeAttachment(AttachmentId attachmentId, InputStream data)
    throws IOException {
  GridFSInputFile file = getAttachmentGrid().createFile(data, attachmentId.serialise());

  try {
    file.save();
  } catch (MongoException e) {
    // Unfortunately, file.save() wraps any IOException thrown in a
    // 'MongoException'. Since the interface explicitly throws IOExceptions,
    // we unwrap any IOExceptions thrown.
    Throwable innerException = e.getCause();
    if (innerException instanceof IOException) {
      throw (IOException) innerException;
    } else {
      throw e;
    }
  }
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:20,代码来源:MongoDbStore.java

示例6: saveFile

import com.mongodb.gridfs.GridFSInputFile; //导入依赖的package包/类
public String saveFile(InputStream is, String contentType) throws IOException {
	GridFSInputFile file = getNewFile();	
	String id = file.getId().toString();
	OutputStream os = getFileOutputStream(id, contentType);
	if (os != null) {
		try {
			byte data[] = new byte[4096];
			int len = 0;
			while ((len = is.read(data, 0, data.length)) > 0) {
				os.write(data, 0, len);
			}
			return id;
		} finally {
			os.close();
		}
	}
	return null;
}
 
开发者ID:hulop,项目名称:BLELocalization,代码行数:19,代码来源:MongoService.java

示例7: insertGrobidTei

import com.mongodb.gridfs.GridFSInputFile; //导入依赖的package包/类
/**
 * Inserts grobid tei using GridFS.
 */
public void insertGrobidTei(String teiString, String repositoryDocId, String anhalyticsId, String version, String source, String type, String date) {
    try {
        GridFS gfs = new GridFS(db, MongoCollectionsInterface.GROBID_TEIS);
        gfs.remove(repositoryDocId + ".tei.xml");
        GridFSInputFile gfsFile = gfs.createFile(new ByteArrayInputStream(teiString.getBytes()), true);
        gfsFile.put("uploadDate", Utilities.parseStringDate(date));
        gfsFile.setFilename(repositoryDocId + ".tei.xml");
        gfsFile.put("repositoryDocId", repositoryDocId);
        gfsFile.put("anhalyticsId", anhalyticsId);
        gfsFile.put("source", source);
        gfsFile.put("version", version);
        gfsFile.put("documentType", type);
        gfsFile.save();
    } catch (ParseException e) {
        logger.error(e.getMessage(), e.getCause());
    }
}
 
开发者ID:anHALytics,项目名称:anhalytics-core,代码行数:21,代码来源:MongoFileManager.java

示例8: insertMetadataTei

import com.mongodb.gridfs.GridFSInputFile; //导入依赖的package包/类
/**
 * Inserts TEI metadata document in the GridFS.
 */
public void insertMetadataTei(String tei, String doi, String pdfUrl, String source, String repositoryDocId, String version, String type, String date) {
    try {
        GridFS gfs = new GridFS(db, MongoCollectionsInterface.METADATAS_TEIS);
        gfs.remove(repositoryDocId + ".tei.xml");
        GridFSInputFile gfsFile = gfs.createFile(new ByteArrayInputStream(tei.getBytes()), true);
        gfsFile.put("uploadDate", Utilities.parseStringDate(date));
        gfsFile.setFilename(repositoryDocId + ".tei.xml");
        gfsFile.put("repositoryDocId", repositoryDocId);
        gfsFile.put("anhalyticsId", generateAnhalyticsId(repositoryDocId, doi, pdfUrl));
        gfsFile.put("source", source);
        gfsFile.put("version", version);
        gfsFile.put("documentType", type);
        gfsFile.save();
    } catch (ParseException e) {
        logger.error(e.getMessage(), e.getCause());
    }
}
 
开发者ID:anHALytics,项目名称:anhalytics-core,代码行数:21,代码来源:MongoFileManager.java

示例9: insertBinaryDocument

import com.mongodb.gridfs.GridFSInputFile; //导入依赖的package包/类
/**
 * Inserts PDF binary document in the GridFS.
 */
public void insertBinaryDocument(BinaryFile bf, String date) {
    try {
        GridFS gfs = new GridFS(db, MongoCollectionsInterface.BINARIES);
        gfs.remove(bf.getFileName());
        GridFSInputFile gfsFile = gfs.createFile(bf.getStream(), true);
        gfsFile.put("uploadDate", Utilities.parseStringDate(date));
        gfsFile.setFilename(bf.getFileName());
        gfsFile.put("repositoryDocId", bf.getRepositoryDocId());
        gfsFile.put("anhalyticsId", bf.getAnhalyticsId());
        gfsFile.put("source", bf.getSource());
        gfsFile.put("version", bf.getRepositoryDocVersion());
        gfsFile.put("documentType", bf.getDocumentType());
        gfsFile.setContentType(bf.getFileType());
        gfsFile.save();
    } catch (ParseException e) {
        logger.error(e.getMessage(), e.getCause());
    }

}
 
开发者ID:anHALytics,项目名称:anhalytics-core,代码行数:23,代码来源:MongoFileManager.java

示例10: updateTei

import com.mongodb.gridfs.GridFSInputFile; //导入依赖的package包/类
/**
 * Updates already existing tei with new (more enriched one, fulltext..).
 */
public void updateTei(String newTei, String repositoryDocId, String collection) {
    try {
        GridFS gfs = new GridFS(db, collection);
        GridFSDBFile gdf = gfs.findOne(repositoryDocId + ".tei.xml");
        GridFSInputFile gfsNew = gfs.createFile(new ByteArrayInputStream(newTei.getBytes()), true);
        gfsNew.put("uploadDate", gdf.getUploadDate());
        gfsNew.setFilename(gdf.get("repositoryDocId") + ".tei.xml");
        gfsNew.put("repositoryDocId", gdf.get("repositoryDocId"));
        gfsNew.put("documentType", gdf.get("documentType"));
        gfsNew.put("anhalyticsId", gdf.get("anhalyticsId"));
        gfsNew.put("source", gdf.get("source"));

        gfsNew.save();
        gfs.remove(gdf);
    } catch (Exception e) {
        logger.error(e.getMessage(), e.getCause());
    }
}
 
开发者ID:anHALytics,项目名称:anhalytics-core,代码行数:22,代码来源:MongoFileManager.java

示例11: insertExternalTeiDocument

import com.mongodb.gridfs.GridFSInputFile; //导入依赖的package包/类
/**
 * inserts a Arxiv/istex TEI document in the GridFS.
 */
public void insertExternalTeiDocument(InputStream file, String identifier, String repository, String namespace, String dateString) {
    try {
        GridFS gfs = new GridFS(db, namespace);
        GridFSInputFile gfsFile = gfs.createFile(file, true);
        gfs.remove(identifier + ".pdf");
        gfsFile.put("uploadDate", Utilities.parseStringDate(dateString));
        gfsFile.setFilename(identifier + ".tei.xml");
        gfsFile.put("identifier", identifier);
        gfsFile.put("repository", repository);
        gfsFile.setContentType("application/tei+xml");
        gfsFile.save();
    } catch (ParseException e) {
        logger.error(e.getMessage(), e.getCause());
    }

}
 
开发者ID:anHALytics,项目名称:anhalytics-core,代码行数:20,代码来源:MongoFileManager.java

示例12: writeBlob

import com.mongodb.gridfs.GridFSInputFile; //导入依赖的package包/类
@Override
public void writeBlob(final String blobName, final InputStream is, final long sizeInBytes, final WriterListener listener) {
    blobStore.executor().execute(new Runnable() {
        @Override
        public void run() {
            try {
                blobStore.gridFS().remove(buildKey(blobName));  // need to remove old file if already exist
                GridFSInputFile file = blobStore.gridFS().createFile(is, buildKey(blobName));
                file.save();
                listener.onCompleted();
            } catch (Exception e) {
                listener.onFailure(e);
            }
        }
    });
}
 
开发者ID:kzwang,项目名称:elasticsearch-repository-gridfs,代码行数:17,代码来源:GridFsImmutableBlobContainer.java

示例13: createOutputStreamToWrite

import com.mongodb.gridfs.GridFSInputFile; //导入依赖的package包/类
@Override
public OutputStream createOutputStreamToWrite() {
  checkState(State.NEW);

  storingOutputStream = new FilterOutputStream(((GridFSInputFile) dbFile).getOutputStream()) {

    @Override
    public void close() throws IOException {
      putMetadataInGridFS(false);
      super.close();
      refreshAttributesOnClose();
    }
  };

  return storingOutputStream;
}
 
开发者ID:Kurento,项目名称:kurento-java,代码行数:17,代码来源:MongoRepositoryItem.java

示例14: concatGridFile

import com.mongodb.gridfs.GridFSInputFile; //导入依赖的package包/类
/**
 * 保存文件到Mongo中
 * @param file  文件对象
 * @param id    id_ 自定义序列
 * @param metaData  元数据类型 Key Value
 * @return
 */
public boolean concatGridFile(File file, Object id, DBObject metaData){
    GridFSInputFile gridFSInputFile;
    DBObject query  = new BasicDBObject("_id", id);
    GridFSDBFile gridFSDBFile = myFS.findOne(query);
    if(gridFSDBFile!= null)
        return false;
    try {
        gridFSInputFile = myFS.createFile(file);
        gridFSInputFile.put("_id",id);
        gridFSInputFile.setFilename(file.getName());
        gridFSInputFile.setMetaData(metaData);
        gridFSInputFile.setContentType(file.getName().substring(file.getName().lastIndexOf(".")));
        gridFSInputFile.save();
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
 
开发者ID:pwd,项目名称:minicli,代码行数:27,代码来源:MongoQuery.java

示例15: run

import com.mongodb.gridfs.GridFSInputFile; //导入依赖的package包/类
@Override
public void run() {
	try{
		File localPath = new File(localRoot, file.getFilename());
		log.info("Save to local file:" + localPath.getAbsolutePath());
		File dirName = localPath.getParentFile();
		if(!dirName.exists()){
			dirName.mkdirs();
		}
		file.writeTo(localPath);
		GridFSInputFile newFile = fs.createFile(new byte[]{0, 0,});
		newFile.setMetaData(file.getMetaData());
		newFile.setFilename(file.getFilename());
		newFile.put("localLength", file.getLength());
		newFile.save(10);
		//log.info("remove:%s" + file.getId() + ", fn:" + file.getFilename());
		fs.remove((ObjectId)file.getId());
	}catch(Throwable e){
		log.error("Failed to dump file to local fs, error:" + e.toString(), e);
	}
}
 
开发者ID:deonwu,项目名称:hdfs-archiver,代码行数:22,代码来源:DumpFileToLocalFS.java


注:本文中的com.mongodb.gridfs.GridFSInputFile类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。