Example usage for com.mongodb.gridfs GridFS GridFS

List of usage examples for com.mongodb.gridfs GridFS GridFS

Introduction

In this page you can find the example usage for com.mongodb.gridfs GridFS GridFS.

Prototype

public GridFS(final DB db, final String bucket) 

Source Link

Document

Creates a GridFS instance for the specified bucket in the given database.

Usage

From source file:in.mtap.iincube.mongoapi.GridFsRequestBuilder.java

License:Apache License

protected GridFS getGridFs() {
    return new GridFS(mongo.getDB(dbname), bucketname);
}

From source file:in.mtap.iincube.mongoapi.MongoCollectionFactory.java

License:Apache License

public GridFS getGridFs() {
    return new GridFS(mongo.getDB(dbname), colname);
}

From source file:io.liveoak.mongo.gridfs.GridFSUserspaceResource.java

License:Open Source License

public GridFS getGridFS() {
    return new GridFS(getRoot().getDB(), id());
}

From source file:it.marcoberri.mbfasturl.helper.MongoConnectionHelper.java

License:Apache License

/**
 * // w w  w . j  a  v a 2 s .  c o  m
 * @return
 */
public static GridFS getGridFS() {
    if (gridFS == null) {
        gridFS = new GridFS(ds.getDB(), GRIDCOLLECTIONNAME);
    }
    return gridFS;
}

From source file:me.yyam.mongodbutils.MongoDbOperater.java

/**
 * mongodb// w w  w.j  av a 2 s .c  o  m
 * @param dbName ???
 * @param fsName  GridFS???fsnull?
 * @param input ??
 * @param fsFileName GridFS??
 * @throws FileNotFoundException
 * @throws IOException 
 */
public void upload2GridFS(String dbName, String fsName, InputStream input, String fsFileName)
        throws FileNotFoundException, IOException {
    DB db = mongoClient.getDB(dbName);
    if (fsName == null) {
        fsName = "fs";
    }
    GridFS fs = new GridFS(db, fsName);
    GridFSInputFile fsFile = fs.createFile(input);
    if (StringUtils.isBlank(fsFileName)) {
        throw new FileNotFoundException("gridfs????fsFileName");
    }
    fsFile.setFilename(fsFileName);
    fsFile.save();
}

From source file:me.yyam.mongodbutils.MongoDbOperater.java

public void upload2GridFS(String dbName, String fsName, byte[] bytes, String fsFileName)
        throws FileNotFoundException, IOException {
    DB db = mongoClient.getDB(dbName);/*from w  ww. jav  a 2  s .  c  o m*/
    if (fsName == null) {
        fsName = "fs";
    }
    GridFS fs = new GridFS(db, fsName);
    GridFSInputFile fsFile = fs.createFile(bytes);
    if (StringUtils.isBlank(fsFileName)) {
        throw new FileNotFoundException("gridfs????fsFileName");
    }
    fsFile.setFilename(fsFileName);
    fsFile.save();
}

From source file:me.yyam.mongodbutils.MongoDbOperater.java

/**
 * GridFS//from   w ww .  j a  v a 2s.  c  o m
 * @param dbName ???
 * @param fsName GridFS???fsnull?
 * @param fsFileName GridFS??
 * @param fileName ???fsFileName??fsFileName??
 * @return ???
 * @throws FileNotFoundException
 * @throws IOException 
 */
public File downloadFsFile(String dbName, String fsName, String fsFileName, String fileName)
        throws FileNotFoundException, IOException {
    if (StringUtils.isBlank(fileName)) {
        fileName = fsFileName;
    }
    File saveFile = new File(fileName);
    if (saveFile.isDirectory()) {
        fileName = saveFile.getPath() + "/" + fsFileName;
    }
    DB db = mongoClient.getDB(dbName);
    if (fsName == null) {
        fsName = "fs";
    }
    GridFS fs = new GridFS(db, fsName);
    GridFSDBFile gfile = fs.findOne(fsFileName);
    if (gfile == null) {
        throw new FileNotFoundException("gridfs" + fsFileName);
    }
    InputStream input = gfile.getInputStream();
    try {
        File f = new File(fileName);
        if (!f.exists()) {
            f.createNewFile();
        }
        OutputStream output = new FileOutputStream(f);
        byte[] bytes = new byte[1024];
        int read = 0;
        while ((read = input.read(bytes)) != -1) {
            output.write(bytes, 0, read);
        }
        output.flush();
        output.close();
        return f;
    } finally {
        input.close();
    }

}

From source file:me.yyam.mongodbutils.MongoDbOperater.java

/**
 * GridFS/*from  w w  w  .j  a  va  2  s . co m*/
 * @param dbName ???
 * @param fsName GridFS???fsnull?
 * @param queryMap GridFS?
 */
public void removeFsFile(String dbName, String fsName, Map queryMap) {
    DB db = mongoClient.getDB(dbName);
    if (fsName == null) {
        fsName = "fs";
    }
    GridFS fs = new GridFS(db, fsName);
    DBObject query = new BasicDBObject(queryMap);
    fs.remove(query);
}

From source file:me.yyam.mongodbutils.MongoDbOperater.java

public byte[] getFsFileBytes(String dbName, String fsName, String fsFileName)
        throws FileNotFoundException, IOException {
    DB db = mongoClient.getDB(dbName);//from www .  ja  v  a  2s.c  o  m
    if (fsName == null) {
        fsName = "fs";
    }
    GridFS fs = new GridFS(db, fsName);
    GridFSDBFile gfile = fs.findOne(fsFileName);
    if (gfile == null) {
        throw new FileNotFoundException("gridfs" + fsFileName);
    }
    InputStream input = gfile.getInputStream();
    try {
        byte[] b = new byte[(int) gfile.getLength()];
        int readCount = 0;
        while (true) {
            int count = input.read(b, readCount, 255);
            if (count <= 0) {
                break;
            }
            readCount += count;
        }
        return b;
    } finally {
        input.close();
    }

}

From source file:mx.org.cedn.avisosconagua.mongo.MongoInterface.java

License:Open Source License

/**
 * Gets a GridFS object to retrieve an image from.
 * @return GridFS object
 */
public GridFS getImagesFS() {
    return new GridFS(mongoDB, IMAGES_COL);
}