Package com.mongodb.gridfs

Examples of com.mongodb.gridfs.GridFSDBFile


                log.info("cacheKey:" + cacheKey + " on servletName: " + this.getClass().getName() + " not found");
            }

            if (c != null) {
                log.debug("get file from cache id: " + c.getGridId());
                final GridFSDBFile imageForOutput = MongoConnectionHelper.getGridFS().findOne(new ObjectId(c.getGridId()));
                if (imageForOutput != null) {

                    ds.save(c);

                    try {
                        response.setHeader("Content-Length", "" + imageForOutput.getLength());
                        response.setHeader("Content-Disposition", "inline; filename=\"" + imageForOutput.getFilename() + "\"");
                        final OutputStream out = response.getOutputStream();
                        final InputStream in = imageForOutput.getInputStream();
                        final byte[] content = new byte[(int) imageForOutput.getLength()];
                        in.read(content);
                        out.write(content);
                        in.close();
                        out.close();
                        return;
View Full Code Here


            if (c == null) {
                log.info("cacheKey:" + cacheKey + " on servletName: " + this.getClass().getName() + " not found");
            }

            if (c != null) {
                final GridFSDBFile imageForOutput = MongoConnectionHelper.getGridFS().findOne(new ObjectId(c.getGridId()));
                if (imageForOutput != null) {
                    ds.save(c);

                    try {
                        response.setHeader("Content-Length", "" + imageForOutput.getLength());
                        response.setHeader("Content-Disposition", "inline; filename=\"" + imageForOutput.getFilename() + "\"");
                        final OutputStream out = response.getOutputStream();
                        final InputStream in = imageForOutput.getInputStream();
                        final byte[] content = new byte[(int) imageForOutput.getLength()];
                        in.read(content);
                        out.write(content);
                        in.close();
                        out.close();
                        return;
View Full Code Here

   * (non-Javadoc)
   * @see org.springframework.core.io.ResourceLoader#getResource(java.lang.String)
   */
  public GridFsResource getResource(String location) {

    GridFSDBFile file = findOne(query(whereFilename().is(location)));
    return file != null ? new GridFsResource(file) : null;
  }
View Full Code Here

    return getDocumentFile(d.getID(), filename);
  }
 
  private DocumentFile<MongoType> getDocumentFile(DocumentID<MongoType> id, String filename) {
    DBObject query = QueryBuilder.start(DOCUMENT_KEY).is(id.getID()).and(FILENAME_KEY).is(filename).get();
    GridFSDBFile file = documentfs.findOne(query);
    if(file==null) {
      return null;
    }
   
    DocumentFile<MongoType> df =  new DocumentFile<MongoType>(id, file.getFilename(), file.getInputStream(), (String)file.get(STAGE_KEY), file.getUploadDate());

    if(file.containsField(MIMETYPE_KEY)) {
      df.setMimetype((String) file.get(MIMETYPE_KEY));
    }
   
    if(file.containsField(ENCODING_KEY)) {
      df.setEncoding((String) file.get(ENCODING_KEY));
    }
   
    return df;
  }
View Full Code Here

    return pipelinefs;
  }
 
  @Override
  public InputStream getStream(DatabaseFile df) {
    GridFSDBFile file = pipelinefs.findOne(new BasicDBObject(MongoDocument.MONGO_ID_KEY, df.getId()));
    return file==null ? null : file.getInputStream();
  }
View Full Code Here

                .as(CustomFileDescriptor.class);
        assertThat(descriptor.filename).isEqualTo("test.txt");
    }

    private void queryWithJongoAndMapToGridFSDBFile() {
        GridFSDBFile gridFile = getJongo().getCollection("fs.files")
                .findOne()
                .map(asRaw(GridFSDBFile.class));
        assertThat(gridFile.getFilename()).isEqualTo("test.txt");
    }
View Full Code Here

                .map(asRaw(GridFSDBFile.class));
        assertThat(gridFile.getFilename()).isEqualTo("test.txt");
    }

    private void queryWithGridFS() {
        GridFSDBFile gridFile = gridFS.findOne(new BasicDBObject());
        assertThat(gridFile.getFilename()).isEqualTo("test.txt");
    }
View Full Code Here

        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

TOP

Related Classes of com.mongodb.gridfs.GridFSDBFile

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.