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


Java GridFS.createFile方法代码示例

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


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

示例1: uploadData

import com.mongodb.gridfs.GridFS; //导入方法依赖的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.GridFS; //导入方法依赖的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: insertGrobidTei

import com.mongodb.gridfs.GridFS; //导入方法依赖的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

示例4: insertMetadataTei

import com.mongodb.gridfs.GridFS; //导入方法依赖的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

示例5: insertBinaryDocument

import com.mongodb.gridfs.GridFS; //导入方法依赖的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

示例6: updateTei

import com.mongodb.gridfs.GridFS; //导入方法依赖的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

示例7: insertExternalTeiDocument

import com.mongodb.gridfs.GridFS; //导入方法依赖的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

示例8: putBlob

import com.mongodb.gridfs.GridFS; //导入方法依赖的package包/类
@Override
public String putBlob(String container, Blob blob, PutOptions options) {
    if (options != null && !options.isMultipart()) {
        throw new IllegalArgumentException("only multipart is supported by this provider");
    }
    Payload payload = checkNotNull(blob.getPayload());
    BlobMetadata metadata = blob.getMetadata();
    ContentMetadata contentMetadata = metadata.getContentMetadata();
    GridFS gridFS = parseGridFSIdentifier(container).connect(mongo);
    GridFSInputFile inputFile = gridFS.createFile(payload.getInput(), metadata.getName(), true);
    inputFile.setContentType(contentMetadata.getContentType());
    DBObject fileMetadata = new BasicDBObject();
    fileMetadata.putAll(metadata.getUserMetadata());
    inputFile.setMetaData(fileMetadata);
    inputFile.save();
    return inputFile.getMD5();
}
 
开发者ID:mhurne,项目名称:jclouds-gridfs-blobstore,代码行数:18,代码来源:GridFSBlobStore.java

示例9: save

import com.mongodb.gridfs.GridFS; //导入方法依赖的package包/类
public Optional<FileEntry> save(final String name, final String mime,
                                final String creator, final boolean privateFile, final String description,
                                InputStream in) {
    GridFS gf = gridFS;
    GridFSInputFile f = gf.createFile(in);
    f.setFilename(name);
    f.setContentType(mime);
    //
    DBObject metadata = f.getMetaData();
    if (metadata == null) {
        metadata = new BasicDBObject();
        f.setMetaData(metadata);
    }
    metadata.put("creator", creator);
    metadata.put("private", privateFile);
    metadata.put("description", description);
    //
    f.save();
    //
    return this.loadFileEntry((ObjectId) f.getId());
}
 
开发者ID:ageldama,项目名称:glados-wiki,代码行数:22,代码来源:FileStoreService.java

示例10: execute

import com.mongodb.gridfs.GridFS; //导入方法依赖的package包/类
@Override
public void execute() throws Exception {
	MongoClient mdb = MongoFactory.getInst().getMongo( sName );
	
	if ( mdb == null )
		throw new Exception("no server selected");
	
	if ( sDb == null )
		throw new Exception("no database selected");
	
	MongoFactory.getInst().setActiveDB(sDb);
	DB db	= mdb.getDB(sDb);
	
	GridFS	gfs	= new GridFS( db, sColl.substring(0,sColl.lastIndexOf(".")) );
	
	GridFSInputFile gridFSInputFile = gfs.createFile(getFile);
	gridFSInputFile.setContentType( MimetypesFileTypeMap.getDefaultFileTypeMap().getContentType(getFile) );
	gridFSInputFile.save();
	
	setMessage( "fileLoaded=" + getFile + "; size=" + getFile.length() );
}
 
开发者ID:aw20,项目名称:MongoWorkBench,代码行数:22,代码来源:GridFSPutFileCommand.java

示例11: prefetchData

