Package com.mongodb.gridfs

Examples of com.mongodb.gridfs.GridFS.findOne()


    response.setHeader("Content-disposition", "attachment;filename="
        + new String(fileName.getBytes(), "iso8859-1"));

    OutputStream os = response.getOutputStream();
    GridFS gridFs = new GridFS(mongoTemplate.getDb(), folder);
    GridFSDBFile gridFSDBFile = gridFs.findOne(fileName);

    FileCopyUtils.copy(gridFSDBFile.getInputStream(), os);
   
    os.flush();
    os.close();
View Full Code Here


        // Optional bucket, default is "fs"
        String bucket = jsonObject.getString("bucket", GridFS.DEFAULT_BUCKET);
        GridFS files = new GridFS(db, bucket);

        GridFSDBFile file = files.findOne(objectId);
        if (file == null) {
            sendError(message, "File does not exist: " + objectId.toString());
            return;
        }
View Full Code Here

            RepositoryDocument rd = new RepositoryDocument();
            if (Logging.connectors.isDebugEnabled()) {
                Logging.connectors.debug("GridFS: Processing document _id = " + _id);
            }

            GridFSDBFile document = gfs.findOne(new ObjectId(_id));

            if (document == null) {
                activities.deleteDocument(_id);
                i++;
                continue;
View Full Code Here

        getSession();
        int i = 0;
        while (i < versions.length) {
            String _id = documentIdentifiers[i];
            GridFS gridfs = new GridFS(session, bucket);
            GridFSDBFile document = gridfs.findOne(new ObjectId(_id));
            if (document == null) {
                versions[i] = null;
            } else {
                DBObject metadata = document.getMetaData();
                versions[i] = document.getMD5() + "+" + metadata != null
View Full Code Here

    DB mdb = this.mongoConn.getDatabase(this.collection);
    GridFS gfsFile = new GridFS(mdb, this.namespace);
 
    // get file file by it's filename
    GridFSDBFile fileForOutput = null;
    fileForOutput = gfsFile.findOne(id);
    if (fileForOutput == null)
    {
      this.logger.error("[File][GridFS] Can not retrieve item: {}", id);
      throw new IllegalStateException(id + " Item not found in Mongo database");
    }
View Full Code Here


        System.out.println("Saved the file to MongoDB");
        System.out.println("Now lets read it back out");

        GridFSDBFile gridFile = videos.findOne(new BasicDBObject("filename", "video.mp4"));

        FileOutputStream outputStream = new FileOutputStream("video_copy.mp4");
        gridFile.writeTo(outputStream);

        System.out.println("Write the file back out");
View Full Code Here

        return blob;
    }

    private void readBlob(String blobId, byte[] readBlob) throws IOException {
        GridFS gridFS = mongoConnection.getGridFS();
        GridFSDBFile gridFile = gridFS.findOne(new BasicDBObject("md5", blobId));
        IOUtils.readFully(gridFile.getInputStream(), readBlob, 0, readBlob.length);
    }
}
View Full Code Here

    }

    @Override
    public Long execute() throws Exception {
        GridFS gridFS = mongoConnection.getGridFS();
        GridFSDBFile gridFSDBFile = gridFS.findOne(new BasicDBObject("md5", blobId));
        if (gridFSDBFile == null) {
            throw new Exception("Blob does not exiss");
        }
        return gridFSDBFile.getLength();
    }
View Full Code Here

    private String saveBlob() throws IOException {
        GridFS gridFS = mongoConnection.getGridFS();
        BufferedInputStream bis = new BufferedInputStream(is);
        String md5 = calculateMd5(bis);
        GridFSDBFile gridFile = gridFS.findOne(new BasicDBObject("md5", md5));
        if (gridFile != null) {
            is.close();
            return md5;
        }
View Full Code Here

    // FIXME [Mete] This takes a long time, see MicroKernelIT#readBlob. See if
    // it can be improved.
    private int fetchBlobFromMongo() throws Exception {
        GridFS gridFS = mongoConnection.getGridFS();
        GridFSDBFile gridFile = gridFS.findOne(new BasicDBObject("md5", blobId));
        long fileLength = gridFile.getLength();

        long start = blobOffset;
        long end = blobOffset + length;
        if (end > fileLength) {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.