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()
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 GridFSUploadStream openUploadStream(ClientSession clientSession, 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 GridFSBucketclientSession - the client session with which to associate this operationfilename - the filename for the streampublic GridFSUploadStream openUploadStream(ClientSession clientSession, 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 GridFSBucketclientSession - 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)
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 GridFSBucketclientSession - 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)
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 GridFSBucketclientSession - 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)
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 GridFSBucketclientSession - 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)
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 ObjectId uploadFromStream(ClientSession clientSession, 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 GridFSBucketclientSession - 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)
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 GridFSBucketclientSession - 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)
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 GridFSBucketclientSession - 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)
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 GridFSBucketclientSession - 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)
GridFSBucketid.openDownloadStream in interface GridFSBucketid - the ObjectId of the file to be put into a stream.public 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 GridFSDownloadStream openDownloadStream(ClientSession clientSession, ObjectId id)
GridFSBucketid.openDownloadStream in interface GridFSBucketclientSession - 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)
GridFSBucketid.openDownloadStream in interface GridFSBucketclientSession - 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)
GridFSBucketfilename.openDownloadStream in interface GridFSBucketclientSession - 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)
GridFSBucketfilename and the revision
in options.openDownloadStream in interface GridFSBucketclientSession - 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)
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 void downloadToStream(ClientSession clientSession, ObjectId id, java.io.OutputStream destination)
GridFSBucketid and writes the contents to the destination Stream.downloadToStream in interface GridFSBucketclientSession - 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)
GridFSBucketid and writes the contents to the destination Stream.downloadToStream in interface GridFSBucketclientSession - 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)
GridFSBucketfilename and writes the contents to
the destination Stream.downloadToStream in interface GridFSBucketclientSession - 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)
GridFSBucketfilename and by the revision in options and writes the
contents to the destination Stream.downloadToStream in interface GridFSBucketclientSession - 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()
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 GridFSFindIterable find(ClientSession clientSession)
GridFSBucketfind in interface GridFSBucketclientSession - the client session with which to associate this operationpublic GridFSFindIterable find(ClientSession clientSession, 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 GridFSBucketclientSession - the client session with which to associate this operationfilter - the query filterFiltersprivate GridFSFindIterable createGridFSFindIterable(ClientSession clientSession, Bson filter)
public 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 delete(ClientSession clientSession, ObjectId id)
GridFSBucketid, delete this stored file's files collection document and associated chunks from a GridFS bucket.delete in interface GridFSBucketclientSession - the client session with which to associate this operationid - the ObjectId of the file to be deletedpublic void delete(ClientSession clientSession, BsonValue id)
GridFSBucketid, delete this stored file's files collection document and associated chunks from a GridFS bucket.delete in interface GridFSBucketclientSession - 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)
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 rename(ClientSession clientSession, ObjectId id, java.lang.String newFilename)
GridFSBucketid.rename in interface GridFSBucketclientSession - 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)
GridFSBucketid.rename in interface GridFSBucketclientSession - 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()
GridFSBucketdrop in interface GridFSBucketpublic void drop(ClientSession clientSession)
GridFSBucketdrop in interface GridFSBucketclientSession - the client session with which to associate this operation@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(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)