Class ReactiveGridFsResource
java.lang.Object
org.springframework.data.mongodb.gridfs.ReactiveGridFsResource
- All Implemented Interfaces:
GridFsObject<Object,
org.reactivestreams.Publisher<org.springframework.core.io.buffer.DataBuffer>>
public class ReactiveGridFsResource
extends Object
implements GridFsObject<Object,org.reactivestreams.Publisher<org.springframework.core.io.buffer.DataBuffer>>
- Since:
- 2.2
- Author:
- Mark Paluch, Christoph Strobl
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.data.mongodb.gridfs.GridFsObject
GridFsObject.Options
-
Constructor Summary
ConstructorDescriptionReactiveGridFsResource
(Object id, String filename, GridFsObject.Options options, com.mongodb.reactivestreams.client.gridfs.GridFSDownloadPublisher downloadPublisher) Creates a new, absentReactiveGridFsResource
.ReactiveGridFsResource
(String filename, com.mongodb.reactivestreams.client.gridfs.GridFSDownloadPublisher downloadPublisher) Creates a new, absentReactiveGridFsResource
. -
Method Summary
Modifier and TypeMethodDescriptionstatic ReactiveGridFsResource
Obtain an absentReactiveGridFsResource
.boolean
exists()
reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer>
The actual file content.reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer>
Obtain the download stream emitting chunks of data as they come in.reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer>
getDownloadStream
(int chunkSize) Obtain the download stream emitting chunks of data with givenchunkSize
as they come in.TheGridFSFile.getId()
value converted into its simple java type.The filename.reactor.core.publisher.Mono<com.mongodb.client.gridfs.model.GridFSFile>
reactor.core.publisher.Mono<InputStream>
Obtain the data asInputStream
.Additional information like file metadata (eg. contentType).
-
Constructor Details
-
ReactiveGridFsResource
public ReactiveGridFsResource(String filename, @Nullable com.mongodb.reactivestreams.client.gridfs.GridFSDownloadPublisher downloadPublisher) Creates a new, absentReactiveGridFsResource
.- Parameters:
filename
- filename of the absent resource.downloadPublisher
-
-
ReactiveGridFsResource
public ReactiveGridFsResource(@Nullable Object id, String filename, GridFsObject.Options options, @Nullable com.mongodb.reactivestreams.client.gridfs.GridFSDownloadPublisher downloadPublisher) Creates a new, absentReactiveGridFsResource
.- Parameters:
id
-filename
- filename of the absent resource.options
-downloadPublisher
-- Since:
- 3.0
-
-
Method Details
-
absent
Obtain an absentReactiveGridFsResource
.- Parameters:
filename
- filename of the absent resource, must not be null.- Returns:
- never null.
- Since:
- 2.1
-
getFileId
Description copied from interface:GridFsObject
TheGridFSFile.getId()
value converted into its simple java type.
ABsonString
will be converted to plainString
.- Specified by:
getFileId
in interfaceGridFsObject<Object,
org.reactivestreams.Publisher<org.springframework.core.io.buffer.DataBuffer>> - Returns:
- can be null depending on the implementation.
-
getFilename
Description copied from interface:GridFsObject
The filename.- Specified by:
getFilename
in interfaceGridFsObject<Object,
org.reactivestreams.Publisher<org.springframework.core.io.buffer.DataBuffer>> - Returns:
- Throws:
IllegalStateException
- See Also:
-
AbstractResource.getFilename()
-
getGridFSFile
public reactor.core.publisher.Mono<com.mongodb.client.gridfs.model.GridFSFile> getGridFSFile()- Returns:
- the underlying
GridFSFile
. Can be null if absent. - Since:
- 2.2
-
getInputStream
Obtain the data asInputStream
.
NOTE Buffers data in memory. UsegetDownloadStream()
for large files.- Throws:
IllegalStateException
- if the underlyingPublisher
has already been consumed.- Since:
- 3.0
- See Also:
-
InputStreamResource.getInputStream()
getDownloadStream()
DataBufferUtils.join(Publisher)
-
getDownloadStream
public reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer> getDownloadStream()Obtain the download stream emitting chunks of data as they come in.- Returns:
Flux.empty()
if the file does not exist.- Throws:
IllegalStateException
- if the underlyingPublisher
has already been consumed.- Since:
- 3.0
- See Also:
-
InputStreamResource.getInputStream()
getDownloadStream()
DataBufferUtils.join(Publisher)
-
getContent
public reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer> getContent()Description copied from interface:GridFsObject
The actual file content.- Specified by:
getContent
in interfaceGridFsObject<Object,
org.reactivestreams.Publisher<org.springframework.core.io.buffer.DataBuffer>> - Returns:
-
getOptions
Description copied from interface:GridFsObject
Additional information like file metadata (eg. contentType).- Specified by:
getOptions
in interfaceGridFsObject<Object,
org.reactivestreams.Publisher<org.springframework.core.io.buffer.DataBuffer>> - Returns:
- never null.
-
getDownloadStream
public reactor.core.publisher.Flux<org.springframework.core.io.buffer.DataBuffer> getDownloadStream(int chunkSize) Obtain the download stream emitting chunks of data with givenchunkSize
as they come in.- Parameters:
chunkSize
- the preferred number of bytes per emittedDataBuffer
.- Returns:
Flux.empty()
if the file does not exist.- Throws:
IllegalStateException
- if the underlyingPublisher
has already been consumed.- Since:
- 3.0
- See Also:
-
InputStreamResource.getInputStream()
getDownloadStream()
DataBufferUtils.join(Publisher)
-
exists
public boolean exists()
-