public class GridFS extends Object
| Modifier and Type | Field and Description |
|---|---|
protected String |
_bucketName |
protected DBCollection |
_chunkCollection |
protected DB |
_db |
protected DBCollection |
_filesCollection |
static String |
DEFAULT_BUCKET
bucket to use for the collection namespaces
|
static int |
DEFAULT_CHUNKSIZE
file's chunk size
|
static long |
MAX_CHUNKSIZE
file's max chunk size
|
| Constructor and Description |
|---|
GridFS(DB db)
Creates a GridFS instance for the default bucket "fs"
in the given database.
|
GridFS(DB db,
String bucket)
Creates a GridFS instance for the specified bucket
in the given database.
|
| Modifier and Type | Method and Description |
|---|---|
protected GridFSDBFile |
_fix(Object o) |
GridFSInputFile |
createFile()
This method creates an empty
GridFSInputFile instance. |
GridFSInputFile |
createFile(byte[] data)
creates a file entry.
|
GridFSInputFile |
createFile(File f)
creates a file entry.
|
GridFSInputFile |
createFile(InputStream in)
creates a file entry.
|
GridFSInputFile |
createFile(InputStream in,
boolean closeStreamOnPersist)
creates a file entry.
|
GridFSInputFile |
createFile(InputStream in,
String filename)
creates a file entry.
|
GridFSInputFile |
createFile(InputStream in,
String filename,
boolean closeStreamOnPersist)
creates a file entry.
|
GridFSInputFile |
createFile(String filename) |
List<GridFSDBFile> |
find(DBObject query)
finds a list of files matching the given query
|
List<GridFSDBFile> |
find(DBObject query,
DBObject sort)
finds a list of files matching the given query
|
GridFSDBFile |
find(ObjectId id)
finds one file matching the given id.
|
List<GridFSDBFile> |
find(String filename)
finds a list of files matching the given filename
|
List<GridFSDBFile> |
find(String filename,
DBObject sort)
finds a list of files matching the given filename
|
GridFSDBFile |
findOne(DBObject query)
finds one file matching the given query
|
GridFSDBFile |
findOne(ObjectId id)
finds one file matching the given id.
|
GridFSDBFile |
findOne(String filename)
finds one file matching the given filename
|
String |
getBucketName()
gets the bucket name used in the collection's namespace
|
DB |
getDB()
gets the db used
|
DBCursor |
getFileList()
gets the list of files stored in this gridfs, sorted by filename
|
DBCursor |
getFileList(DBObject query)
gets a filtered list of files stored in this gridfs, sorted by filename
|
DBCursor |
getFileList(DBObject query,
DBObject sort)
gets a filtered list of files stored in this gridfs, sorted by param sort
|
void |
remove(DBObject query)
removes all files matching the given query
|
void |
remove(ObjectId id)
removes the file matching the given id
|
void |
remove(String filename)
removes all files matching the given filename
|
public static final int DEFAULT_CHUNKSIZE
public static final long MAX_CHUNKSIZE
public static final String DEFAULT_BUCKET
protected final DB _db
protected final String _bucketName
protected final DBCollection _filesCollection
protected final DBCollection _chunkCollection
public GridFS(DB db)
db - database to work withMongoExceptionWriteConcernpublic GridFS(DB db, String bucket)
db - database to work withbucket - bucket to use in the given databaseMongoExceptionWriteConcernpublic DBCursor getFileList()
public DBCursor getFileList(DBObject query)
query - filter to applypublic DBCursor getFileList(DBObject query, DBObject sort)
query - filter to applysort - sorting to applypublic GridFSDBFile find(ObjectId id)
id - MongoExceptionpublic GridFSDBFile findOne(ObjectId id)
id - MongoExceptionpublic GridFSDBFile findOne(String filename)
filename - MongoExceptionpublic GridFSDBFile findOne(DBObject query)
query - MongoExceptionpublic List<GridFSDBFile> find(String filename)
filename - MongoExceptionpublic List<GridFSDBFile> find(String filename, DBObject sort)
filename - sort - MongoExceptionpublic List<GridFSDBFile> find(DBObject query)
query - MongoExceptionpublic List<GridFSDBFile> find(DBObject query, DBObject sort)
query - sort - MongoExceptionprotected GridFSDBFile _fix(Object o)
public void remove(ObjectId id)
id - MongoExceptionpublic void remove(String filename)
filename - MongoExceptionpublic void remove(DBObject query)
query - MongoExceptionpublic GridFSInputFile createFile(byte[] data)
data - the file's datapublic GridFSInputFile createFile(File f) throws IOException
f - the file objectIOExceptionpublic GridFSInputFile createFile(InputStream in)
in - an inputstream containing the file's datapublic GridFSInputFile createFile(InputStream in, boolean closeStreamOnPersist)
in - an inputstream containing the file's datacloseStreamOnPersist - indicate the passed in input stream should be closed
once the data chunk persistedpublic GridFSInputFile createFile(InputStream in, String filename)
in - an inputstream containing the file's datafilename - the file name as stored in the dbpublic GridFSInputFile createFile(InputStream in, String filename, boolean closeStreamOnPersist)
in - an inputstream containing the file's datafilename - the file name as stored in the dbcloseStreamOnPersist - indicate the passed in input stream should be closed
once the data chunk persistedpublic GridFSInputFile createFile(String filename)
filename - the file name as stored in the dbGridFS#createFile()} on how to use this methodpublic GridFSInputFile createFile()
GridFSInputFile instance. On this
instance an OutputStream can be obtained using the
GridFSInputFile.getOutputStream() method. You can still call
GridFSInputFile.setContentType(String) and
GridFSInputFile.setFilename(String). The file will be completely
written and closed after calling the OutputStream.close()
method on the output stream.public String getBucketName()
public DB getDB()