Example usage for com.mongodb.gridfs GridFS getFileList

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

Introduction

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

Prototype

public DBCursor getFileList(final DBObject query, final DBObject sort) 

Source Link

Document

Gets a sorted, filtered list of files stored in this gridfs.

Usage

From source file:eu.eubrazilcc.lvl.storage.mongodb.MongoDBConnector.java

License:EUPL

/**
 * Lists all the files in the specified name space. Only latest versions are included in the list.
 * @param namespace - (optional) name space to be searched for files. When nothing specified, the default bucket is used
 * @param sortCriteria - objects in the collection are sorted with this criteria
 * @param start - starting index/*from   w  w w. j  a  v a  2  s .c  o m*/
 * @param size - maximum number of objects returned
 * @param count - (optional) is updated with the number of objects in the database
 * @return a view of the files stored under the specified name space that contains the specified range.
 */
public List<GridFSDBFile> listFiles(final @Nullable String namespace, final DBObject sortCriteria,
        final int start, final int size, final @Nullable MutableLong count) {
    final List<GridFSDBFile> list = newArrayList();
    final DB db = client().getDB(CONFIG_MANAGER.getDbName());
    final GridFS gfsNs = isNotBlank(namespace) ? new GridFS(db, namespace.trim()) : new GridFS(db);
    final DBCursor cursor = gfsNs.getFileList(
            new BasicDBObject(FILE_VERSION_PROP, new BasicDBObject("$exists", true)), sortCriteria);
    cursor.skip(start).limit(size);
    try {
        while (cursor.hasNext()) {
            list.add((GridFSDBFile) cursor.next());
        }
    } finally {
        cursor.close();
    }
    if (count != null) {
        count.setValue(cursor.count());
    }
    return list;
}

From source file:eu.eubrazilcc.lvl.storage.mongodb.MongoDBConnector.java

License:EUPL

public List<GridFSDBFile> listFileOpenAccess(final @Nullable String namespace, final DBObject sortCriteria,
        final int start, final int size, final @Nullable MutableLong count) {
    final List<GridFSDBFile> list = newArrayList();
    final DB db = client().getDB(CONFIG_MANAGER.getDbName());
    final GridFS gfsNs = isNotBlank(namespace) ? new GridFS(db, namespace.trim()) : new GridFS(db);
    final DBCursor cursor = gfsNs
            .getFileList(new BasicDBObject(FILE_VERSION_PROP, new BasicDBObject("$exists", true))
                    .append(FILE_OPEN_ACCESS_LINK_PROP, new BasicDBObject("$exists", true)), sortCriteria);
    cursor.skip(start).limit(size);//from   w ww.j a va2 s  . c o m
    try {
        while (cursor.hasNext()) {
            list.add((GridFSDBFile) cursor.next());
        }
    } finally {
        cursor.close();
    }
    if (count != null) {
        count.setValue(cursor.count());
    }
    return list;
}

From source file:eu.eubrazilcc.lvl.storage.mongodb.MongoDBConnector.java

License:EUPL

/**
 * Lists all the versions of the specified file.
 * @param namespace - (optional) name space to be searched for files. When nothing specified, the default bucket is used
 * @param filename - filename to be searched for in the database
 * @param sortCriteria - objects in the collection are sorted with this criteria
 * @param start - starting index/*from  ww w.  j  a  va  2 s  . c o  m*/
 * @param size - maximum number of objects returned
 * @param count - (optional) is updated with the number of objects in the database
 * @return a view of the versions stored of the specified file that contains the specified range.
 */
public List<GridFSDBFile> listFileVersions(final @Nullable String namespace, final String filename,
        final DBObject sortCriteria, final int start, final int size, final @Nullable MutableLong count) {
    checkArgument(isNotBlank(filename), "Uninitialized or invalid filename");
    final List<GridFSDBFile> list = newArrayList();
    final DB db = client().getDB(CONFIG_MANAGER.getDbName());
    final GridFS gfsNs = isNotBlank(namespace) ? new GridFS(db, namespace.trim()) : new GridFS(db);
    final DBCursor cursor = gfsNs.getFileList(new BasicDBObject("filename", filename.trim()), sortCriteria);
    cursor.skip(start).limit(size);
    try {
        while (cursor.hasNext()) {
            list.add((GridFSDBFile) cursor.next());
        }
    } finally {
        cursor.close();
    }
    if (count != null) {
        count.setValue(cursor.count());
    }
    return list;
}