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


Java GridFS.findOne方法代码示例

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


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

示例1: isExistedImage

import com.mongodb.gridfs.GridFS; //导入方法依赖的package包/类
private String isExistedImage(BundleEntry entry) {
    GridFS gridFS = getInstance();
    DBObject query = new BasicDBObject();
    query.put("crc",entry.crc);
    query.put("md5_source",entry.md5);
    GridFSDBFile _current = gridFS.findOne(query);
    //根据MD5值查询,检测是否存在
    if(_current == null) {
        return null;
    }
    String format = (String)_current.get("format");
    if(format.startsWith(".")) {
        return _current.getFilename() + format;
    }
    return _current.getFilename() + "." + format;
}
 
开发者ID:javahongxi,项目名称:whatsmars,代码行数:17,代码来源:GridFSClient.java

示例2: storeBlob

import com.mongodb.gridfs.GridFS; //导入方法依赖的package包/类
@Override
public Boolean storeBlob(CallingContext context, String docPath, InputStream newContent, Boolean append) {
    GridFS gridFS = getGridFS();
    GridFSInputFile file;
    if (!append) {
        gridFS.remove(docPath);
        file = createNewFile(docPath, newContent);
    } else {
        GridFSDBFile existing = gridFS.findOne(docPath);
        if (existing != null) {
            try {
                file = updateExisting(context, docPath, newContent, gridFS, existing);
            } catch (IOException e) {
                file = null;
                log.error(String.format("Error while appending to docPath %s: %s", docPath, ExceptionToString.format(e)));
            }

        } else {
            file = createNewFile(docPath, newContent);
        }
    }
    return file != null;
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:24,代码来源:GridFSBlobHandler.java

示例3: deleteBlob

import com.mongodb.gridfs.GridFS; //导入方法依赖的package包/类
@Override
public Boolean deleteBlob(CallingContext context, String docPath) {
    GridFS gridFS = getGridFS();
    String lockKey = createLockKey(gridFS, docPath);
    LockHandle lockHandle = grabLock(context, lockKey);
    boolean retVal = false;
    try {
        if (gridFS.findOne(docPath) != null) {
            gridFS.remove(docPath);
            retVal = true;
        }
    } finally {
        releaseLock(context, lockKey, lockHandle);
    }
    return retVal;
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:17,代码来源:GridFSBlobHandler.java

示例4: getBlob

import com.mongodb.gridfs.GridFS; //导入方法依赖的package包/类
@Override
public InputStream getBlob(CallingContext context, String docPath) {
    GridFS gridFS = getGridFS();
    String lockKey = createLockKey(gridFS, docPath);
    LockHandle lockHandle = grabLock(context, lockKey);
    InputStream retVal = null;
    try {
        GridFSDBFile file = gridFS.findOne(docPath);
        if (file != null) {
            retVal = file.getInputStream();
        }
    } finally {
        releaseLock(context, lockKey, lockHandle);
    }
    return retVal;
}
 
开发者ID:RapturePlatform,项目名称:Rapture,代码行数:17,代码来源:GridFSBlobHandler.java

示例5: 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

示例6: getBlob

import com.mongodb.gridfs.GridFS; //导入方法依赖的package包/类
@Override
public Blob getBlob(String container, String name, GetOptions options) {
    GridFSIdentifier identifier = parseGridFSIdentifier(container);
    if (!identifier.storeExists(mongo)) {
        throw new ContainerNotFoundException(container, "could not find expected collections in database");
    }
    // TODO: support get options
    if (options != null && (
            options.getIfMatch() != null || options.getIfNoneMatch() != null ||
                    options.getIfModifiedSince() != null || options.getIfUnmodifiedSince() != null ||
                    !options.getRanges().isEmpty()
    )) {
        throw new IllegalArgumentException("Get options are not currently supported by this provider");
    }
    GridFS gridFS = identifier.connect(mongo); // TODO: cache
    GridFSDBFile dbFile = gridFS.findOne(name);
    if (dbFile == null) {
        return null;
    }
    Blob blob = dbFileToBlob.apply(dbFile);
    blob.getMetadata().setContainer(container);
    return blob;
}
 
开发者ID:mhurne,项目名称:jclouds-gridfs-blobstore,代码行数:24,代码来源:GridFSBlobStore.java

示例7: 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

示例8: 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

示例9: getFile

import com.mongodb.gridfs.GridFS; //导入方法依赖的package包/类
public InputStream getFile(String filename) {
    GridFS gridFS = getInstance();
    GridFSDBFile _current = gridFS.findOne(filename);
    if(_current == null) {
        return null;
    }
    return _current.getInputStream();
}
 
开发者ID:javahongxi,项目名称:whatsmars,代码行数:9,代码来源:GridFSClient.java

示例10: getImage

import com.mongodb.gridfs.GridFS; //导入方法依赖的package包/类
public InputStream getImage(String filename,String path) throws Exception{
    //获取最大边,等比缩放
    if(ImageSizeEnum.valueOfPath(path) == null) {
        return null;
    }

    GridFS gridFS = getInstance();
    GridFSDBFile _current = gridFS.findOne(filename);
    if(_current == null) {
        return null;
    }

    int size = ImageSizeEnum.valueOfPath(path).size;

    int max = (Integer)_current.get("max");//图片的实际尺寸

    InputStream result = null;
    //裁剪
    if(size < max) {
        InputStream inputStream = _current.getInputStream();
        BufferedImage image = ImageIO.read(inputStream);

        inputStream.close();
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        BufferedImage thumbnail = Scalr.resize(image, size);//保留最大尺寸
        String format = (String) _current.get("format");
        ImageIO.write(thumbnail, format, bos);
        result = new ByteArrayInputStream(bos.toByteArray());
    } else {
        result = _current.getInputStream();
    }

    return result;
}
 
开发者ID:javahongxi,项目名称:whatsmars,代码行数:35,代码来源:GridFSClient.java

示例11: testGetImage

import com.mongodb.gridfs.GridFS; //导入方法依赖的package包/类
protected static void testGetImage(GridFS gridFS,String filename,String path) {
    DBObject query = new BasicDBObject();
    query.put("md5_source","9e131ae4ed7337d4712650229b827725");
    GridFSDBFile file = gridFS.findOne(query);
    if(file != null) {
        System.out.println(file.getFilename());
    }
}
 
开发者ID:javahongxi,项目名称:whatsmars,代码行数:9,代码来源:GridFSClient.java

示例12: removeGridFsFile

import com.mongodb.gridfs.GridFS; //导入方法依赖的package包/类
private void removeGridFsFile(Id id) {
    DB db = (DB) connections.getConnection("mongodb.dma");
    GridFS fs = new GridFS(db);
    GridFSDBFile file = fs.findOne(new BasicDBObject("_id", id.num()));
    if (file != null) {
        fs.remove(new BasicDBObject("_id", id.num()));
    }
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:9,代码来源:DefaultMediaAssetService.java

示例13: getGridFsFile

import com.mongodb.gridfs.GridFS; //导入方法依赖的package包/类
@Override
public GridFSDBFile getGridFsFile(Id id) {
    DB db = (DB) connections.getConnection("mongodb.dma");
    GridFS fs = new GridFS(db);
    GridFSDBFile file = fs.findOne(new BasicDBObject("_id", id.num()));
    return file;
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:8,代码来源:DefaultMediaAssetService.java

示例14: getArtifact

import com.mongodb.gridfs.GridFS; //导入方法依赖的package包/类
@Override
public Artifact getArtifact(DBKey dbKey, String objectID) {
  Artifact artifact = null;

  GridFS gfs = getGridFS(dbKey);
  BasicDBObject query = new BasicDBObject();
  query.put(ID_FIELD_NAME, new ObjectId(objectID));
  GridFSDBFile file = gfs.findOne(query);
  if (file != null) {
    artifact = new Artifact(file.getInputStream(), file.getContentType());
  }
  return artifact;
}
 
开发者ID:Cognifide,项目名称:aet,代码行数:14,代码来源:ArtifactsDAOMongoDBImpl.java

示例15: findAssetBasicDBFile

import com.mongodb.gridfs.GridFS; //导入方法依赖的package包/类
private GridFSDBFile findAssetBasicDBFile(String repositoryDocId, String filename) {
    GridFS gfs = new GridFS(db, MongoCollectionsInterface.GROBID_ASSETS);
    BasicDBObject whereQuery = new BasicDBObject();
    whereQuery.put("repositoryDocId", repositoryDocId);
    whereQuery.put("filename", filename);
    GridFSDBFile cursor = gfs.findOne(whereQuery);
    return cursor;
}
 
开发者ID:anHALytics,项目名称:anhalytics-core,代码行数:9,代码来源:MongoFileManager.java


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