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


Java GridFSInputFile.setId方法代码示例

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


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

示例1: saveBlob

import com.mongodb.gridfs.GridFSInputFile; //导入方法依赖的package包/类
@Override
public void saveBlob(final MD5 md5, final InputStream data,
		final boolean sorted)
		throws BlobStoreCommunicationException {
	if(data == null || md5 == null) {
		throw new NullPointerException("Arguments cannot be null");
	}
	if (getFile(md5) != null) {
		return; //already exists
	}
	final GridFSInputFile gif = gfs.createFile(data, true);
	gif.setId(md5.getMD5());
	gif.setFilename(md5.getMD5());
	gif.put(Fields.GFS_SORTED, sorted);
	try {
		gif.save();
	} catch (DuplicateKeyException dk) {
		// already here, done
	} catch (MongoException me) {
		throw new BlobStoreCommunicationException(
				"Could not write to the mongo database", me);
	}
}
 
开发者ID:kbase,项目名称:workspace_deluxe,代码行数:24,代码来源:GridFSBlobStore.java

示例2: dataWithoutSortMarker

import com.mongodb.gridfs.GridFSInputFile; //导入方法依赖的package包/类
@Test
public void dataWithoutSortMarker() throws Exception {
	String s = "pootypoot";
	final GridFSInputFile gif = gfs.createFile(s.getBytes("UTF-8"));
	MD5 md5 = new MD5(a32);
	gif.setId(md5.getMD5());
	gif.setFilename(md5.getMD5());
	gif.save();
	
	ByteArrayFileCache d = gfsb.getBlob(md5, 
			new ByteArrayFileCacheManager(16000000, 2000000000L, tfm));
	assertThat("data returned marked as unsorted", d.isSorted(), is(false));
	String returned = IOUtils.toString(d.getJSON());
	assertThat("Didn't get same data back from store", returned, is(s));
	gfsb.removeBlob(md5);
}
 
开发者ID:kbase,项目名称:workspace_deluxe,代码行数:17,代码来源:GridFSBlobStoreTest.java

示例3: createGridFsFile

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

示例4: createGridFsFile

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

示例5: createAttachmentContent

import com.mongodb.gridfs.GridFSInputFile; //导入方法依赖的package包/类
/**
 * @param attachmentContentStream
 * @return
 */
@Override
public AttachmentContentMetadata createAttachmentContent(String name, String contentType, InputStream attachmentContentStream) {
    // Do not specify a bucket (so the data will be stored in fs.files and fs.chunks)
    GridFSInputFile gfsFile = gridFS.createFile(attachmentContentStream);
    ObjectId id = new ObjectId();
    gfsFile.setContentType(contentType);
    gfsFile.setId(id);
    String filename = id.toString();
    gfsFile.setFilename(filename);
    gfsFile.save();

    return new AttachmentContentMetadata(gfsFile.getFilename(), gfsFile.getLength());
}
 
开发者ID:WASdev,项目名称:tool.lars,代码行数:18,代码来源:PersistenceBean.java

示例6: saveFile

import com.mongodb.gridfs.GridFSInputFile; //导入方法依赖的package包/类
private GridFSInputFile saveFile(ImageFile img, String id, GridFS fs) {
	GridFSInputFile f = fs.createFile(img.getData());
	f.setId(id);
	f.setContentType(img.getContentType());
	f.setFilename(img.getFilename());
	f.save();
	return f;
}
 
开发者ID:web-education,项目名称:mod-image-resizer,代码行数:9,代码来源:GridFsFileAccess.java

示例7: createRepositoryItem

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

示例8: execute

