Interface OutputFormatter<T>

  • Type Parameters:
    T - the output format type
    All Known Implementing Classes:
    DummyFormatter, JsonOutputFormatter, TextLineFormatter

    public interface OutputFormatter<T>
    Generic output formatter. You may add information to one chunk until chunkCompleted() is called. Custom implementations must have a constructor with a single String argument, the character encoding name. Implementing classes shall use their specific rather than generic return types for getConverter() to reduce dependencies on <T>. Moreover, add(String, Object) shall be directly used in combination with InputParser.InputConverter to avoid exposing <T> unless explicitly necessary. This interface is used to generate connector code against.
    Author:
    Holger Eichelberger, SSE
    • Field Detail

      • SEPARATOR

        static final char SEPARATOR
        Separator for hierarchical names.
        See Also:
        Constant Field Values
    • Method Detail

      • add

        void add​(java.lang.String name,
                 T data)
          throws java.io.IOException
        Adds information to one chunk of output. Hierarchical names separated by SEPARATOR can be used, but nested values for the same parent (object) field must be named in sequence.
        Parameters:
        name - optional data name field (may be null for none)
        data - the data to be added
        Throws:
        java.io.IOException - if adding the data fails for some reason
      • startArrayStructure

        void startArrayStructure​(java.lang.String name)
                          throws java.io.IOException
        Starts an array structure. Following add(String, Object) calls will add elements to the array. Must be closed with endStructure()
        Parameters:
        name - optional data name field holding the array (may be null for none)
        Throws:
        java.io.IOException - if starting this structure fails
      • startObjectStructure

        void startObjectStructure​(java.lang.String name)
                           throws java.io.IOException
        Starts an object structure. Following add(String, Object) calls will add elements to the object. Must be closed with endStructure()
        Parameters:
        name - optional data name field holding the array (may be null for none)
        Throws:
        java.io.IOException - if starting this structure fails
      • endStructure

        void endStructure()
                   throws java.io.IOException
        Ends a structure started before.
        Throws:
        java.io.IOException - if ending the actual structure fails
      • chunkCompleted

        byte[] chunkCompleted()
                       throws java.io.IOException
        Completes a chunk of output data.
        Returns:
        the chunk
        Throws:
        java.io.IOException - if creating the chunk fails for some reason