Class GridFS
- java.lang.Object
-
- com.mongodb.gridfs.GridFS
-
@Deprecated(since="2021-05-27") public class GridFS extends java.lang.Object
Deprecated.Usage of this API is not supported in AEM as a Cloud Service.Implementation of GridFS - a specification for storing and retrieving files that exceed the BSON-document size limit of 16MB.
Instead of storing a file in a single document, GridFS divides a file into parts, or chunks, and stores each of those chunks as a separate document. By default GridFS limits chunk size to 255k. GridFS uses two collections to store files. One collection stores the file chunks, and the other stores file metadata.
When you query a GridFS store for a file, the driver or client will reassemble the chunks as needed. You can perform range queries on files stored through GridFS. You also can access information from arbitrary sections of files, which allows you to "skip" into the middle of a video or audio file.
GridFS is useful not only for storing files that exceed 16MB but also for storing any files for which you want access without having to load the entire file into memory. For more information on the indications of GridFS, see MongoDB official documentation.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_BUCKET
Deprecated.Bucket to use for the collection namespacesstatic int
DEFAULT_CHUNKSIZE
Deprecated.File's chunk sizestatic long
MAX_CHUNKSIZE
Deprecated.You can calculate max chunkSize with a similar formulaMongo.getMaxBsonObjectSize()
- 500*1000.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description GridFSInputFile
createFile()
Deprecated.This method creates an emptyGridFSInputFile
instance.GridFSInputFile
createFile(byte[] data)
Deprecated.Creates a file entry.GridFSInputFile
createFile(java.io.File file)
Deprecated.Creates a file entry.GridFSInputFile
createFile(java.io.InputStream in)
Deprecated.Creates a file entry.GridFSInputFile
createFile(java.io.InputStream in, boolean closeStreamOnPersist)
Deprecated.Creates a file entry.GridFSInputFile
createFile(java.io.InputStream in, java.lang.String filename)
Deprecated.Creates a file entry.GridFSInputFile
createFile(java.io.InputStream in, java.lang.String filename, boolean closeStreamOnPersist)
Deprecated.Creates a file entry.GridFSInputFile
createFile(java.lang.String filename)
Deprecated.Creates a file entry.java.util.List<GridFSDBFile>
find(DBObject query)
Deprecated.Finds a list of files matching the given query.java.util.List<GridFSDBFile>
find(DBObject query, DBObject sort)
Deprecated.Finds a list of files matching the given query.java.util.List<GridFSDBFile>
find(java.lang.String filename)
Deprecated.Finds a list of files matching the given filename.java.util.List<GridFSDBFile>
find(java.lang.String filename, DBObject sort)
Deprecated.Finds a list of files matching the given filename.GridFSDBFile
find(ObjectId objectId)
Deprecated.Finds one file matching the given objectId.GridFSDBFile
findOne(DBObject query)
Deprecated.Finds one file matching the given query.GridFSDBFile
findOne(java.lang.String filename)
Deprecated.Finds one file matching the given filename.GridFSDBFile
findOne(ObjectId objectId)
Deprecated.Finds one file matching the given objectId.java.lang.String
getBucketName()
Deprecated.Gets the bucket name used in the collection's namespace.DB
getDB()
Deprecated.Gets the database used.DBCursor
getFileList()
Deprecated.Gets the list of files stored in this gridfs, sorted by filename.DBCursor
getFileList(DBObject query)
Deprecated.Gets a filtered list of files stored in this gridfs, sorted by filename.DBCursor
getFileList(DBObject query, DBObject sort)
Deprecated.Gets a sorted, filtered list of files stored in this gridfs.void
remove(DBObject query)
Deprecated.Removes all files matching the given query.void
remove(java.lang.String filename)
Deprecated.Removes all files matching the given filename.void
remove(ObjectId id)
Deprecated.Removes the file matching the given id.
-
-
-
Field Detail
-
DEFAULT_CHUNKSIZE
public static final int DEFAULT_CHUNKSIZE
Deprecated.File's chunk size- See Also:
- Constant Field Values
-
MAX_CHUNKSIZE
@Deprecated public static final long MAX_CHUNKSIZE
Deprecated.You can calculate max chunkSize with a similar formulaMongo.getMaxBsonObjectSize()
- 500*1000. Please ensure that you left enough space for metadata (500kb is enough).File's max chunk size- See Also:
- Constant Field Values
-
DEFAULT_BUCKET
public static final java.lang.String DEFAULT_BUCKET
Deprecated.Bucket to use for the collection namespaces- See Also:
- Constant Field Values
-
-
Constructor Detail
-
GridFS
public GridFS(DB db)
Deprecated.Creates a GridFS instance for the default bucket "fs" in the given database. Set the preferred WriteConcern on the give DB with DB.setWriteConcern- Parameters:
db
- database to work with- Throws:
MongoException
- if there's a failure- See Also:
WriteConcern
-
GridFS
public GridFS(DB db, java.lang.String bucket)
Deprecated.Creates a GridFS instance for the specified bucket in the given database. Set the preferred WriteConcern on the give DB with DB.setWriteConcern- Parameters:
db
- database to work withbucket
- bucket to use in the given database- Throws:
MongoException
- if there's a failure- See Also:
WriteConcern
-
-
Method Detail
-
getFileList
public DBCursor getFileList()
Deprecated.Gets the list of files stored in this gridfs, sorted by filename.- Returns:
- cursor of file objects
-
getFileList
public DBCursor getFileList(DBObject query)
Deprecated.Gets a filtered list of files stored in this gridfs, sorted by filename.- Parameters:
query
- filter to apply- Returns:
- cursor of file objects
-
getFileList
public DBCursor getFileList(DBObject query, DBObject sort)
Deprecated.Gets a sorted, filtered list of files stored in this gridfs.- Parameters:
query
- filter to applysort
- sorting to apply- Returns:
- cursor of file objects
-
find
public GridFSDBFile find(ObjectId objectId)
Deprecated.Finds one file matching the given objectId. Equivalent to findOne(objectId).- Parameters:
objectId
- the objectId of the file stored on a server- Returns:
- a gridfs file
- Throws:
MongoException
- if the operation fails
-
findOne
public GridFSDBFile findOne(ObjectId objectId)
Deprecated.Finds one file matching the given objectId.- Parameters:
objectId
- the objectId of the file stored on a server- Returns:
- a gridfs file
- Throws:
MongoException
- if the operation fails
-
findOne
public GridFSDBFile findOne(java.lang.String filename)
Deprecated.Finds one file matching the given filename.- Parameters:
filename
- the name of the file stored on a server- Returns:
- the gridfs db file
- Throws:
MongoException
- if the operation fails
-
findOne
public GridFSDBFile findOne(DBObject query)
Deprecated.Finds one file matching the given query.- Parameters:
query
- filter to apply- Returns:
- a gridfs file
- Throws:
MongoException
- if the operation fails
-
find
public java.util.List<GridFSDBFile> find(java.lang.String filename)
Deprecated.Finds a list of files matching the given filename.- Parameters:
filename
- the filename to look for- Returns:
- list of gridfs files
- Throws:
MongoException
- if the operation fails
-
find
public java.util.List<GridFSDBFile> find(java.lang.String filename, DBObject sort)
Deprecated.Finds a list of files matching the given filename.- Parameters:
filename
- the filename to look forsort
- the fields to sort with- Returns:
- list of gridfs files
- Throws:
MongoException
- if the operation fails
-
find
public java.util.List<GridFSDBFile> find(DBObject query)
Deprecated.Finds a list of files matching the given query.- Parameters:
query
- the filter to apply- Returns:
- list of gridfs files
- Throws:
MongoException
- if the operation fails
-
find
public java.util.List<GridFSDBFile> find(DBObject query, DBObject sort)
Deprecated.Finds a list of files matching the given query.- Parameters:
query
- the filter to applysort
- the fields to sort with- Returns:
- list of gridfs files
- Throws:
MongoException
- if the operation fails
-
remove
public void remove(ObjectId id)
Deprecated.Removes the file matching the given id.- Parameters:
id
- the id of the file to be removed- Throws:
MongoException
- if the operation fails
-
remove
public void remove(java.lang.String filename)
Deprecated.Removes all files matching the given filename.- Parameters:
filename
- the name of the file to be removed- Throws:
MongoException
- if the operation fails
-
remove
public void remove(DBObject query)
Deprecated.Removes all files matching the given query.- Parameters:
query
- filter to apply- Throws:
MongoException
- if the operation fails
-
createFile
public GridFSInputFile createFile(byte[] data)
Deprecated.Creates a file entry. After calling this method, you have to callGridFSInputFile.save()
.- Parameters:
data
- the file's data- Returns:
- a gridfs input file
-
createFile
public GridFSInputFile createFile(java.io.File file) throws java.io.IOException
Deprecated.Creates a file entry. After calling this method, you have to callGridFSInputFile.save()
.- Parameters:
file
- the file object- Returns:
- a GridFS input file
- Throws:
java.io.IOException
- if there are problems readingfile
-
createFile
public GridFSInputFile createFile(java.io.InputStream in)
Deprecated.Creates a file entry. After calling this method, you have to callGridFSInputFile.save()
.- Parameters:
in
- an inputstream containing the file's data- Returns:
- a gridfs input file
-
createFile
public GridFSInputFile createFile(java.io.InputStream in, boolean closeStreamOnPersist)
Deprecated.Creates a file entry. After calling this method, you have to callGridFSInputFile.save()
.- Parameters:
in
- an inputstream containing the file's datacloseStreamOnPersist
- indicate the passed in input stream should be closed once the data chunk persisted- Returns:
- a gridfs input file
-
createFile
public GridFSInputFile createFile(java.io.InputStream in, java.lang.String filename)
Deprecated.Creates a file entry. After calling this method, you have to callGridFSInputFile.save()
.- Parameters:
in
- an inputstream containing the file's datafilename
- the file name as stored in the db- Returns:
- a gridfs input file
-
createFile
public GridFSInputFile createFile(java.io.InputStream in, java.lang.String filename, boolean closeStreamOnPersist)
Deprecated.Creates a file entry. After calling this method, you have to callGridFSInputFile.save()
.- Parameters:
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 persisted- Returns:
- a gridfs input file
-
createFile
public GridFSInputFile createFile(java.lang.String filename)
Deprecated.Creates a file entry.- Parameters:
filename
- the file name as stored in the db- Returns:
- a gridfs input file
- See Also:
createFile()
-
createFile
public GridFSInputFile createFile()
Deprecated.This method creates an emptyGridFSInputFile
instance. On this instance anOutputStream
can be obtained using theGridFSInputFile.getOutputStream()
method. You can still callGridFSInputFile.setContentType(String)
andGridFSInputFile.setFilename(String)
. The file will be completely written and closed after calling theOutputStream.close()
method on the output stream.- Returns:
- GridFS file handle instance.
-
getBucketName
public java.lang.String getBucketName()
Deprecated.Gets the bucket name used in the collection's namespace. Default value is 'fs'.- Returns:
- the name of the file bucket
-
getDB
public DB getDB()
Deprecated.Gets the database used.- Returns:
- the database
-
-