final class GridFSBucketImpl extends java.lang.Object implements GridFSBucket
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
bucketName |
private MongoCollection<Document> |
chunksCollection |
private int |
chunkSizeBytes |
private static int |
DEFAULT_BUFFER_SIZE |
private static int |
DEFAULT_CHUNKSIZE_BYTES |
private MongoCollection<GridFSFile> |
filesCollection |
private static Logger |
LOGGER |
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 |
---|---|
void |
delete(BsonValue id,
SingleResultCallback<java.lang.Void> callback)
Given a
id , delete this stored file's files collection document and associated chunks from a GridFS bucket. |
void |
delete(ObjectId id,
SingleResultCallback<java.lang.Void> callback)
Given a
id , delete this stored file's files collection document and associated chunks from a GridFS bucket. |
private void |
downloadToAsyncOutputStream(GridFSDownloadStream downloadStream,
AsyncOutputStream destination,
SingleResultCallback<java.lang.Long> callback) |
void |
downloadToStream(BsonValue id,
AsyncOutputStream destination,
SingleResultCallback<java.lang.Long> callback)
Downloads the contents of the stored file specified by
id and writes the contents to the destination
AsyncOutputStream. |
void |
downloadToStream(ObjectId id,
AsyncOutputStream destination,
SingleResultCallback<java.lang.Long> callback)
Downloads the contents of the stored file specified by
id and writes the contents to the destination
AsyncOutputStream. |
void |
downloadToStream(java.lang.String filename,
AsyncOutputStream destination,
GridFSDownloadOptions options,
SingleResultCallback<java.lang.Long> callback)
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 |
downloadToStream(java.lang.String filename,
AsyncOutputStream destination,
SingleResultCallback<java.lang.Long> callback)
Downloads the contents of the latest version of the stored file specified by
filename and writes the contents to
the destination Stream. |
void |
drop(SingleResultCallback<java.lang.Void> callback)
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 GridFSFindIterable |
findFileByName(java.lang.String filename,
GridFSDownloadOptions options) |
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 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.
|
GridFSDownloadStream |
openDownloadStream(BsonValue id)
Opens a AsyncInputStream from which the application can read the contents of the stored file specified by
id . |
GridFSDownloadStream |
openDownloadStream(ObjectId id)
Opens a AsyncInputStream 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 . |
GridFSUploadStream |
openUploadStream(BsonValue id,
java.lang.String filename)
Opens a AsyncOutputStream that the application can write the contents of the file to.
|
GridFSUploadStream |
openUploadStream(BsonValue id,
java.lang.String filename,
GridFSUploadOptions options)
Opens a AsyncOutputStream that the application can write the contents of the file to.
|
GridFSUploadStream |
openUploadStream(java.lang.String filename)
Opens a AsyncOutputStream that the application can write the contents of the file to.
|
GridFSUploadStream |
openUploadStream(java.lang.String filename,
GridFSUploadOptions options)
Opens a AsyncOutputStream that the application can write the contents of the file to.
|
private void |
readAndWriteInputStream(AsyncInputStream source,
GridFSUploadStream uploadStream,
java.nio.ByteBuffer buffer,
SingleResultCallback<java.lang.Void> callback) |
private void |
readAndWriteOutputStream(AsyncOutputStream destination,
GridFSDownloadStream downloadStream,
java.nio.ByteBuffer buffer,
long amountRead,
SingleResultCallback<java.lang.Long> callback) |
void |
rename(BsonValue id,
java.lang.String newFilename,
SingleResultCallback<java.lang.Void> callback)
Renames the stored file with the specified
id . |
void |
rename(ObjectId id,
java.lang.String newFilename,
SingleResultCallback<java.lang.Void> callback)
Renames the stored file with the specified
id . |
void |
uploadFromStream(BsonValue id,
java.lang.String filename,
AsyncInputStream source,
GridFSUploadOptions options,
SingleResultCallback<java.lang.Void> callback)
Uploads the contents of the given
AsyncInputStream to a GridFS bucket. |
void |
uploadFromStream(BsonValue id,
java.lang.String filename,
AsyncInputStream source,
SingleResultCallback<java.lang.Void> callback)
Uploads the contents of the given
AsyncInputStream to a GridFS bucket. |
void |
uploadFromStream(java.lang.String filename,
AsyncInputStream source,
GridFSUploadOptions options,
SingleResultCallback<ObjectId> callback)
Uploads the contents of the given
AsyncInputStream to a GridFS bucket. |
void |
uploadFromStream(java.lang.String filename,
AsyncInputStream source,
SingleResultCallback<ObjectId> callback)
Uploads the contents of the given
AsyncInputStream 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 MongoDatabase 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 Logger LOGGER
private static final int DEFAULT_CHUNKSIZE_BYTES
private static final int DEFAULT_BUFFER_SIZE
private final java.lang.String bucketName
private final int chunkSizeBytes
private final MongoCollection<GridFSFile> filesCollection
private final MongoCollection<Document> chunksCollection
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()
GridFSBucket
getBucketName
in interface GridFSBucket
public int getChunkSizeBytes()
GridFSBucket
getChunkSizeBytes
in interface GridFSBucket
public ReadPreference getReadPreference()
GridFSBucket
getReadPreference
in interface GridFSBucket
ReadPreference
public WriteConcern getWriteConcern()
GridFSBucket
getWriteConcern
in interface GridFSBucket
WriteConcern
public ReadConcern getReadConcern()
GridFSBucket
getReadConcern
in interface GridFSBucket
ReadConcern
public GridFSBucket withChunkSizeBytes(int chunkSizeBytes)
GridFSBucket
withChunkSizeBytes
in interface GridFSBucket
chunkSizeBytes
- the new chunk size in bytes.public GridFSBucket withReadPreference(ReadPreference readPreference)
GridFSBucket
withReadPreference
in interface GridFSBucket
readPreference
- the new ReadPreference
for the databasepublic GridFSBucket withWriteConcern(WriteConcern writeConcern)
GridFSBucket
withWriteConcern
in interface GridFSBucket
writeConcern
- the new WriteConcern
for the databasepublic GridFSBucket withReadConcern(ReadConcern readConcern)
GridFSBucket
withReadConcern
in interface GridFSBucket
readConcern
- the new ReadConcern
for the databasepublic GridFSUploadStream openUploadStream(java.lang.String filename)
GridFSBucket
As 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 GridFSBucket
filename
- the filename for the streampublic GridFSUploadStream openUploadStream(java.lang.String filename, GridFSUploadOptions options)
GridFSBucket
As 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 GridFSBucket
filename
- the filename for the streamoptions
- the GridFSUploadOptionspublic GridFSUploadStream openUploadStream(BsonValue id, java.lang.String filename)
GridFSBucket
As 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 GridFSBucket
id
- the custom id value of the filefilename
- the filename for the streampublic GridFSUploadStream openUploadStream(BsonValue id, java.lang.String filename, GridFSUploadOptions options)
GridFSBucket
As 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 GridFSBucket
id
- the custom id value of the filefilename
- the filename for the streamoptions
- the GridFSUploadOptionspublic void uploadFromStream(java.lang.String filename, AsyncInputStream source, SingleResultCallback<ObjectId> callback)
GridFSBucket
AsyncInputStream
to a GridFS bucket.
Reads the contents of the user file from the source
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 GridFSBucket
filename
- the filename for the streamsource
- the Stream providing the file datacallback
- with the ObjectId of the uploaded file.public void uploadFromStream(java.lang.String filename, AsyncInputStream source, GridFSUploadOptions options, SingleResultCallback<ObjectId> callback)
GridFSBucket
AsyncInputStream
to a GridFS bucket.
Reads the contents of the user file from the source
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 GridFSBucket
filename
- the filename for the streamsource
- the Stream providing the file dataoptions
- the GridFSUploadOptionscallback
- with the ObjectId of the uploaded file.public void uploadFromStream(BsonValue id, java.lang.String filename, AsyncInputStream source, SingleResultCallback<java.lang.Void> callback)
GridFSBucket
AsyncInputStream
to a GridFS bucket.
Reads the contents of the user file from the source
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 GridFSBucket
id
- the custom id value of the filefilename
- the filename for the streamsource
- the Stream providing the file datacallback
- with the ObjectId of the uploaded file.public void uploadFromStream(BsonValue id, java.lang.String filename, AsyncInputStream source, GridFSUploadOptions options, SingleResultCallback<java.lang.Void> callback)
GridFSBucket
AsyncInputStream
to a GridFS bucket.
Reads the contents of the user file from the source
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 GridFSBucket
id
- the custom id value of the filefilename
- the filename for the streamsource
- the Stream providing the file dataoptions
- the GridFSUploadOptionscallback
- with the ObjectId of the uploaded file.public GridFSDownloadStream openDownloadStream(ObjectId id)
GridFSBucket
id
.openDownloadStream
in interface GridFSBucket
id
- the ObjectId of the file to be put into a stream.public void downloadToStream(ObjectId id, AsyncOutputStream destination, SingleResultCallback<java.lang.Long> callback)
GridFSBucket
id
and writes the contents to the destination
AsyncOutputStream.downloadToStream
in interface GridFSBucket
id
- the ObjectId of the file to be written to the destination streamdestination
- the destination streamcallback
- the callback that is completed once the file has been downloadedpublic GridFSDownloadStream openDownloadStream(BsonValue id)
GridFSBucket
id
.openDownloadStream
in interface GridFSBucket
id
- the custom id value of the file, to be put into a stream.public void downloadToStream(BsonValue id, AsyncOutputStream destination, SingleResultCallback<java.lang.Long> callback)
GridFSBucket
id
and writes the contents to the destination
AsyncOutputStream.downloadToStream
in interface GridFSBucket
id
- the custom id of the file, to be written to the destination streamdestination
- the destination streamcallback
- the callback that is completed once the file has been downloadedpublic GridFSDownloadStream openDownloadStream(java.lang.String filename)
GridFSBucket
filename
.openDownloadStream
in interface GridFSBucket
filename
- the name of the file to be downloadedpublic GridFSDownloadStream openDownloadStream(java.lang.String filename, GridFSDownloadOptions options)
GridFSBucket
filename
and the revision
in options
.openDownloadStream
in interface GridFSBucket
filename
- the name of the file to be downloadedoptions
- the download optionspublic void downloadToStream(java.lang.String filename, AsyncOutputStream destination, SingleResultCallback<java.lang.Long> callback)
GridFSBucket
filename
and writes the contents to
the destination
Stream.downloadToStream
in interface GridFSBucket
filename
- the name of the file to be downloadeddestination
- the destination streamcallback
- the callback that is completed once the file has been downloadedpublic void downloadToStream(java.lang.String filename, AsyncOutputStream destination, GridFSDownloadOptions options, SingleResultCallback<java.lang.Long> callback)
GridFSBucket
filename
and by the revision in options
and writes the
contents to the destination
Stream.downloadToStream
in interface GridFSBucket
filename
- the name of the file to be downloadeddestination
- the destination streamoptions
- the download optionscallback
- the callback that is completed once the file has been downloadedpublic GridFSFindIterable find()
GridFSBucket
find
in interface GridFSBucket
public GridFSFindIterable find(Bson filter)
GridFSBucket
Below 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 GridFSBucket
filter
- the query filterFilters
public void delete(ObjectId id, SingleResultCallback<java.lang.Void> callback)
GridFSBucket
id
, delete this stored file's files collection document and associated chunks from a GridFS bucket.delete
in interface GridFSBucket
id
- the ObjectId of the file to be deletedcallback
- the callback that is completed once the file has been deletedpublic void delete(BsonValue id, SingleResultCallback<java.lang.Void> callback)
GridFSBucket
id
, delete this stored file's files collection document and associated chunks from a GridFS bucket.delete
in interface GridFSBucket
id
- the ObjectId of the file to be deletedcallback
- the callback that is completed once the file has been deletedpublic void rename(ObjectId id, java.lang.String newFilename, SingleResultCallback<java.lang.Void> callback)
GridFSBucket
id
.rename
in interface GridFSBucket
id
- the id of the file in the files collection to renamenewFilename
- the new filename for the filecallback
- the callback that is completed once the file has been renamedpublic void rename(BsonValue id, java.lang.String newFilename, SingleResultCallback<java.lang.Void> callback)
GridFSBucket
id
.rename
in interface GridFSBucket
id
- the id of the file in the files collection to renamenewFilename
- the new filename for the filecallback
- the callback that is completed once the file has been renamedpublic void drop(SingleResultCallback<java.lang.Void> callback)
GridFSBucket
drop
in interface GridFSBucket
callback
- the callback that is completed once the collection has been droppedprivate GridFSFindIterable findFileByName(java.lang.String filename, GridFSDownloadOptions options)
private static MongoCollection<GridFSFile> getFilesCollection(MongoDatabase database, java.lang.String bucketName)
private static MongoCollection<Document> getChunksCollection(MongoDatabase database, java.lang.String bucketName)
private void downloadToAsyncOutputStream(GridFSDownloadStream downloadStream, AsyncOutputStream destination, SingleResultCallback<java.lang.Long> callback)
private void readAndWriteInputStream(AsyncInputStream source, GridFSUploadStream uploadStream, java.nio.ByteBuffer buffer, SingleResultCallback<java.lang.Void> callback)
private void readAndWriteOutputStream(AsyncOutputStream destination, GridFSDownloadStream downloadStream, java.nio.ByteBuffer buffer, long amountRead, SingleResultCallback<java.lang.Long> callback)