Class LineAwareByteArrayOutputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.io.Flushable, java.lang.AutoCloseable

    public class LineAwareByteArrayOutputStream
    extends java.io.ByteArrayOutputStream
    A ByteArrayOutputStream which decodes bytes into string and invokes the given callback when a new line is detected. Can be used as outputStream in StreamGobbler to get progress from external process without waiting for process to finish. By default it accumulates written bytes (as does normal ByteArrayOutputStream), this can be disabled, so that written bytes are not accumulated, but callback is notified about detected lines. This is useful if external process reports only progress and its output can be big.
    • Method Detail

      • setCREndsLine

        public void setCREndsLine​(boolean CREndsLine)
      • write

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

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.ByteArrayOutputStream
        Throws:
        java.io.IOException