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(ClientSession clientSession) |
private <T> boolean |
collectionIsEmpty(ClientSession clientSession,
MongoCollection<T> collection) |
private FindIterable<GridFSFile> |
createFindIterable(ClientSession clientSession,
Bson filter) |
private GridFSDownloadStream |
createGridFSDownloadStream(ClientSession clientSession,
GridFSFile gridFSFile) |
private GridFSFindIterable |
createGridFSFindIterable(ClientSession clientSession,
Bson filter) |
private GridFSUploadStream |
createGridFSUploadStream(ClientSession clientSession,
BsonValue id,
java.lang.String filename,
GridFSUploadOptions options) |
private <T> void |
createIndex(ClientSession clientSession,
MongoCollection<T> collection,
Document index,
IndexOptions indexOptions) |
void |
delete(BsonValue id)
Given a
id , delete this stored file's files collection document and associated chunks from a GridFS bucket. |
void |
delete(ClientSession clientSession,
BsonValue id)
Given a
id , delete this stored file's files collection document and associated chunks from a GridFS bucket. |
void |
delete(ClientSession clientSession,
ObjectId 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. |
void |
downloadToStream(ClientSession clientSession,
BsonValue 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(ClientSession clientSession,
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(ClientSession clientSession,
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(ClientSession clientSession,
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. |
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.
|
void |
drop(ClientSession clientSession)
Drops the data associated with this bucket from the database.
|
private void |
executeDelete(ClientSession clientSession,
BsonValue id) |
private void |
executeRename(ClientSession clientSession,
BsonValue id,
java.lang.String newFilename) |
private void |
executeUploadFromStream(ClientSession clientSession,
BsonValue id,
java.lang.String filename,
java.io.InputStream source,
GridFSUploadOptions options) |
GridFSFindIterable |
find()
Finds all documents in the files collection.
|
GridFSFindIterable |
find(Bson filter)
Finds all documents in the collection that match the filter.
|
GridFSFindIterable |
find(ClientSession clientSession)
Finds all documents in the files collection.
|
GridFSFindIterable |
find(ClientSession clientSession,
Bson filter)
Finds all documents in the collection that match the filter.
|
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(ClientSession clientSession,
java.lang.String filename,
GridFSDownloadOptions options) |
private GridFSFile |
getFileInfoById(ClientSession clientSession,
BsonValue id) |
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(ClientSession clientSession,
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(ClientSession clientSession,
BsonValue id)
Opens a Stream from which the application can read the contents of the stored file specified by
id . |
GridFSDownloadStream |
openDownloadStream(ClientSession clientSession,
ObjectId id)
Opens a Stream from which the application can read the contents of the stored file specified by
id . |
GridFSDownloadStream |
openDownloadStream(ClientSession clientSession,
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(ClientSession clientSession,
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 |
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(ClientSession clientSession,
BsonValue id,
java.lang.String filename)
Opens a Stream that the application can write the contents of the file to.
|
GridFSUploadStream |
openUploadStream(ClientSession clientSession,
BsonValue id,
java.lang.String filename,
GridFSUploadOptions options)
Opens a Stream that the application can write the contents of the file to.
|
GridFSUploadStream |
openUploadStream(ClientSession clientSession,
ObjectId id,
java.lang.String filename)
Opens a Stream that the application can write the contents of the file to.
|
GridFSUploadStream |
openUploadStream(ClientSession clientSession,
java.lang.String filename)
Opens a Stream that the application can write the contents of the file to.
|
GridFSUploadStream |
openUploadStream(ClientSession clientSession,
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(ClientSession clientSession,
BsonValue id,
java.lang.String newFilename)
Renames the stored file with the specified
id . |
void |
rename(ClientSession clientSession,
ObjectId 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. |
void |
uploadFromStream(ClientSession clientSession,
BsonValue id,
java.lang.String filename,
java.io.InputStream source)
Uploads the contents of the given
InputStream to a GridFS bucket. |
void |
uploadFromStream(ClientSession clientSession,
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(ClientSession clientSession,
java.lang.String filename,
java.io.InputStream source)
Uploads the contents of the given
InputStream to a GridFS bucket. |
ObjectId |
uploadFromStream(ClientSession clientSession,
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()
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 GridFSBucketpublic GridFSBucket withWriteConcern(WriteConcern writeConcern)
GridFSBucket
withWriteConcern
in interface GridFSBucket
writeConcern
- the new WriteConcern
for the GridFSBucketpublic GridFSBucket withReadConcern(ReadConcern readConcern)
GridFSBucket
withReadConcern
in interface GridFSBucket
readConcern
- the new ReadConcern
for the GridFSBucketpublic 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 GridFSUploadStream openUploadStream(ClientSession clientSession, 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
clientSession
- the client session with which to associate this operationfilename
- the filename for the streampublic GridFSUploadStream openUploadStream(ClientSession clientSession, 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
clientSession
- the client session with which to associate this operationfilename
- the filename for the streamoptions
- the GridFSUploadOptionspublic GridFSUploadStream openUploadStream(ClientSession clientSession, ObjectId 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
clientSession
- the client session with which to associate this operationid
- the custom id value of the filefilename
- the filename for the streampublic GridFSUploadStream openUploadStream(ClientSession clientSession, 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
clientSession
- the client session with which to associate this operationid
- the custom id value of the filefilename
- the filename for the streampublic GridFSUploadStream openUploadStream(ClientSession clientSession, 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
clientSession
- the client session with which to associate this operationid
- the custom id value of the filefilename
- the filename for the streamoptions
- the GridFSUploadOptionsprivate GridFSUploadStream createGridFSUploadStream(ClientSession clientSession, BsonValue id, java.lang.String filename, GridFSUploadOptions options)
public ObjectId uploadFromStream(java.lang.String filename, java.io.InputStream source)
GridFSBucket
InputStream
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 GridFSBucket
filename
- the filename for the streamsource
- the Stream providing the file datapublic ObjectId uploadFromStream(java.lang.String filename, java.io.InputStream source, GridFSUploadOptions options)
GridFSBucket
InputStream
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 GridFSBucket
filename
- 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)
GridFSBucket
InputStream
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 GridFSBucket
id
- 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)
GridFSBucket
InputStream
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 GridFSBucket
id
- the custom id value of the filefilename
- the filename for the streamsource
- the Stream providing the file dataoptions
- the GridFSUploadOptionspublic ObjectId uploadFromStream(ClientSession clientSession, java.lang.String filename, java.io.InputStream source)
GridFSBucket
InputStream
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 GridFSBucket
clientSession
- the client session with which to associate this operationfilename
- the filename for the streamsource
- the Stream providing the file datapublic ObjectId uploadFromStream(ClientSession clientSession, java.lang.String filename, java.io.InputStream source, GridFSUploadOptions options)
GridFSBucket
InputStream
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 GridFSBucket
clientSession
- the client session with which to associate this operationfilename
- the filename for the streamsource
- the Stream providing the file dataoptions
- the GridFSUploadOptionspublic void uploadFromStream(ClientSession clientSession, BsonValue id, java.lang.String filename, java.io.InputStream source)
GridFSBucket
InputStream
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 GridFSBucket
clientSession
- the client session with which to associate this operationid
- the custom id value of the filefilename
- the filename for the streamsource
- the Stream providing the file datapublic void uploadFromStream(ClientSession clientSession, BsonValue id, java.lang.String filename, java.io.InputStream source, GridFSUploadOptions options)
GridFSBucket
InputStream
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 GridFSBucket
clientSession
- the client session with which to associate this operationid
- the custom id value of the filefilename
- the filename for the streamsource
- the Stream providing the file dataoptions
- the GridFSUploadOptionsprivate void executeUploadFromStream(ClientSession clientSession, BsonValue id, java.lang.String filename, java.io.InputStream source, GridFSUploadOptions options)
public GridFSDownloadStream openDownloadStream(ObjectId id)
GridFSBucket
id
.openDownloadStream
in interface GridFSBucket
id
- the ObjectId of the file to be put into a stream.public 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 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 GridFSDownloadStream openDownloadStream(ClientSession clientSession, ObjectId id)
GridFSBucket
id
.openDownloadStream
in interface GridFSBucket
clientSession
- the client session with which to associate this operationid
- the ObjectId of the file to be put into a stream.public GridFSDownloadStream openDownloadStream(ClientSession clientSession, BsonValue id)
GridFSBucket
id
.openDownloadStream
in interface GridFSBucket
clientSession
- the client session with which to associate this operationid
- the custom id value of the file, to be put into a stream.public GridFSDownloadStream openDownloadStream(ClientSession clientSession, java.lang.String filename)
GridFSBucket
filename
.openDownloadStream
in interface GridFSBucket
clientSession
- the client session with which to associate this operationfilename
- the name of the file to be downloadedpublic GridFSDownloadStream openDownloadStream(ClientSession clientSession, java.lang.String filename, GridFSDownloadOptions options)
GridFSBucket
filename
and the revision
in options
.openDownloadStream
in interface GridFSBucket
clientSession
- the client session with which to associate this operationfilename
- the name of the file to be downloadedoptions
- the download optionsprivate GridFSDownloadStream createGridFSDownloadStream(ClientSession clientSession, GridFSFile gridFSFile)
public void downloadToStream(ObjectId id, java.io.OutputStream destination)
GridFSBucket
id
and writes the contents to the destination
Stream.downloadToStream
in interface GridFSBucket
id
- the ObjectId of the file to be written to the destination streamdestination
- the destination streampublic void downloadToStream(BsonValue id, java.io.OutputStream destination)
GridFSBucket
id
and writes the contents to the destination
Stream.downloadToStream
in interface GridFSBucket
id
- 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)
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 streampublic void downloadToStream(java.lang.String filename, java.io.OutputStream destination, GridFSDownloadOptions options)
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 optionspublic void downloadToStream(ClientSession clientSession, ObjectId id, java.io.OutputStream destination)
GridFSBucket
id
and writes the contents to the destination
Stream.downloadToStream
in interface GridFSBucket
clientSession
- the client session with which to associate this operationid
- the ObjectId of the file to be written to the destination streamdestination
- the destination streampublic void downloadToStream(ClientSession clientSession, BsonValue id, java.io.OutputStream destination)
GridFSBucket
id
and writes the contents to the destination
Stream.downloadToStream
in interface GridFSBucket
clientSession
- the client session with which to associate this operationid
- the custom id of the file, to be written to the destination streamdestination
- the destination streampublic void downloadToStream(ClientSession clientSession, java.lang.String filename, java.io.OutputStream destination)
GridFSBucket
filename
and writes the contents to
the destination
Stream.downloadToStream
in interface GridFSBucket
clientSession
- the client session with which to associate this operationfilename
- the name of the file to be downloadeddestination
- the destination streampublic void downloadToStream(ClientSession clientSession, java.lang.String filename, java.io.OutputStream destination, GridFSDownloadOptions options)
GridFSBucket
filename
and by the revision in options
and writes the
contents to the destination
Stream.downloadToStream
in interface GridFSBucket
clientSession
- the client session with which to associate this operationfilename
- the name of the file to be downloadeddestination
- the destination streamoptions
- the download optionspublic 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 GridFSFindIterable find(ClientSession clientSession)
GridFSBucket
find
in interface GridFSBucket
clientSession
- the client session with which to associate this operationpublic GridFSFindIterable find(ClientSession clientSession, 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
clientSession
- the client session with which to associate this operationfilter
- the query filterFilters
private GridFSFindIterable createGridFSFindIterable(ClientSession clientSession, Bson filter)
public void delete(ObjectId id)
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 deletedpublic void delete(BsonValue id)
GridFSBucket
id
, delete this stored file's files collection document and associated chunks from a GridFS bucket.delete
in interface GridFSBucket
id
- the id of the file to be deletedpublic void delete(ClientSession clientSession, ObjectId id)
GridFSBucket
id
, delete this stored file's files collection document and associated chunks from a GridFS bucket.delete
in interface GridFSBucket
clientSession
- the client session with which to associate this operationid
- the ObjectId of the file to be deletedpublic void delete(ClientSession clientSession, BsonValue id)
GridFSBucket
id
, delete this stored file's files collection document and associated chunks from a GridFS bucket.delete
in interface GridFSBucket
clientSession
- the client session with which to associate this operationid
- the id of the file to be deletedprivate void executeDelete(ClientSession clientSession, BsonValue id)
public void rename(ObjectId id, java.lang.String newFilename)
GridFSBucket
id
.rename
in interface GridFSBucket
id
- 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)
GridFSBucket
id
.rename
in interface GridFSBucket
id
- the id of the file in the files collection to renamenewFilename
- the new filename for the filepublic void rename(ClientSession clientSession, ObjectId id, java.lang.String newFilename)
GridFSBucket
id
.rename
in interface GridFSBucket
clientSession
- the client session with which to associate this operationid
- the id of the file in the files collection to renamenewFilename
- the new filename for the filepublic void rename(ClientSession clientSession, BsonValue id, java.lang.String newFilename)
GridFSBucket
id
.rename
in interface GridFSBucket
clientSession
- the client session with which to associate this operationid
- the id of the file in the files collection to renamenewFilename
- the new filename for the fileprivate void executeRename(ClientSession clientSession, BsonValue id, java.lang.String newFilename)
public void drop()
GridFSBucket
drop
in interface GridFSBucket
public void drop(ClientSession clientSession)
GridFSBucket
drop
in interface GridFSBucket
clientSession
- the client session with which to associate this operation@Deprecated public GridFSDownloadStream openDownloadStreamByName(java.lang.String filename)
GridFSBucket
filename
.openDownloadStreamByName
in interface GridFSBucket
filename
- the name of the file to be downloaded@Deprecated public GridFSDownloadStream openDownloadStreamByName(java.lang.String filename, GridFSDownloadByNameOptions options)
GridFSBucket
filename
and the revision
in options
.openDownloadStreamByName
in interface GridFSBucket
filename
- the name of the file to be downloadedoptions
- the download options@Deprecated public void downloadToStreamByName(java.lang.String filename, java.io.OutputStream destination)
GridFSBucket
filename
and writes the contents to
the destination
Stream.downloadToStreamByName
in interface GridFSBucket
filename
- 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)
GridFSBucket
filename
and by the revision in options
and writes the
contents to the destination
Stream.downloadToStreamByName
in interface GridFSBucket
filename
- 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(ClientSession clientSession)
private <T> boolean collectionIsEmpty(ClientSession clientSession, MongoCollection<T> collection)
private <T> boolean hasIndex(ClientSession clientSession, MongoCollection<T> collection, Document index)
private <T> void createIndex(ClientSession clientSession, MongoCollection<T> collection, Document index, IndexOptions indexOptions)
private GridFSFile getFileByName(ClientSession clientSession, java.lang.String filename, GridFSDownloadOptions options)
private GridFSFile getFileInfoById(ClientSession clientSession, BsonValue id)
private FindIterable<GridFSFile> createFindIterable(ClientSession clientSession, Bson filter)
private void downloadToStream(GridFSDownloadStream downloadStream, java.io.OutputStream destination)