Java Code Examples for com.mongodb.gridfs.GridFSDBFile#getInputStream()

The following examples show how to use com.mongodb.gridfs.GridFSDBFile#getInputStream() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MongoService.java    From BLELocalization with MIT License 6 votes vote down vote up
private boolean readFile(GridFSDBFile dbFile, OutputStream os) throws IOException {
	InputStream is = null;
	try {
		is = dbFile.getInputStream();
		byte data[] = new byte[4096];
		int len = 0;
		while ((len = is.read(data, 0, data.length)) > 0) {
			os.write(data, 0, len);
		}
		return true;
	} finally {
		if (is != null) {
			is.close();
		}
	}
}
 
Example 2
Source File: MongoConstants.java    From lumongo with Apache License 2.0 6 votes vote down vote up
public static byte[] readFileFromGridFS(GridFSDBFile file) {
	InputStream is = file.getInputStream();
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	try {

		byte bytes[] = new byte[BUFFER_SIZE];
		int read = -1;

		while ((read = is.read(bytes)) != -1) {
			baos.write(bytes, 0, read);
		}

		return baos.toByteArray();
	}
	catch (Exception e) {
	}
	return null;
}
 
Example 3
Source File: MongoDbStore.java    From incubator-retired-wave with Apache License 2.0 6 votes vote down vote up
private AttachmentData fileToAttachmentData(final GridFSDBFile attachmant) {
  if (attachmant == null) {
    return null;
  } else {
    return new AttachmentData() {

      @Override
      public InputStream getInputStream() throws IOException {
        return attachmant.getInputStream();
      }

      @Override
      public long getSize() {
        return attachmant.getLength();
      }
    };
  }
}
 
Example 4
Source File: MongoDbStorageService.java    From jsflight with Apache License 2.0 5 votes vote down vote up
@Nullable
private InputStream getStreamByFilename(String fname)
{
    GridFSDBFile file = getGridFsTemplate().findOne(new Query().addCriteria(Criteria.where("filename").is(fname)));

    return file != null ? file.getInputStream() : null;
}
 
Example 5
Source File: MapFileRepositoryCustomImpl.java    From osiris with Apache License 2.0 5 votes vote down vote up
private InputStream getMapFileByAppId(GridFS gridFS,String appIdentifier) throws MapFileNotExistsException{
	InputStream fileMap=null;
	GridFSDBFile gridFSFileMap = gridFS.findOne(appIdentifier);
	if(gridFSFileMap==null){
		throw new MapFileNotExistsException();
	}
	fileMap=gridFSFileMap.getInputStream();
	return fileMap;
}
 
Example 6
Source File: ImageUploader.java    From bugu-mongo with Apache License 2.0 5 votes vote down vote up
private InputStream getOriginalInputStream(){
    DBObject query = new BasicDBObject(BuguFS.FILENAME, filename);
    query.put(DIMENSION, null);
    BuguFS fs = BuguFSFactory.getInstance().create(connection, bucket, chunkSize);
    GridFSDBFile f = fs.findOne(query);
    return f.getInputStream();
}