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 is a file result that takes in the input stream as is and allows to simply forward it as file result. Since we do not know what kind of data it will deliver, there is no file size This should be used for large results whose results are in-determined
Since:
24.10
  • Constructor Details

    • LazyInputStreamFileResult

      public LazyInputStreamFileResult(@Nonnull @Nonnull String name, @Nonnull @Nonnull LazyInputStreamFileResult.InputStreamSupplier supplier)
      Create the lazy stream file result, just with a name and the stream
      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, then this method is called to clean up used system resources, i.e. to delete a created file.

      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

      @Nonnull 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 processed this result. Those calls come one after another: the first has finished it's work (closed the stream) when the second calls this method.

      The caller will close the Stream.

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

      @Nonnull 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 is could not be determined due to an IO problem
    • getFileName

      @Nonnull 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. E.g. in an email this will be the name of the attached file of this is a LocalFileResult, if this is a StringTextResult it will not appear in the email.

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