本文整理汇总了Java中com.mongodb.gridfs.GridFSInputFile.setContentType方法的典型用法代码示例。如果您正苦于以下问题:Java GridFSInputFile.setContentType方法的具体用法?Java GridFSInputFile.setContentType怎么用?Java GridFSInputFile.setContentType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.gridfs.GridFSInputFile
的用法示例。
在下文中一共展示了GridFSInputFile.setContentType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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());
}
}
示例2: 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());
}
}
示例3: 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;
}
示例4: 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();
}
示例5: 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());
}
示例6: execute
import com.mongodb.gridfs.GridFSInputFile; //导入方法依赖的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() );
}
示例7: 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
示例8: 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
示例9: saveArtifact
import com.mongodb.gridfs.GridFSInputFile; //导入方法依赖的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;
}
示例10: build
import com.mongodb.gridfs.GridFSInputFile; //导入方法依赖的package包/类
public GridFSInputFile build(IGridFSSession gridFS) throws Exception {
GridFSInputFile _inFile = null;
switch (__type) {
case 1: // is File
_inFile = gridFS.getGridFS().createFile((File) __targetObject);
break;
case 2: // is InputStream
_inFile = gridFS.getGridFS().createFile((InputStream) __targetObject);
break;
case 3: // is Array
_inFile = gridFS.getGridFS().createFile((byte[]) __targetObject);
}
if (_inFile != null) {
_inFile.setFilename(__filename);
_inFile.setContentType(__contentType);
if (__chunkSize > 0) {
_inFile.setChunkSize(__chunkSize);
}
if (!__attributes.isEmpty()) {
for (Map.Entry<String, Object> _entry : __attributes.entrySet()) {
_inFile.put(_entry.getKey(), _entry.getValue());
}
}
}
return _inFile;
}
示例11: getFileOutputStream
import com.mongodb.gridfs.GridFSInputFile; //导入方法依赖的package包/类
private OutputStream getFileOutputStream(String id, String contentType) {
if (mFS != null) {
try {
deleteFile(id);
GridFSInputFile dbFile = mFS.createFile(id);
if (contentType != null) {
dbFile.setContentType(contentType);
}
return dbFile.getOutputStream();
} catch (Exception e) {
e.printStackTrace();
}
}
return null;
}
示例12: insertTei
import com.mongodb.gridfs.GridFSInputFile; //导入方法依赖的package包/类
/**
* Inserts generated tei using GridFS.
*/
public void insertTei(TEIFile tei, String date, String collection) {
try {
GridFS gfs = new GridFS(db, collection);
gfs.remove(tei.getFileName());
GridFSInputFile gfsFile = gfs.createFile(new ByteArrayInputStream(tei.getTei().getBytes()), true);
gfsFile.put("uploadDate", Utilities.parseStringDate(date));
gfsFile.setFilename(tei.getFileName());
gfsFile.put("repositoryDocId", tei.getRepositoryDocId());
if (collection.equals(MongoCollectionsInterface.METADATAS_TEIS)) {
String anhalyticsID = generateAnhalyticsId(tei.getRepositoryDocId(), tei.getDoi(), (tei.getPdfdocument() != null) ? tei.getPdfdocument().getUrl() : null);
gfsFile.put("anhalyticsId", anhalyticsID);
if (tei.getPdfdocument() != null) {
tei.getPdfdocument().setAnhalyticsId(anhalyticsID);
}
for (BinaryFile annex : tei.getAnnexes()) {
annex.setAnhalyticsId(anhalyticsID);
}
} else {
gfsFile.put("anhalyticsId", tei.getAnhalyticsId());
}
gfsFile.put("source", tei.getSource());
gfsFile.put("version", tei.getRepositoryDocVersion());
gfsFile.put("documentType", tei.getDocumentType());
gfsFile.setContentType(tei.getFileType());
gfsFile.save();
} catch (ParseException e) {
logger.error(e.getMessage(), e.getCause());
}
}
示例13: 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());
}
}
}
}
}
}
}
示例14: 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());
}
示例15: 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;
}