Package com.mongodb.gridfs

Examples of com.mongodb.gridfs.GridFS


        }
        return blob;
    }

    private void readBlob(String blobId, byte[] readBlob) throws IOException {
        GridFS gridFS = mongoConnection.getGridFS();
        GridFSDBFile gridFile = gridFS.findOne(new BasicDBObject("md5", blobId));
        IOUtils.readFully(gridFile.getInputStream(), readBlob, 0, readBlob.length);
    }
View Full Code Here


        }
        return blob;
    }

    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

     * @param database The database name.
     * @throws Exception If an error occurred while trying to connect.
     */
    public MongoConnection(String host, int port, String database) throws Exception {
        db = new Mongo(host, port).getDB(database);
        gridFS = new GridFS(db);
    }
View Full Code Here

        this.blobId = blobId;
    }

    @Override
    public Long execute() throws Exception {
        GridFS gridFS = mongoConnection.getGridFS();
        GridFSDBFile gridFSDBFile = gridFS.findOne(new BasicDBObject("md5", blobId));
        if (gridFSDBFile == null) {
            throw new Exception("Blob does not exiss");
        }
        return gridFSDBFile.getLength();
    }
View Full Code Here

    public String execute() throws Exception {
        return saveBlob();
    }

    private String saveBlob() throws IOException {
        GridFS gridFS = mongoConnection.getGridFS();
        BufferedInputStream bis = new BufferedInputStream(is);
        String md5 = calculateMd5(bis);
        GridFSDBFile gridFile = gridFS.findOne(new BasicDBObject("md5", md5));
        if (gridFile != null) {
            is.close();
            return md5;
        }

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

    }

    // FIXME [Mete] This takes a long time, see MicroKernelIT#readBlob. See if
    // it can be improved.
    private int fetchBlobFromMongo() throws Exception {
        GridFS gridFS = mongoConnection.getGridFS();
        GridFSDBFile gridFile = gridFS.findOne(new BasicDBObject("md5", blobId));
        long fileLength = gridFile.getLength();

        long start = blobOffset;
        long end = blobOffset + length;
        if (end > fileLength) {
View Full Code Here

        blob = new byte[100];
        for (int i = 0; i < blob.length; i++) {
            blob[i] = (byte) i;
        }
        ByteArrayInputStream is = new ByteArrayInputStream(blob);
        GridFS gridFS = mongoConnection.getGridFS();
        GridFSInputFile gridFSInputFile = gridFS.createFile(is, true);
        gridFSInputFile.save();
        blobId = gridFSInputFile.getMD5();
    }
View Full Code Here

  @Autowired
  private RepositoryHttpManager httpManager;

  @PostConstruct
  private void postConstruct() {
    gridFS = new GridFS(mongoTemplate.getDb());
  }
View Full Code Here

            return;
        }

        // Optional bucket, default is "fs"
        String bucket = jsonObject.getString("bucket", GridFS.DEFAULT_BUCKET);
        GridFS files = new GridFS(db, bucket);

        GridFSDBFile file = files.findOne(objectId);
        if (file == null) {
            sendError(message, "File does not exist: " + objectId.toString());
            return;
        }
View Full Code Here

      }
      return _social_share;
    }
    public GridFS getShareBinary() {
      if (null == _social_share_binary) {
        _social_share_binary = new GridFS(_savedMongo.getDB("file"), "binary_shares");         
      }
      return _social_share_binary;
    }
View Full Code Here

TOP

Related Classes of com.mongodb.gridfs.GridFS

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.