本文整理汇总了Java中com.mongodb.gridfs.GridFSInputFile.setMetaData方法的典型用法代码示例。如果您正苦于以下问题:Java GridFSInputFile.setMetaData方法的具体用法?Java GridFSInputFile.setMetaData怎么用?Java GridFSInputFile.setMetaData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.gridfs.GridFSInputFile
的用法示例。
在下文中一共展示了GridFSInputFile.setMetaData方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
}
示例3: putBlob
import com.mongodb.gridfs.GridFSInputFile; //导入方法依赖的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();
}
示例4: save
import com.mongodb.gridfs.GridFSInputFile; //导入方法依赖的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());
}
示例5: embedSteps
import com.mongodb.gridfs.GridFSInputFile; //导入方法依赖的package包/类
/**
* go through all the embedded content, store it to GridFS, replace the doc embeddings with a hyperlink to the saved content.
*/
protected void embedSteps(final DBObject feature, final GridFS gridFS, final Coordinates coordinates) {
final BasicDBList elements = (BasicDBList) feature.get("elements");
final String featureId = (String) feature.get("_id");
if (elements != null) {
for (int j = 0; j < elements.size(); j++) {
final DBObject scenario = (DBObject) elements.get(j);
final String scenarioId = (String) scenario.get("_id");
final BasicDBList steps = (BasicDBList) scenario.get("steps");
if (steps != null) {
for (int k = 0; k < steps.size(); k++) {
final DBObject step = (DBObject) steps.get(k);
final BasicDBList embeddings = (BasicDBList) step.get("embeddings");
if (embeddings != null) {
for (int l = 0; l < embeddings.size(); l++) {
final DBObject embedding = (DBObject) embeddings.get(l);
final GridFSInputFile image = gridFS
.createFile(Base64.decodeBase64(((String) embedding.get("data")).getBytes()));
image.setFilename(guid());
final BasicDBObject metadata = new BasicDBObject().append("product", coordinates.getProduct())
.append("major", coordinates.getMajor()).append("minor", coordinates.getMinor())
.append("servicePack", coordinates.getServicePack()).append("build", coordinates.getBuild())
.append("feature", featureId)
.append("scenario", scenarioId);
image.setMetaData(metadata);
image.setContentType((String) embedding.get("mime_type"));
image.save();
embeddings.put(l, image.getFilename());
}
}
}
}
}
}
}
示例6: createFileWriteBean
import com.mongodb.gridfs.GridFSInputFile; //导入方法依赖的package包/类
@Override
public FileStorage.FileWriteBean createFileWriteBean(Id id, FileStorage.FileMetaBean meta) {
meta.setLastModified(new Date());
meta.setCreated(new Date());
GridFS fs = new GridFS(MongoDBConnectionHelper.getConnection(id.getDatabase()), id.getCollection());
fs.remove(id.getEntity());
GridFSInputFile gfsFile = fs.createFile(id.getEntity());
gfsFile.setContentType(meta.getContentType());
gfsFile.setMetaData(MongoDBFormat.fromMap(meta.toMap()));
GridFSFileWriteBean gridFSFileWriteBean = new GridFSFileWriteBean(id,gfsFile.getOutputStream(),meta);
gridFSFileWriteBean.gfsFile = gfsFile;
return gridFSFileWriteBean;
}
示例7: 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;
}
}