/** * Finds a list of files matching the given query. * * @param query the filter to apply * @return list of gridfs files * @throws com.mongodb.MongoException if the operation fails */ public List<GridFSDBFile> find(final DBObject query) { return find(query, null); }
/** * Finds a list of files matching the given filename. * * @param filename the filename to look for * @return list of gridfs files * @throws com.mongodb.MongoException if the operation fails */ public List<GridFSDBFile> find(final String filename) { return find(new BasicDBObject("filename", filename)); }
/** * Finds a list of files matching the given filename. * * @param filename the filename to look for * @param sort the fields to sort with * @return list of gridfs files * @throws com.mongodb.MongoException if the operation fails */ public List<GridFSDBFile> find(final String filename, final DBObject sort) { return find(new BasicDBObject("filename", filename), sort); }
/** * Removes all files matching the given query. * * @param query filter to apply * @throws com.mongodb.MongoException if the operation fails */ public void remove(final DBObject query) { if (query == null) { throw new IllegalArgumentException("query can not be null"); } for (final GridFSDBFile f : find(query)) { f.remove(); } }
/** * Finds a list of files matching the given query. * * @param query the filter to apply * @return list of gridfs files * @throws com.mongodb.MongoException if the operation fails */ public List<GridFSDBFile> find(final DBObject query) { return find(query, null); }
/** * Finds a list of files matching the given filename. * * @param filename the filename to look for * @return list of gridfs files * @throws com.mongodb.MongoException if the operation fails */ public List<GridFSDBFile> find(final String filename) { return find(new BasicDBObject("filename", filename)); }
/** * Finds a list of files matching the given filename. * * @param filename the filename to look for * @param sort the fields to sort with * @return list of gridfs files * @throws com.mongodb.MongoException if the operation fails */ public List<GridFSDBFile> find(final String filename, final DBObject sort) { return find(new BasicDBObject("filename", filename), sort); }
@Override public RepositoryItem findRepositoryItemById(String id) { List<GridFSDBFile> dbFiles = gridFS.find(id); if (dbFiles.size() > 0) { if (dbFiles.size() > 1) { log.warn("There are several files with the same " + "filename and should be only one"); } return createRepositoryItem(dbFiles.get(0)); } throw new NoSuchElementException("The repository item with id \"" + id + "\" does not exist"); } //
@Override public RepositoryItem findRepositoryItemById(String id) { List<GridFSDBFile> dbFiles = gridFS.find(id); if (dbFiles.size() > 0) { if (dbFiles.size() > 1) { log.warn("There are several files with the same " + "filename and should be only one"); } return createRepositoryItem(dbFiles.get(0)); } throw new NoSuchElementException("The repository item with id \"" + id + "\" does not exist"); } //
private GridFSDBFile getFile() throws IOException { if (null == file) { file = getGridFS().find(fileId); if (null == file) { throw new IOException("No file found for id " + fileId); } } return file; }
@Override public List<FileInfo> listFilesByName(final String filename){ final List<GridFSDBFile> files = gridfs.find(new BasicDBObject("filename",new BasicDBObject("$regex", ".*"+filename+".*"))); final ArrayList<FileInfo> toReturn = new ArrayList<FileInfo>(); for (GridFSDBFile file : files) { toReturn.add(new FileInfo(file,false)); } return toReturn; }
@Override public boolean deleteFile(Object id) { DBObject obj = new BasicDBObject(MongoDocument.MONGO_ID_KEY, id); if (pipelinefs.find(obj).size()==0) { return false; } pipelinefs.remove(obj); return true; } }
@Override public List<GridFSDBFile> find(String filename, OrderBy orderBy) { return __gridFS.find(filename, orderBy.toBson()); }
private List<RepositoryItem> findRepositoryItemsByQuery(String query) { List<GridFSDBFile> files = gridFS.find((DBObject) JSON.parse(query)); List<RepositoryItem> repositoryItems = new ArrayList<>(); for (GridFSDBFile file : files) { repositoryItems.add(createRepositoryItem(file)); } return repositoryItems; }
private List<RepositoryItem> findRepositoryItemsByQuery(String query) { List<GridFSDBFile> files = gridFS.find((DBObject) JSON.parse(query)); List<RepositoryItem> repositoryItems = new ArrayList<>(); for (GridFSDBFile file : files) { repositoryItems.add(createRepositoryItem(file)); } return repositoryItems; }
GridFS gfs = new GridFS(db); ObjectId fileId = new ObjectId("your_object_id"); GridFSDBFile gfsFile = gfs.find(fileId); File outFile; RelativeLayout v = (RelativeLayout) findViewById(R.id.RelativeLayout); Context context = (Context) v.getContext(); outFile = File.createTempFile("xyz", null, context.getCacheDir()); gfsFile.writeTo(outFile); ImageView iv= (ImageView)findViewById(R.id.imageView1); InputStream is = new FileInputStream(outFile); iv.setImageBitmap(BitmapFactory.decodeStream(is)); outFile.delete();`
@Override @Deprecated public void removeInactiveFiles() { BasicDBObject query = new BasicDBObject(); query.put(MongoPipelineReader.ACTIVE_KEY, Stage.Mode.INACTIVE.toString()); List<GridFSDBFile> list = pipelinefs.find(query); for(GridFSDBFile file : list) { pipelinefs.remove(file); } }
@Override public RepositoryItem createRepositoryItem(String id) { // TODO The file is not written until outputstream is closed. There is a // potentially data race with this unique test if (!gridFS.find(id).isEmpty()) { throw new DuplicateItemException(id); } GridFSInputFile dbFile = gridFS.createFile(id); dbFile.setId(id); return createRepositoryItem(dbFile); }
@Override public RepositoryItem createRepositoryItem(String id) { // TODO The file is not written until outputstream is closed. There is a // potentially data race with this unique test if (!gridFS.find(id).isEmpty()) { throw new DuplicateItemException(id); } GridFSInputFile dbFile = gridFS.createFile(id); dbFile.setId(id); return createRepositoryItem(dbFile); }
@Override public List<String> getDocumentFileNames(DatabaseDocument<MongoType> d) { MongoDocument md = (MongoDocument)d; DBObject query = QueryBuilder.start(DOCUMENT_KEY).is(md.getID().getID()).get(); ArrayList<String> list = new ArrayList<String>(); List<GridFSDBFile> files = documentfs.find(query); for(GridFSDBFile file : files) { list.add(file.getFilename()); } return list; }