Class StringTextResult

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

public class StringTextResult extends Object implements TextResult
A result that contains human-readable text.
Since:
taskplanner 3.0
  • Constructor Details

    • StringTextResult

      public StringTextResult(String text, String contentType)
      Creates a new StringTextResult instance.
      Parameters:
      text - the text this result contains.
      contentType - the content type, typical MimeTypes.TXT or MimeTypes.HTM
      Since:
      taskplanner 3.0
  • Method Details

    • getTextContent

      public @Nonnull InputStream getTextContent() throws IOException
      Returns a new UTF-8 encoded input stream containing this result's text. Each invocation creates an independent stream positioned at the beginning of the text.
      Specified by:
      getTextContent in interface TextResult
      Returns:
      the text content as a UTF-8 input stream.
      Throws:
      IOException - if the input stream cannot be created
      Since:
      taskplanner 3.0
    • cleanup

      public void cleanup() throws IOException
      Releases resources held by this result. Because this result stores its content in memory, there are no resources to release and this method does nothing.
      Specified by:
      cleanup in interface Result
      Throws:
      IOException - if an error occurs while releasing resources
      Since:
      taskplanner 3.0
    • getTextContentType

      public String getTextContentType() throws Exception
      Get the MIME type this result has.
      Specified by:
      getTextContentType in interface TextResult
      Returns:
      the content type of this result. When null, 'text/plain' is to be used.
      Throws:
      Exception - if the type could not be determined due to an IO problem
    • getText

      public String getText() throws IOException
      Returns the content of the result in the form of a String. The actual interpretation of the content depends on the type as returned by TextResult.getTextContentType().
      Specified by:
      getText in interface TextResult
      Returns:
      the content as a String
      Throws:
      IOException - thrown if the content is created on demand and the creation failed