Package com.mongodb.gridfs

Examples of com.mongodb.gridfs.GridFSInputFile.save()


    }

    private String writeBlob(byte[] blob) {
        GridFS gridFS = mongoConnection.getGridFS();
        GridFSInputFile gridFSInputFile = gridFS.createFile(new ByteArrayInputStream(blob), true);
        gridFSInputFile.save();
        return gridFSInputFile.getMD5();
    }
}
View Full Code Here


            is.close();
            return md5;
        }

        GridFSInputFile gridFSInputFile = gridFS.createFile(bis, true);
        gridFSInputFile.save();
        return gridFSInputFile.getMD5();
    }

    private String calculateMd5(BufferedInputStream bis) throws IOException {
        bis.mark(Integer.MAX_VALUE);
View Full Code Here

            blob[i] = (byte) i;
        }
        ByteArrayInputStream is = new ByteArrayInputStream(blob);
        GridFS gridFS = mongoConnection.getGridFS();
        GridFSInputFile gridFSInputFile = gridFS.createFile(is, true);
        gridFSInputFile.save();
        blobId = gridFSInputFile.getMD5();
    }

    @Test
    public void testReadBlobComplete() throws Exception {
View Full Code Here

  private ObjectId saveGridFile(byte[] bytes)
  {
    try
    {
      GridFSInputFile file = DbManager.getSocial().getShareBinary().createFile(bytes);
      file.save();
      return (ObjectId) file.getId();
    }
    catch (Exception ex){}
    return null;
  }
View Full Code Here

  {
    try
    {
      //create new file
      GridFSInputFile file = DbManager.getSocial().getShareBinary().createFile(bytes);
      file.save();
     
      //remove old file if exists (this way if file throws an exception we don't lose the old file)
      if ( binaryId != null )
        DbManager.getSocial().getShareBinary().remove(binaryId);
     
View Full Code Here

                    file.setContentType(contentType);
                }
                if (metadata != null) {
                    file.setMetaData(metadata);
                }
                file.save();
                return file;
            }

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

  public static void saveFile(String fileName, byte[] data) {
    GridFS fs = new GridFS(db());
    GridFSInputFile in = fs.createFile(data);
    in.setId(fileName);
    in.save();
  }

  public static byte[] getFile(String fileName) {
    try {
      GridFS fs = new GridFS(db());
View Full Code Here

      GridFSInputFile file = gridFS.createFile(new File(
          "test-files/sample.txt"));

      file.setId("sample.txt");

      file.save();

      List<GridFSDBFile> files = gridFS.find((DBObject) JSON
          .parse("{ _id : 'sample.txt' }"));

      assertNotNull(files);
View Full Code Here

            }

            GridFS gridFS = new GridFS(mongoInstance.getDB(dbName), bucketName);
            GridFSInputFile fsInputFile = gridFS.createFile(inputStream, fileData.getFileName());
            fsInputFile.setContentType(formData.getMediaType().toString());
            fsInputFile.save();
            String objectId = JSON.serialize(fsInputFile.getId());
            JSONObject obj = new JSONObject();
            obj.put("name", fsInputFile.getFilename());
            obj.put("size", fsInputFile.getLength());
            obj.put("url", String.format("services/%s/%s/gridfs/getfile?id=%s&download=%s&connectionId=%s&ts=%s", dbName, bucketName, objectId, false, connectionId, new Date()));
View Full Code Here

        try {

            if (cacheWriteEnable) {
                final GridFSInputFile gfsFile = MongoConnectionHelper.getGridFS().createFile(f);
                gfsFile.setFilename(f.getName());
                gfsFile.save();

                final Cache c = new Cache();
                c.setServletName(this.getClass().getName());
                c.setCacheKey(cacheKey);
                c.setGridId(gfsFile.getId().toString());
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.