import com.mongodb.gridfs.GridFS; //导入方法依赖的package包/类
public DataAddress prefetchData(DataAddress givenAddress, ServerAddress destAddress) throws IOException {
	logger.info("yo2");
	ServerAddress givenServer = new ServerAddress(givenAddress.hostname, givenAddress.port);
	GridFS givenDatabase = connectToDatabase(givenServer);
	
	logger.info("yo");
            		
       GridFSDBFile givenPackage = givenDatabase.findOne(new BasicDBObject("_id", givenAddress.ID));
       ByteArrayOutputStream baos = new ByteArrayOutputStream((int)givenPackage.getLength());
       givenPackage.writeTo(baos);
              
       logger.info("Prefetched");
                                     
       GridFS destDatabase = connectToDatabase(destAddress);
       GridFSInputFile destPackage = destDatabase.createFile(baos.toByteArray());
       int newID = getNextId(destDatabase);
       logger.info("Got new id for prefetched package: " + newID);
       destPackage.put("_id", newID);
       destPackage.save();
       
       logger.info("after save");
       
       DataAddress ret = new DataAddress();
       ret.hostname = destAddress.getHost();
       ret.port = destAddress.getPort();
       ret.ID = newID;            
       return ret;        
}
 
开发者ID:roscisz,项目名称:KernelHive,代码行数:29,代码来源:DataManager.java

示例12: saveFile

import com.mongodb.gridfs.GridFS; //导入方法依赖的package包/类
/**
 *
 * @param inputStream 文件流
 * @param format 文件格式,“pdf”,“png”等,不包含后缀符号“.”
 * @return
 */
public String saveFile(InputStream inputStream,String format,String uid) {
    try {
        GridFS gridFS = getInstance();

        //随机生成文件名称,多次重试
        String filename = this.randomFileName();
        //如果有文件重复,则重新生成filename
        while (true) {
            GridFSDBFile _current = gridFS.findOne(filename);
            //如果文件不存在,则保存操作
            if (_current == null) {
                break;
            }
            filename = this.randomFileName();
        }

        GridFSInputFile file = gridFS.createFile(inputStream, filename);
        if(format != null) {
            file.put("format", format);
        }
        if(uid != null) {
            file.put("uid",uid);
        }
        file.put("content-type","application/octet-stream");
        file.save();
        return concat(filename,format);
    }catch (Exception e) {

        throw new RuntimeException(e);
    } finally {
        try{
            inputStream.close();
        }catch (Exception ex) {
            //
        }
    }
}
 
开发者ID:javahongxi,项目名称:whatsmars,代码行数:44,代码来源:GridFSClient.java

示例13: createGridFsFile

import com.mongodb.gridfs.GridFS; //导入方法依赖的package包/类
public long createGridFsFile(Id id, InputStream inputStream, String filename, String mimeType) {
    DB db = (DB) connections.getConnection("mongodb.dma");
    GridFS fs = new GridFS(db);
    GridFSInputFile gridFile = fs.createFile(inputStream, filename);
    gridFile.setId(id);
    gridFile.setContentType(mimeType);
    gridFile.save();
    return gridFile.getLength();
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:10,代码来源:DefaultMediaAssetHelper.java

示例14: createGridFsFile

import com.mongodb.gridfs.GridFS; //导入方法依赖的package包/类
private long createGridFsFile(Id id, InputStream inputStream, String filename, String mimeType) {
    DB db = (DB) connections.getConnection("mongodb.dma");
    GridFS fs = new GridFS(db);
    GridFSInputFile gridFile = fs.createFile(inputStream, filename);
    gridFile.setId(id);
    gridFile.setContentType(mimeType);
    gridFile.save();
    return gridFile.getLength();
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:10,代码来源:DefaultMediaAssetService.java

示例15: saveArtifact

import com.mongodb.gridfs.GridFS; //导入方法依赖的package包/类
@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;
}
 
开发者ID:Cognifide,项目名称:aet,代码行数:13,代码来源:ArtifactsDAOMongoDBImpl.java


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