Class LazyInputStreamFileResult

java.lang.Object
com.inet.taskplanner.server.api.result.LazyInputStreamFileResult
All Implemented Interfaces:
FileResult, Result

public class LazyInputStreamFileResult extends Object implements FileResult
This file result obtains its content from an input-stream supplier and forwards it as a file result. Since the content is supplied lazily, its size is unknown. This should be used for large results whose size is undetermined.
Since:
24.10
  • Constructor Details

    • LazyInputStreamFileResult

      public LazyInputStreamFileResult(@Nonnull String name, @Nonnull LazyInputStreamFileResult.InputStreamSupplier supplier)
      Creates a lazy stream file result with a name and an input-stream supplier.
      Parameters:
      name - the name of the result file
      supplier - supplier of the input stream to use
      Since:
      24.10
  • Method Details

    • cleanup

      public void cleanup() throws Exception
      When result handling is finished, this method is called to release resources held by the result.

      This is also called if no appropriate ResultAction handled this result.

      Specified by:
      cleanup in interface Result
      Throws:
      Exception - if there was an IO problem
    • getFileSize

      public long getFileSize() throws Exception
      Returns the size of this result in bytes.
      Specified by:
      getFileSize in interface FileResult
      Returns:
      the size in bytes
      Throws:
      Exception - if the result data makes problems
    • getFileContent

      public @Nonnull InputStream getFileContent() throws Exception
      Get a stream to access the data of this result.

      Note that this method is called multiple times when more than one action processes this result. Those calls come one after another: the first action has finished its work (and closed the stream) before the second calls this method.

      The caller will close the Stream.

      Specified by:
      getFileContent in interface FileResult
      Returns:
      an input stream that can transfer the data of this result
      Throws:
      Exception - if there is a problem accessing the data
    • getFileContentType

      public @Nonnull String getFileContentType() throws Exception
      Get the MIME type this result has.
      Specified by:
      getFileContentType in interface FileResult
      Returns:
      the content type of this result. When null, 'application/octet-stream' is to be used.
      Throws:
      Exception - if the type could not be determined due to an IO problem
    • getFileName

      public @Nonnull String getFileName()
      Returns a human-readable name of this result, typically a file name.

      It depends on the Result-implementation and on the ResultAction whether and where this appears. For example, in an email, this can be used as the name of an attached file.

      Specified by:
      getFileName in interface FileResult
      Returns:
      a name for this result.