List of usage examples for com.mongodb.gridfs GridFS GridFS
public GridFS(final DB db)
From source file:com.hangum.tadpole.mongodb.core.query.MongoDBQuery.java
License:Open Source License
/** * gridFS//from w w w . j av a2 s . c o m * * @param userDB * @param strBucket * @param strFileName * @param intSkip * @param intLimit * @return * @throws Exception */ public static DBCursor getGridFS(UserDBDAO userDB, String strBucket, String strFileName, int intSkip, int intLimit) throws Exception { DB mongoDb = findDB(userDB); GridFS gridFs = null; if ("".equals(strBucket)) gridFs = new GridFS(mongoDb); else gridFs = new GridFS(mongoDb, strBucket); if ("".equals(strFileName)) { return gridFs.getFileList().skip(intSkip).limit(intLimit); } else { DBObject queryObj = new BasicDBObject(); Pattern regex = Pattern.compile(".*" + strFileName + "*"); queryObj.put("filename", regex); return gridFs.getFileList(queryObj).skip(intSkip).limit(intLimit); } }
From source file:com.hangum.tadpole.mongodb.core.query.MongoDBQuery.java
License:Open Source License
/** * get gridfs data/*w w w .j av a 2 s .c om*/ * * @param userDB * @param _id * @return * @throws Exception */ public static byte[] getGridFS(UserDBDAO userDB, String strBucket, String _id) throws Exception { DB mongoDb = findDB(userDB); GridFS gridFs = null; if ("".equals(strBucket)) gridFs = new GridFS(mongoDb); else gridFs = new GridFS(mongoDb, strBucket); GridFSDBFile gridFSFile = gridFs.findOne(new ObjectId(_id)); InputStream is = gridFSFile.getInputStream(); return IOUtils.toByteArray(is); }
From source file:com.hangum.tadpole.mongodb.core.query.MongoDBQuery.java
License:Open Source License
/** * delte gridfs/*from w ww. j a v a 2 s .c o m*/ * * @param userDB * @param _id * @throws Exception */ public static void dleteGridFs(UserDBDAO userDB, String strBucket, String _id) throws Exception { DB mongoDb = findDB(userDB); GridFS gridFs = null; if ("".equals(strBucket)) gridFs = new GridFS(mongoDb); else gridFs = new GridFS(mongoDb, strBucket); gridFs.remove(gridFs.findOne(new ObjectId(_id))); }
From source file:com.hangum.tadpole.mongodb.core.query.MongoDBQuery.java
License:Open Source License
/** * insert gridfs// w w w . j a v a 2 s .com * * @param userDB * @param strBucket * @param fileList * @throws Exception */ public static void insertGridFS(UserDBDAO userDB, String strBucket, List<String> fileList) throws Exception { DB mongoDb = findDB(userDB); GridFS gridFs = null; if ("".equals(strBucket)) gridFs = new GridFS(mongoDb); else gridFs = new GridFS(mongoDb, strBucket); for (String strFile : fileList) { String saveFileName = strFile.substring(strFile.lastIndexOf(File.separator) + 1); GridFSInputFile gfsFile = gridFs.createFile(new File(strFile)); gfsFile.setFilename(saveFileName); gfsFile.save(); } }
From source file:com.hangum.tadpole.mongodb.core.test.MongoTestGridFS.java
License:Open Source License
private static void allList(DB db) throws Exception { System.out.println("##[all GridFs list] [start]######################"); GridFS gridFs = new GridFS(db); DBCursor dbCursor = gridFs.getFileList(); for (DBObject dbObject : dbCursor) { System.out.println(dbObject); }/*from www. j a v a 2s .c o m*/ System.out.println("##[all GridFs list] [end]######################"); }
From source file:com.hangum.tadpole.mongodb.core.test.MongoTestGridFS.java
License:Open Source License
private static void saveImage(DB db) throws Exception { String newFileName = "currentop"; File imageFile = new File("c:/temp/currentop.png"); GridFS gfsPhoto = new GridFS(db); GridFSInputFile gfsFile = gfsPhoto.createFile(imageFile); gfsFile.setFilename(newFileName);/*from w w w. j ava 2 s. co m*/ gfsFile.save(); }
From source file:com.ibm.ws.lars.rest.PersistenceBean.java
License:Apache License
@PostConstruct public void createGridFS() { gridFS = new GridFS(db); }
From source file:com.kurento.kmf.repository.internal.repoimpl.mongo.MongoRepository.java
License:Open Source License
@PostConstruct private void postConstruct() { gridFS = new GridFS(mongoTemplate.getDb()); }
From source file:com.mongo.gridfs.GridFSFileLoader.java
License:Open Source License
public GridFSFileLoader() { try {/*from w ww . ja v a2 s . c o m*/ mon = new Mongo(); } catch (UnknownHostException e) { throw new IllegalStateException(e); } catch (MongoException e) { throw new IllegalStateException(e); } gridfs = new GridFS(mon.getDB("filernd")); }
From source file:com.seajas.search.contender.service.storage.StorageService.java
License:Open Source License
/** * Default constructor./*from w w w. jav a 2 s. c o m*/ * * @param dbFactory */ @Autowired public StorageService(final MongoDbFactory dbFactory) { this.gridFs = new GridFS(dbFactory.getDb()); }