Package com.mongodb.gridfs

Examples of com.mongodb.gridfs.GridFSDBFile$MyInputStream


        this.gridFS = gridFS;
    }

    @Override
    public Long execute() throws Exception {
        GridFSDBFile gridFSDBFile = gridFS.findOne(new BasicDBObject("md5", blobId));
        if (gridFSDBFile == null) {
            throw new Exception("Blob does not exist");
        }
        return gridFSDBFile.getLength();
    }
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

    }

    private String saveBlob() throws IOException {
        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

  }

  @Override
  public AttachmentData getAttachment(AttachmentId attachmentId) {

    final GridFSDBFile attachment = getAttachmentGrid().findOne(attachmentId.serialise());

    if (attachment == null) {
      return null;
    } else {
      return new AttachmentData() {

        @Override
        public InputStream getInputStream() throws IOException {
          return attachment.getInputStream();
        }

        @Override
        public long getSize() {
          return attachment.getLength();
        }
      };
    }
  }
View Full Code Here

    public GridFSDBFile findById(String hash) {
        return gridFS.findOne(new BasicDBObject("_id", hash));
    }

    public InputStream findOne(String hash) {
        GridFSDBFile dbFile = gridFS.findOne(new BasicDBObject("_id", hash));
        if (dbFile == null) {
            return null;
        }
        return dbFile.getInputStream();
    }
View Full Code Here

        return results;
    }

    @Override
    public DriftFile getDriftFile(Subject subject, String hashId) throws Exception {
        GridFSDBFile gridFSDBFile = fileDAO.findById(hashId);
        if (gridFSDBFile == null) {
            return null;
        }
        return newDriftFile(hashId, DriftFileStatus.LOADED);
    }
View Full Code Here

        }
    }

    @Override
    public String getDriftFileBits(Subject subject, String hash) {
        GridFSDBFile file = fileDAO.findById(hash);
        if (file == null) {
            return null;
        }
        return new String(StreamUtil.slurp(file.getInputStream()));
    }
View Full Code Here

        return changeSet.getId();
    }

    @Override
    public byte[] getDriftFileAsByteArray(Subject subject, String hash) {
        GridFSDBFile file = fileDAO.findById(hash);
        if (file == null) {
            return null;
        }
        return StreamUtil.slurp(file.getInputStream());
    }
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

    }

    private String saveBlob() throws IOException {
        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

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.