Package com.mongodb.gridfs

Examples of com.mongodb.gridfs.GridFSDBFile


        String jsonShare = (String) _resultObj.get(SharePojo.share_);
        if (null != jsonShare) {
          return new ByteArrayInputStream(jsonShare.toString().getBytes());         
        }//TESTED (1.4)
        else { // must be binary
          GridFSDBFile file = DbManager.getSocial().getShareBinary().find(_resultObj.getObjectId(SharePojo.binaryId_));
          return file.getInputStream();
        }//TESTED (2.4)
      }
      else if (_isShare) { // then must be a zip file
        try {
          return _zipView.getInputStream(_zipEntry);
View Full Code Here


  private byte[] getGridFile(ObjectId id)
  {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try
    {
      GridFSDBFile file = DbManager.getSocial().getShareBinary().find(id);           
      file.writeTo(out);
      byte[] toReturn = out.toByteArray();
      out.close();
      return toReturn;
    }
    catch (Exception ex){}   
View Full Code Here

  private ByteArrayOutputStream getGridStream(ObjectId id)
  {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try
    {
      GridFSDBFile file = DbManager.getSocial().getShareBinary().find(id)
      file.writeTo(out);       
    }
    catch (Exception ex){}   
    return out;
  }
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

        new DbJob() {

            @Override
            public Object doRun() throws IOException {
                GridFSDBFile dbfile = null;
                if (query != null) {
                    dbfile = getGridFS().findOne(query);
                } else {
                    dbfile = getGridFS().findOne(fname);
                }
                if (dbfile == null) {
                    throw new MongoException("GridFS cannot find file " + fname);
                }
                dbfile.writeTo(dfile);
                return dbfile;
            }

            @Override
            public String getNS() {
View Full Code Here

                post.picture = blob;
                post.insert();
                ObjectId id = post.id;

                post = Post.find().byId(id);
                GridFSDBFile gridFSDBFile = post.picture.getGridFSFile();
                assertThat(gridFSDBFile).isNotNull();

                assertThat(post.title).isEqualTo("fake post");
                assertThat(Post.find().byId(post.id).id).isEqualTo(post.id);
                assertThat(Post.find().byId(post.id).title).isEqualTo(post.title);
View Full Code Here

  }

  public static byte[] getFile(String fileName) {
    try {
      GridFS fs = new GridFS(db());
      GridFSDBFile out = fs.findOne(new BasicDBObject("_id", fileName));
      ByteArrayOutputStream temp = new ByteArrayOutputStream();
      out.writeTo(temp);
      return temp.toByteArray();
    } catch (Exception e) {
      // quiet
    }
    return null;
View Full Code Here

                    "Database with dbName [ " + dbName + "] does not exist");
            }
            Object docId = JSON.parse(_id);
            BasicDBObject objectId = new BasicDBObject("_id", docId);
            GridFS gridFS = new GridFS(mongoInstance.getDB(dbName), bucketName);
            GridFSDBFile gridFSDBFile = gridFS.findOne(objectId);
            String tempDir = System.getProperty("java.io.tmpdir");
            tempFile = new File(tempDir + "/" + gridFSDBFile.getFilename());
            gridFSDBFile.writeTo(tempFile);

        } catch (MongoException m) {
            throw new CollectionException(ErrorCodes.GET_COLLECTION_LIST_EXCEPTION, m.getMessage());
        } catch (IOException e) {
            throw new CollectionException(ErrorCodes.GET_COLLECTION_LIST_EXCEPTION, e.getMessage());
View Full Code Here

        if (bucketName.equals("")) {
            throw new CollectionException(ErrorCodes.COLLECTION_NAME_EMPTY, "Bucket Name Empty");
        }

        String result = null;
        GridFSDBFile gridFSDBFile = null;
        try {
            if (!databaseService.getDbList().contains(dbName)) {
                throw new DatabaseException(ErrorCodes.DB_DOES_NOT_EXISTS, "DB [" + dbName + "] DOES NOT EXIST");
            }
            if (_id == null) {
                throw new DocumentException(ErrorCodes.DOCUMENT_EMPTY, "File is empty");
            }

            GridFS gridFS = new GridFS(mongoInstance.getDB(dbName), bucketName);
            Object docId = JSON.parse(_id);
            BasicDBObject objectId = new BasicDBObject("_id", docId);
            gridFSDBFile = gridFS.findOne(objectId);

            if (gridFSDBFile == null) {
                throw new DocumentException(ErrorCodes.DOCUMENT_DOES_NOT_EXIST, "Document does not exist !");
            }

            gridFS.remove(objectId);

        } catch (MongoException e) {
            throw new DocumentException(ErrorCodes.DOCUMENT_DELETION_EXCEPTION, e.getMessage());
        }
        result = "File [" + gridFSDBFile.getFilename() + "] has been deleted.";
        return result;
    }
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

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.