Class LocalFileResult

  • All Implemented Interfaces:
    FileResult, Result

    public class LocalFileResult
    extends java.lang.Object
    implements FileResult
    A result that is based on a file.
    Since:
    taskplanner 3.0
    • Constructor Summary

      Constructors 
      Constructor Description
      LocalFileResult​(java.io.File file, boolean deleteOnCleanUp)
      Create a new instance.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void cleanup()
      When result-handling is finished, then this method is called to clean up used system resources, i.e.
      java.io.InputStream getFileContent()
      Get a stream to access the data of this result.
      java.lang.String getFileContentType()
      Get the MIME type this result has.
      java.lang.String getFileName()
      Returns a human readable name of this result, typically a file name.
      long getFileSize()
      Returns the size of this result in bytes.
      java.util.List<ResultFlavor> getFlavors()
      Defined the types of data this Result contains.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LocalFileResult

        public LocalFileResult​(@Nonnull
                               java.io.File file,
                               boolean deleteOnCleanUp)
        Create a new instance.
        Parameters:
        file - the underlying file. Cannot be a directory.
        deleteOnCleanUp - if true, the file will be deleted after processing all results (even if this result was not used)
        Throws:
        java.lang.IllegalArgumentException - if the given file is a directory
        java.lang.NullPointerException - if file is null
        Since:
        taskplanner 3.0
    • Method Detail

      • getFileName

        @Nonnull
        public java.lang.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.
      • getFileSize

        public long getFileSize()
        Returns the size of this result in bytes.
        Specified by:
        getFileSize in interface FileResult
        Returns:
        the size in bytes
      • getFileContent

        @Nonnull
        public java.io.InputStream getFileContent()
                                           throws java.io.IOException
        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:
        java.io.IOException
      • cleanup

        public void cleanup()
        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
      • getFileContentType

        public java.lang.String getFileContentType()
                                            throws java.io.IOException
        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:
        java.io.IOException