import com.mongodb.gridfs.GridFSInputFile; //导入方法依赖的package包/类
public cfData execute(cfSession _session, cfArgStructData argStruct ) throws cfmRunTimeException {
	
	// Get the necessary Mongo references
	DB db	= getDB(_session,argStruct);
	
	GridFS	gridfs	= getGridFS(_session, argStruct, db);
	GridFSInputFile fsInputFile = null;
	
	// Get the file information
	String filename	= getNamedStringParam(argStruct, "filename", null);
	if ( filename == null )
		throwException(_session, "please specify a filename");
	
	try{
		
		cfData	ftmp	= getNamedParam(argStruct, "file", null);
		if ( ftmp.getDataType() == cfData.CFBINARYDATA ){
			fsInputFile	= gridfs.createFile( ((cfBinaryData)ftmp).getByteArray() );
		}else{
			// The 'file' parameter is a string, which means it is a path to a file
			
			File	inputFile	= new File( ftmp.getString() );
			if ( !inputFile.exists() )
				throwException(_session, "File:" + inputFile + " does not exist" );
			
			if ( !inputFile.isFile() )
				throwException(_session, "File:" + inputFile + " is not a valid file" );
			
			fsInputFile	= gridfs.createFile(inputFile);
		}
		
	} catch (IOException e) {
		throwException(_session, e.getMessage() );
	}
	
	fsInputFile.setFilename(filename);
	
	String contenttype	= getNamedStringParam(argStruct, "contenttype", null);		
	if ( contenttype != null )
		fsInputFile.setContentType(contenttype);

	
	String _id	= getNamedStringParam(argStruct, "_id", null);
	if ( _id != null )
		fsInputFile.setId( _id );

	
	// Get and set the metadata
	cfData mTmp	= getNamedParam(argStruct, "metadata", null);
	if ( mTmp != null )
		fsInputFile.setMetaData(getDBObject(mTmp));
	
	
	// Save the Object
	try{
		fsInputFile.save();
		return new cfStringData( fsInputFile.getId().toString() );
	} catch (MongoException me){
		throwException(_session, me.getMessage());
		return null;
	}
}
 
开发者ID:OpenBD,项目名称:openbd-core,代码行数:63,代码来源:Add.java

示例9: test

import com.mongodb.gridfs.GridFSInputFile; //导入方法依赖的package包/类
@Test
public void test() throws IOException {

  Repository repository = getRepository();

  if (repository instanceof MongoRepository) {

    MongoRepository mongoRepository = (MongoRepository) repository;

    GridFS gridFS = mongoRepository.getGridFS();

    GridFSInputFile file = gridFS.createFile(new File("test-files/sample.txt"));

    file.setId("sample.txt");

    file.save();

    List<GridFSDBFile> files = gridFS.find((DBObject) JSON.parse("{ _id : 'sample.txt' }"));

    assertNotNull(files);
    assertEquals(1, files.size());
  } else {
    log.debug("Repository is not MongoDB");
  }

}
 
开发者ID:Kurento,项目名称:kurento-java,代码行数:27,代码来源:FilenameAsIdTest.java

示例10: pushToDB

import com.mongodb.gridfs.GridFSInputFile; //导入方法依赖的package包/类
private GridFSFilesPathItemResource pushToDB(RequestContext ctx, MediaType contentType, GridFSDBObject fileInfo, Supplier contentProvider) throws IOException {
    ObjectId currentId = fileInfo.getId();
    boolean fileExists = currentId != null;

    // update the targeted userspace - hopefully current user has rights to do that
    GridFS gridfs = getUserspace().getGridFS();

    Object content = contentProvider.get();
    GridFSInputFile blob;
    if (fileExists) {
        // here is a time gap when file doesn't exist for a while when being updated.
        // making the switch instantaneous would require another layer of indirection
        // - not using file_id as canonical id, but some other id, mapped to a file.
        // there would still remain a moment between mapping from old file to new file
        // involving two separate file items and a moment in time when during a switch
        // no file would match a filename, nor file id.
        gridfs.remove(currentId);
    }
    if (content instanceof File) {
        blob = gridfs.createFile((File) content);
    } else if (content instanceof InputStream) {
        blob = gridfs.createFile((InputStream) content);
    } else if (content instanceof ByteBuf) {
        blob = gridfs.createFile(((ByteBuf) content).array());
    } else {
        throw new IllegalArgumentException("Unsupported value supplied: " + content.getClass());
    }

    // meta data
    if (fileExists) {
        blob.setId(currentId);
    }
    blob.setFilename(fileInfo().getString("filename"));
    blob.setContentType(contentType != null ? contentType.toString() : "application/octet-stream");
    blob.put("parent", fileInfo().getParentId());
    blob.save();

    String oid = blob.getId().toString();

    return new GridFSFilesPathItemResource(ctx,
            getFilesRoot(), oid, new GridFSDBObject(blob), GridFSResourcePath.fromContext(ctx));
}
 
开发者ID:liveoak-io,项目名称:liveoak,代码行数:43,代码来源:GridFSBlobResource.java


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