Package com.mongodb.gridfs

Examples of com.mongodb.gridfs.GridFSDBFile.writeTo()


    }
    //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("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

      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

  {
    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

  {
    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

                    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

  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

            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

      return null;
    } else {
      return new AttachmentData() {
        @Override
        public void writeDataTo(OutputStream out) throws IOException {
          attachment.writeTo(out);
        }

        @Override
        public Date getLastModifiedDate() {
          return attachment.getUploadDate();
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.