final class GridFSBucketImpl extends java.lang.Object implements GridFSBucket
| Modifier and Type | Field and Description |
|---|---|
private java.lang.String |
bucketName |
private boolean |
checkedIndexes |
private MongoCollection<Document> |
chunksCollection |
private int |
chunkSizeBytes |
private static int |
DEFAULT_CHUNKSIZE_BYTES |
private MongoCollection<GridFSFile> |
filesCollection |
| Constructor and Description |
|---|
GridFSBucketImpl(MongoDatabase database) |
GridFSBucketImpl(MongoDatabase database,
java.lang.String bucketName) |
GridFSBucketImpl(java.lang.String bucketName,
int chunkSizeBytes,
MongoCollection<GridFSFile> filesCollection,
MongoCollection<Document> chunksCollection) |
| Modifier and Type | Method and Description |
|---|---|
private void |
checkCreateIndex() |
void |
delete(BsonValue id)
Given a
id, delete this stored file's files collection document and associated chunks from a GridFS bucket. |
void |
delete(ObjectId id)
Given a
id, delete this stored file's files collection document and associated chunks from a GridFS bucket. |
void |
downloadToStream(BsonValue id,
java.io.OutputStream destination)
Downloads the contents of the stored file specified by
id and writes the contents to the destination Stream. |
private void |
downloadToStream(GridFSDownloadStream downloadStream,
java.io.OutputStream destination) |
void |
downloadToStream(ObjectId id,
java.io.OutputStream destination)
Downloads the contents of the stored file specified by
id and writes the contents to the destination Stream. |
void |
downloadToStream(java.lang.String filename,
java.io.OutputStream destination)
Downloads the contents of the latest version of the stored file specified by
filename and writes the contents to
the destination Stream. |
void |
downloadToStream(java.lang.String filename,
java.io.OutputStream destination,
GridFSDownloadOptions options)
Downloads the contents of the stored file specified by
filename and by the revision in options and writes the
contents to the destination Stream. |
void |
downloadToStreamByName(java.lang.String filename,
java.io.OutputStream destination)
Deprecated.
|
void |
downloadToStreamByName(java.lang.String filename,
java.io.OutputStream destination,
GridFSDownloadByNameOptions options)
Deprecated.
|
void |
drop()
Drops the data associated with this bucket from the database.
|
GridFSFindIterable |
find()
Finds all documents in the files collection.
|
GridFSFindIterable |
find(Bson filter)
Finds all documents in the collection that match the filter.
|
private GridFSDownloadStream |
findTheFileInfoAndOpenDownloadStream(BsonValue id) |
java.lang.String |
getBucketName()
The bucket name.
|
private static MongoCollection<Document> |
getChunksCollection(MongoDatabase database,
java.lang.String bucketName) |
int |
getChunkSizeBytes()
Sets the chunk size in bytes.
|
private GridFSFile |
getFileByName(java.lang.String filename,
GridFSDownloadOptions options) |
private static MongoCollection<GridFSFile> |
getFilesCollection(MongoDatabase database,
java.lang.String bucketName) |
ReadConcern |
getReadConcern()
Get the read concern for the GridFSBucket.
|
ReadPreference |
getReadPreference()
Get the read preference for the GridFSBucket.
|
WriteConcern |
getWriteConcern()
Get the write concern for the GridFSBucket.
|
private <T> boolean |
hasIndex(MongoCollection<T> collection,
Document index) |
GridFSDownloadStream |
openDownloadStream(BsonValue id)
Opens a Stream from which the application can read the contents of the stored file specified by
id. |
GridFSDownloadStream |
openDownloadStream(ObjectId id)
Opens a Stream from which the application can read the contents of the stored file specified by
id. |
GridFSDownloadStream |
openDownloadStream(java.lang.String filename)
Opens a Stream from which the application can read the contents of the latest version of the stored file specified by the
filename. |
GridFSDownloadStream |
openDownloadStream(java.lang.String filename,
GridFSDownloadOptions options)
Opens a Stream from which the application can read the contents of the stored file specified by
filename and the revision
in options. |
GridFSDownloadStream |
openDownloadStreamByName(java.lang.String filename)
Deprecated.
|
GridFSDownloadStream |
openDownloadStreamByName(java.lang.String filename,
GridFSDownloadByNameOptions options)
Deprecated.
|
GridFSUploadStream |
openUploadStream(BsonValue id,
java.lang.String filename)
Opens a Stream that the application can write the contents of the file to.
|
GridFSUploadStream |
openUploadStream(BsonValue id,
java.lang.String filename,
GridFSUploadOptions options)
Opens a Stream that the application can write the contents of the file to.
|
GridFSUploadStream |
openUploadStream(java.lang.String filename)
Opens a Stream that the application can write the contents of the file to.
|
GridFSUploadStream |
openUploadStream(java.lang.String filename,
GridFSUploadOptions options)
Opens a Stream that the application can write the contents of the file to.
|
void |
rename(BsonValue id,
java.lang.String newFilename)
Renames the stored file with the specified
id. |
void |
rename(ObjectId id,
java.lang.String newFilename)
Renames the stored file with the specified
id. |
void |
uploadFromStream(BsonValue id,
java.lang.String filename,
java.io.InputStream source)
Uploads the contents of the given
InputStream to a GridFS bucket. |
void |
uploadFromStream(BsonValue id,
java.lang.String filename,
java.io.InputStream source,
GridFSUploadOptions options)
Uploads the contents of the given
InputStream to a GridFS bucket. |
ObjectId |
uploadFromStream(java.lang.String filename,
java.io.InputStream source)
Uploads the contents of the given
InputStream to a GridFS bucket. |
ObjectId |
uploadFromStream(java.lang.String filename,
java.io.InputStream source,
GridFSUploadOptions options)
Uploads the contents of the given
InputStream to a GridFS bucket. |
GridFSBucket |
withChunkSizeBytes(int chunkSizeBytes)
Create a new GridFSBucket instance with a new chunk size in bytes.
|
GridFSBucket |
withReadConcern(ReadConcern readConcern)
Create a new GridFSBucket instance with a different read concern.
|
GridFSBucket |
withReadPreference(ReadPreference readPreference)
Create a new GridFSBucket instance with a different read preference.
|
GridFSBucket |
withWriteConcern(WriteConcern writeConcern)
Create a new GridFSBucket instance with a different write concern.
|
private static final int DEFAULT_CHUNKSIZE_BYTES
private final java.lang.String bucketName
private final int chunkSizeBytes
private final MongoCollection<GridFSFile> filesCollection
private final MongoCollection<Document> chunksCollection
private volatile boolean checkedIndexes
GridFSBucketImpl(MongoDatabase database)
GridFSBucketImpl(MongoDatabase database, java.lang.String bucketName)
GridFSBucketImpl(java.lang.String bucketName,
int chunkSizeBytes,
MongoCollection<GridFSFile> filesCollection,
MongoCollection<Document> chunksCollection)
public java.lang.String getBucketName()
GridFSBucketgetBucketName in interface GridFSBucketpublic int getChunkSizeBytes()
GridFSBucketgetChunkSizeBytes in interface GridFSBucketpublic ReadPreference getReadPreference()
GridFSBucketgetReadPreference in interface GridFSBucketReadPreferencepublic WriteConcern getWriteConcern()
GridFSBucketgetWriteConcern in interface GridFSBucketWriteConcernpublic ReadConcern getReadConcern()
GridFSBucketgetReadConcern in interface GridFSBucketReadConcernpublic GridFSBucket withChunkSizeBytes(int chunkSizeBytes)
GridFSBucketwithChunkSizeBytes in interface GridFSBucketchunkSizeBytes - the new chunk size in bytes.public GridFSBucket withReadPreference(ReadPreference readPreference)
GridFSBucketwithReadPreference in interface GridFSBucketreadPreference - the new ReadPreference for the GridFSBucketpublic GridFSBucket withWriteConcern(WriteConcern writeConcern)
GridFSBucketwithWriteConcern in interface GridFSBucketwriteConcern - the new WriteConcern for the GridFSBucketpublic GridFSBucket withReadConcern(ReadConcern readConcern)
GridFSBucketwithReadConcern in interface GridFSBucketreadConcern - the new ReadConcern for the GridFSBucketpublic GridFSUploadStream openUploadStream(java.lang.String filename)
GridFSBucketAs the application writes the contents to the returned Stream, the contents are uploaded as chunks in the chunks collection. When the application signals it is done writing the contents of the file by calling close on the returned Stream, a files collection document is created in the files collection.
openUploadStream in interface GridFSBucketfilename - the filename for the streampublic GridFSUploadStream openUploadStream(java.lang.String filename, GridFSUploadOptions options)
GridFSBucketAs the application writes the contents to the returned Stream, the contents are uploaded as chunks in the chunks collection. When the application signals it is done writing the contents of the file by calling close on the returned Stream, a files collection document is created in the files collection.
openUploadStream in interface GridFSBucketfilename - the filename for the streamoptions - the GridFSUploadOptionspublic GridFSUploadStream openUploadStream(BsonValue id, java.lang.String filename)
GridFSBucketAs the application writes the contents to the returned Stream, the contents are uploaded as chunks in the chunks collection. When the application signals it is done writing the contents of the file by calling close on the returned Stream, a files collection document is created in the files collection.
openUploadStream in interface GridFSBucketid - the custom id value of the filefilename - the filename for the streampublic GridFSUploadStream openUploadStream(BsonValue id, java.lang.String filename, GridFSUploadOptions options)
GridFSBucketAs the application writes the contents to the returned Stream, the contents are uploaded as chunks in the chunks collection. When the application signals it is done writing the contents of the file by calling close on the returned Stream, a files collection document is created in the files collection.
openUploadStream in interface GridFSBucketid - the custom id value of the filefilename - the filename for the streamoptions - the GridFSUploadOptionspublic ObjectId uploadFromStream(java.lang.String filename, java.io.InputStream source)
GridFSBucketInputStream to a GridFS bucket.
Reads the contents of the user file from the Stream and uploads it as chunks in the chunks collection. After all the
chunks have been uploaded, it creates a files collection document for filename in the files collection.
uploadFromStream in interface GridFSBucketfilename - the filename for the streamsource - the Stream providing the file datapublic ObjectId uploadFromStream(java.lang.String filename, java.io.InputStream source, GridFSUploadOptions options)
GridFSBucketInputStream to a GridFS bucket.
Reads the contents of the user file from the Stream and uploads it as chunks in the chunks collection. After all the
chunks have been uploaded, it creates a files collection document for filename in the files collection.
uploadFromStream in interface GridFSBucketfilename - the filename for the streamsource - the Stream providing the file dataoptions - the GridFSUploadOptionspublic void uploadFromStream(BsonValue id, java.lang.String filename, java.io.InputStream source)
GridFSBucketInputStream to a GridFS bucket.
Reads the contents of the user file from the Stream and uploads it as chunks in the chunks collection. After all the
chunks have been uploaded, it creates a files collection document for filename in the files collection.
uploadFromStream in interface GridFSBucketid - the custom id value of the filefilename - the filename for the streamsource - the Stream providing the file datapublic void uploadFromStream(BsonValue id, java.lang.String filename, java.io.InputStream source, GridFSUploadOptions options)
GridFSBucketInputStream to a GridFS bucket.
Reads the contents of the user file from the Stream and uploads it as chunks in the chunks collection. After all the
chunks have been uploaded, it creates a files collection document for filename in the files collection.
uploadFromStream in interface GridFSBucketid - the custom id value of the filefilename - the filename for the streamsource - the Stream providing the file dataoptions - the GridFSUploadOptionspublic GridFSDownloadStream openDownloadStream(ObjectId id)
GridFSBucketid.openDownloadStream in interface GridFSBucketid - the ObjectId of the file to be put into a stream.public void downloadToStream(ObjectId id, java.io.OutputStream destination)
GridFSBucketid and writes the contents to the destination Stream.downloadToStream in interface GridFSBucketid - the ObjectId of the file to be written to the destination streamdestination - the destination streampublic void downloadToStream(BsonValue id, java.io.OutputStream destination)
GridFSBucketid and writes the contents to the destination Stream.downloadToStream in interface GridFSBucketid - the custom id of the file, to be written to the destination streamdestination - the destination streampublic void downloadToStream(java.lang.String filename,
java.io.OutputStream destination)
GridFSBucketfilename and writes the contents to
the destination Stream.downloadToStream in interface GridFSBucketfilename - the name of the file to be downloadeddestination - the destination streampublic void downloadToStream(java.lang.String filename,
java.io.OutputStream destination,
GridFSDownloadOptions options)
GridFSBucketfilename and by the revision in options and writes the
contents to the destination Stream.downloadToStream in interface GridFSBucketfilename - the name of the file to be downloadeddestination - the destination streamoptions - the download optionspublic GridFSDownloadStream openDownloadStream(BsonValue id)
GridFSBucketid.openDownloadStream in interface GridFSBucketid - the custom id value of the file, to be put into a stream.public GridFSDownloadStream openDownloadStream(java.lang.String filename)
GridFSBucketfilename.openDownloadStream in interface GridFSBucketfilename - the name of the file to be downloadedpublic GridFSDownloadStream openDownloadStream(java.lang.String filename, GridFSDownloadOptions options)
GridFSBucketfilename and the revision
in options.openDownloadStream in interface GridFSBucketfilename - the name of the file to be downloadedoptions - the download optionspublic GridFSFindIterable find()
GridFSBucketfind in interface GridFSBucketpublic GridFSFindIterable find(Bson filter)
GridFSBucketBelow is an example of filtering against the filename and some nested metadata that can also be stored along with the file data:
Filters.and(Filters.eq("filename", "mongodb.png"), Filters.eq("metadata.contentType", "image/png"));
find in interface GridFSBucketfilter - the query filterFilterspublic void delete(ObjectId id)
GridFSBucketid, delete this stored file's files collection document and associated chunks from a GridFS bucket.delete in interface GridFSBucketid - the ObjectId of the file to be deletedpublic void delete(BsonValue id)
GridFSBucketid, delete this stored file's files collection document and associated chunks from a GridFS bucket.delete in interface GridFSBucketid - the id of the file to be deletedpublic void rename(ObjectId id, java.lang.String newFilename)
GridFSBucketid.rename in interface GridFSBucketid - the id of the file in the files collection to renamenewFilename - the new filename for the filepublic void rename(BsonValue id, java.lang.String newFilename)
GridFSBucketid.rename in interface GridFSBucketid - the id of the file in the files collection to renamenewFilename - the new filename for the filepublic void drop()
GridFSBucketdrop in interface GridFSBucket@Deprecated public GridFSDownloadStream openDownloadStreamByName(java.lang.String filename)
GridFSBucketfilename.openDownloadStreamByName in interface GridFSBucketfilename - the name of the file to be downloaded@Deprecated public GridFSDownloadStream openDownloadStreamByName(java.lang.String filename, GridFSDownloadByNameOptions options)
GridFSBucketfilename and the revision
in options.openDownloadStreamByName in interface GridFSBucketfilename - the name of the file to be downloadedoptions - the download options@Deprecated
public void downloadToStreamByName(java.lang.String filename,
java.io.OutputStream destination)
GridFSBucketfilename and writes the contents to
the destination Stream.downloadToStreamByName in interface GridFSBucketfilename - the name of the file to be downloadeddestination - the destination stream@Deprecated
public void downloadToStreamByName(java.lang.String filename,
java.io.OutputStream destination,
GridFSDownloadByNameOptions options)
GridFSBucketfilename and by the revision in options and writes the
contents to the destination Stream.downloadToStreamByName in interface GridFSBucketfilename - the name of the file to be downloadeddestination - the destination streamoptions - the download optionsprivate static MongoCollection<GridFSFile> getFilesCollection(MongoDatabase database, java.lang.String bucketName)
private static MongoCollection<Document> getChunksCollection(MongoDatabase database, java.lang.String bucketName)
private void checkCreateIndex()
private <T> boolean hasIndex(MongoCollection<T> collection, Document index)
private GridFSFile getFileByName(java.lang.String filename, GridFSDownloadOptions options)
private GridFSDownloadStream findTheFileInfoAndOpenDownloadStream(BsonValue id)
private void downloadToStream(GridFSDownloadStream downloadStream, java.io.OutputStream destination)