public class GridFS
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected java.lang.String |
_bucketName |
protected DBCollection |
_chunkCollection |
protected DB |
_db |
protected DBCollection |
_filesCollection |
static java.lang.String |
DEFAULT_BUCKET
bucket to use for the collection namespaces
|
static int |
DEFAULT_CHUNKSIZE
file's chunk size
|
| Constructor and Description |
|---|
GridFS(DB db)
Creates a GridFS instance for the default bucket "fs"
in the given database.
|
GridFS(DB db,
java.lang.String bucket)
Creates a GridFS instance for the specified bucket
in the given database.
|
| Modifier and Type | Method and Description |
|---|---|
GridFSInputFile |
createFile()
This method creates an empty
GridFSInputFile instance. |
GridFSInputFile |
createFile(byte[] data)
creates a file entry.
|
GridFSInputFile |
createFile(java.io.File f)
creates a file entry.
|
GridFSInputFile |
createFile(java.io.InputStream in)
creates a file entry.
|
GridFSInputFile |
createFile(java.io.InputStream in,
boolean closeStreamOnPersist)
creates a file entry.
|
GridFSInputFile |
createFile(java.io.InputStream in,
java.lang.String filename)
creates a file entry.
|
GridFSInputFile |
createFile(java.io.InputStream in,
java.lang.String filename,
boolean closeStreamOnPersist)
creates a file entry.
|
GridFSInputFile |
createFile(java.lang.String filename) |
java.util.List<GridFSDBFile> |
find(DBObject query)
finds a list of files matching the given query
|
GridFSDBFile |
find(ObjectId id)
finds one file matching the given id.
|
java.util.List<GridFSDBFile> |
find(java.lang.String filename)
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(java.lang.String filename)
finds one file matching the given filename
|
java.lang.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
|
void |
remove(DBObject query)
removes all files matching the given query
|
void |
remove(ObjectId id)
removes the file matching the given id
|
void |
remove(java.lang.String filename)
removes all files matching the given filename
|
public static final int DEFAULT_CHUNKSIZE
public static final java.lang.String DEFAULT_BUCKET
protected final DB _db
protected final java.lang.String _bucketName
protected final DBCollection _filesCollection
protected final DBCollection _chunkCollection
public GridFS(DB db)
db - database to work withpublic GridFS(DB db, java.lang.String bucket)
db - database to work withbucket - bucket to use in the given databasepublic DBCursor getFileList()
public DBCursor getFileList(DBObject query)
query - filter to applypublic GridFSDBFile find(ObjectId id)
id - public GridFSDBFile findOne(ObjectId id)
id - public GridFSDBFile findOne(java.lang.String filename)
filename - public GridFSDBFile findOne(DBObject query)
query - public java.util.List<GridFSDBFile> find(java.lang.String filename)
filename - public java.util.List<GridFSDBFile> find(DBObject query)
query - public void remove(ObjectId id)
id - public void remove(java.lang.String filename)
filename - public void remove(DBObject query)
query - public GridFSInputFile createFile(byte[] data)
data - the file's datapublic GridFSInputFile createFile(java.io.File f) throws java.io.IOException
f - the file objectjava.io.IOExceptionpublic GridFSInputFile createFile(java.io.InputStream in)
in - an inputstream containing the file's datapublic GridFSInputFile createFile(java.io.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(java.io.InputStream in, java.lang.String filename)
in - an inputstream containing the file's datafilename - the file name as stored in the dbpublic GridFSInputFile createFile(java.io.InputStream in, java.lang.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(java.lang.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 java.lang.String getBucketName()
public DB getDB()