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>>
Reactive GridFSFile based Resource implementation. Note that the content can be consumed only once.
Since:
2.2
Author:
Mark Paluch, Christoph Strobl
  • Constructor Details

    • ReactiveGridFsResource

      public ReactiveGridFsResource(String filename, @Nullable com.mongodb.reactivestreams.client.gridfs.GridFSDownloadPublisher downloadPublisher)
      Creates a new, absent ReactiveGridFsResource.
      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, absent ReactiveGridFsResource.
      Parameters:
      id -
      filename - filename of the absent resource.
      options -
      downloadPublisher -
      Since:
      3.0
  • Method Details

    • absent

      public static ReactiveGridFsResource absent(String filename)
      Obtain an absent ReactiveGridFsResource.
      Parameters:
      filename - filename of the absent resource, must not be null.
      Returns:
      never null.
      Since:
      2.1
    • getFileId

      public Object getFileId()
      Description copied from interface: GridFsObject
      The GridFSFile.getId() value converted into its simple java type.
      A BsonString will be converted to plain String.
      Specified by:
      getFileId in interface GridFsObject<Object,org.reactivestreams.Publisher<org.springframework.core.io.buffer.DataBuffer>>
      Returns:
      can be null depending on the implementation.
    • getFilename

      public String getFilename() throws IllegalStateException
      Description copied from interface: GridFsObject
      The filename.
      Specified by:
      getFilename in interface GridFsObject<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

      public reactor.core.publisher.Mono<InputStream> getInputStream() throws IllegalStateException
      Obtain the data as InputStream.
      NOTE: Buffers data in memory. Use getDownloadStream() for large files.
      Throws:
      IllegalStateException - if the underlying Publisher has already been consumed.
      Since:
      3.0
      See Also:
    • 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 underlying Publisher has already been consumed.
      Since:
      3.0
      See Also:
    • 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 interface GridFsObject<Object,org.reactivestreams.Publisher<org.springframework.core.io.buffer.DataBuffer>>
      Returns:
    • getOptions

      public GridFsObject.Options getOptions()
      Description copied from interface: GridFsObject
      Additional information like file metadata (eg. contentType).
      Specified by:
      getOptions in interface GridFsObject<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 given chunkSize as they come in.
      Parameters:
      chunkSize - the preferred number of bytes per emitted DataBuffer.
      Returns:
      Flux.empty() if the file does not exist.
      Throws:
      IllegalStateException - if the underlying Publisher has already been consumed.
      Since:
      3.0
      See Also:
    • exists

      public boolean exists()