Class StdOutputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable
    Direct Known Subclasses:
    StdErr, StdOut

    abstract class StdOutputStream
    extends java.io.OutputStream
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.io.ByteArrayOutputStream out  
    • Constructor Summary

      Constructors 
      Constructor Description
      StdOutputStream()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String[] capturedLines()
      The capturedString(), divided on the line separator.
      java.lang.String capturedString()  
      void write​(byte[] b, int off, int len)  
      void write​(int i)  
      • Methods inherited from class java.io.OutputStream

        close, flush, nullOutputStream, write
      • Methods inherited from class java.lang.Object

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

      • out

        private final java.io.ByteArrayOutputStream out
    • Constructor Detail

      • StdOutputStream

        public StdOutputStream()
    • Method Detail

      • write

        public void write​(int i)
        Specified by:
        write in class java.io.OutputStream
      • write

        public final void write​(byte[] b,
                                int off,
                                int len)
        Overrides:
        write in class java.io.OutputStream
      • capturedString

        public java.lang.String capturedString()
        Returns:
        the string that was written to System.out or System.err
      • capturedLines

        public java.lang.String[] capturedLines()
        The capturedString(), divided on the line separator.

        This includes leading, inner, and trailing empty lines but does not include the potential empty string that comes after a trailing line separator. (The exact algorithm is based on but behaves differently from String.split(String).)

        Because the return value does not include a trailing empty line that comes from a trailing line separator, it can't be used to distinguish the cases where the last line was created by a print or a println. For more details and examples on this, see the documentation on standard input/output.

        Returns:
        the lines that were written to System.out or System.err