Package com.mongodb.gridfs

Examples of com.mongodb.gridfs.GridFSDBFile$MyInputStream


        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
                        ? Integer.toString(metadata.hashCode())
                        : StringUtils.EMPTY;
            }
            i++;
        }
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");
    }
    //kind of clone
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try
     
      fileForOutput.writeTo(baos);

    } catch (IOException e) {
      this.logger.error("Error getting file: {}", e.toString());
    }
   
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

    public Integer execute() throws Exception {
        return fetchBlobFromMongo();
    }

    private int fetchBlobFromMongo() throws Exception {
        GridFSDBFile gridFile = gridFS.findOne(new BasicDBObject("md5", blobId));
        long fileLength = gridFile.getLength();
        long start = blobOffset;
        long end = blobOffset + length;
        if (end > fileLength) {
            end = fileLength;
        }
        length = (int) (end - start);

        if (start < end) {
            InputStream is = gridFile.getInputStream();
            if (blobOffset > 0) {
                IOUtils.skipFully(is, blobOffset);
            }
            IOUtils.readFully(is, buffer, bufferOffset, length);
            is.close();
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) {
            end = fileLength;
        }

        int totalBytes = -1;
        if (start < end) {
            InputStream is = gridFile.getInputStream();
            IOUtils.skipFully(is, blobOffset);
            totalBytes = is.read(buffer, bufferOffset, length);
            is.close();
        }
        return totalBytes;
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;
        }

        JsonObject fileInfo = new JsonObject()
                .putString("filename", file.getFilename())
                .putString("contentType", file.getContentType())
                .putNumber("length", file.getLength())
                .putNumber("chunkSize", file.getChunkSize())
                .putNumber("uploadDate", file.getUploadDate().getTime());

        DBObject metadata = file.getMetaData();
        if (metadata != null) {
            fileInfo.putObject("metadata", new JsonObject(JSON.serialize(metadata)));
        }

        // Send file info
View Full Code Here

     
      if (!tempFile.exists() || (tempFile.lastModified() < share.getModified().getTime())) {
        OutputStream out = new BufferedOutputStream(new FileOutputStream(tempFileName));
        if ( share.getBinaryId() != null )
        {     
          GridFSDBFile file = DbManager.getSocial().getShareBinary().find(share.getBinaryId());           
          file.writeTo(out);       
        }
        else
        {
          out.write(share.getBinaryData());
        }
View Full Code Here

TOP

Related Classes of com.mongodb.gridfs.GridFSDBFile$MyInputStream

Copyright © 2018 www.massapicom. 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.