本文整理汇总了Java中com.mongodb.gridfs.GridFSInputFile.setFilename方法的典型用法代码示例。如果您正苦于以下问题:Java GridFSInputFile.setFilename方法的具体用法?Java GridFSInputFile.setFilename怎么用?Java GridFSInputFile.setFilename使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.gridfs.GridFSInputFile
的用法示例。
在下文中一共展示了GridFSInputFile.setFilename方法的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);
}
示例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());
}
}
示例3: 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());
}
}
示例4: 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());
}
}
示例5: 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());
}
}
示例6: 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());
}
}
示例7: 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());
}
}
示例8: 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;
}
示例9: 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);
}
}
示例10: 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);
}
}
示例11: 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);
}
示例12: 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());
}
示例13: openOutputStream
import com.mongodb.gridfs.GridFSInputFile; //导入方法依赖的package包/类
@Override
synchronized public OutputStream openOutputStream(final byte[] key) {
return new ByteArrayOutputStream(256) {
@Override
public void close() throws IOException {
super.close();
byte[] keyString = adoptKey(key);
byte[] byteArray = toByteArray();
if (byteArray.length < MAX_BSON_SIZE) {
collection.update(new BasicDBObject(KEY, keyString), new BasicDBObject(KEY, keyString).append(TYPE, TYPE_BSON).append(VALUE, byteArray), true, false);
} else {
// do grid fs
GridFSInputFile gridFsFile = gridFs.createFile(byteArray);
String fileName = URIUtils.encode(key);
gridFsFile.setFilename(fileName);
gridFsFile.save();
collection.update(new BasicDBObject(KEY, keyString), new BasicDBObject(KEY, keyString).append(TYPE, TYPE_GRID_FS).append(FILE_NAME, fileName), true, false);
}
}
};
}
示例14: create
import com.mongodb.gridfs.GridFSInputFile; //导入方法依赖的package包/类
@Override
public boolean create(String filename, byte[] data) {
this.delete(filename);
GridFSInputFile file = getGridFS().createFile(data);
file.setFilename(filename);
file.save();
return true;
}
示例15: put
import com.mongodb.gridfs.GridFSInputFile; //导入方法依赖的package包/类
@Override
public void put(String keyText, T obj) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream objectOutput = new ObjectOutputStream(baos);
objectOutput.writeObject(obj);
objectOutput.close();
byte[] binaryObject = baos.toByteArray();
GridFSInputFile objFile = gridfs.createFile(binaryObject);
objFile.setFilename(DigestUtils.sha256Hex(keyText));
//it will not update content of existing file
objFile.save();
}