Class StringDrain

  • All Implemented Interfaces:
    Drain

    public class StringDrain
    extends java.lang.Object
    implements Drain
    Drain implementation gathering all output in a StringBuffer.

    The result string can be accessed through the toString() method.

    • Constructor Summary

      Constructors 
      Constructor Description
      StringDrain()
      Constructs a new StringDrain which will append/reconstruct newlines.
      StringDrain​(boolean appendNewlines)
      Creates a new StringDrain which optionally appends newline to each processed line.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void drain​(java.lang.String line)
      Callback method to process a line outputted by the process.
      boolean isAppendingNewlines()
      Accesses whether newline characters are appended to each consumed line.
      java.lang.String toString()
      Accesses the current contents of this StringDrain.
      • Methods inherited from class java.lang.Object

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

      • StringDrain

        public StringDrain()
        Constructs a new StringDrain which will append/reconstruct newlines.
      • StringDrain

        public StringDrain​(boolean appendNewlines)
        Creates a new StringDrain which optionally appends newline to each processed line.
        Parameters:
        appendNewlines - whether newlines (\n) should be appended to each line, this would reconstruct the original contents of the output.
    • Method Detail

      • drain

        public void drain​(java.lang.String line)
        Callback method to process a line outputted by the process. A trailing newline character is truncated.
        Specified by:
        drain in interface Drain
        Parameters:
        line - the output line to process.
        See Also:
        Drain.drain(String)
      • isAppendingNewlines

        public boolean isAppendingNewlines()
        Accesses whether newline characters are appended to each consumed line.
        Returns:
        the appendNewlines flag as specified on construction time.
      • toString

        public java.lang.String toString()
        Accesses the current contents of this StringDrain.
        Overrides:
        toString in class java.lang.Object
        Returns:
        the current contents of the underlying StringBuffer, i.e. all data forwarded to this Drain yet.
        See Also:
        Object.toString()