Class ByteBufferTeePrintStream

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

    public class ByteBufferTeePrintStream
    extends java.io.PrintStream
    PrintStream which performs every write twice: once to the original output stream, and another to an internal byte array, so the full output can be later collected and processed transparently. Since ByteArrayOutputStream.close() and OutputStream.flush() do not do anything, they are not called from this class.
    Version:
    1.0
    Author:
    Antonio García-Domínguez
    • Field Summary

      • Fields inherited from class java.io.FilterOutputStream

        out
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte[] getBytes()
      Returns the bytes collected by this output stream.
      void write​(byte[] buf)  
      void write​(byte[] buf, int off, int len)  
      void write​(int b)  
      • Methods inherited from class java.io.PrintStream

        append, append, append, checkError, clearError, close, flush, format, format, print, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, println, setError
      • Methods inherited from class java.io.OutputStream

        nullOutputStream
      • Methods inherited from class java.lang.Object

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

      • ByteBufferTeePrintStream

        public ByteBufferTeePrintStream​(java.io.OutputStream out)
      • ByteBufferTeePrintStream

        public ByteBufferTeePrintStream​(java.lang.String fileName)
                                 throws java.io.FileNotFoundException
        Throws:
        java.io.FileNotFoundException
      • ByteBufferTeePrintStream

        public ByteBufferTeePrintStream​(java.io.File file)
                                 throws java.io.FileNotFoundException
        Throws:
        java.io.FileNotFoundException
      • ByteBufferTeePrintStream

        public ByteBufferTeePrintStream​(java.io.OutputStream out,
                                        boolean autoFlush)
      • ByteBufferTeePrintStream

        public ByteBufferTeePrintStream​(java.lang.String fileName,
                                        java.lang.String csn)
                                 throws java.io.FileNotFoundException,
                                        java.io.UnsupportedEncodingException
        Throws:
        java.io.FileNotFoundException
        java.io.UnsupportedEncodingException
      • ByteBufferTeePrintStream

        public ByteBufferTeePrintStream​(java.io.File file,
                                        java.lang.String csn)
                                 throws java.io.FileNotFoundException,
                                        java.io.UnsupportedEncodingException
        Throws:
        java.io.FileNotFoundException
        java.io.UnsupportedEncodingException
      • ByteBufferTeePrintStream

        public ByteBufferTeePrintStream​(java.io.OutputStream out,
                                        boolean autoFlush,
                                        java.lang.String encoding)
                                 throws java.io.UnsupportedEncodingException
        Throws:
        java.io.UnsupportedEncodingException
    • Method Detail

      • write

        public void write​(int b)
        Overrides:
        write in class java.io.PrintStream
      • write

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

        public void write​(byte[] buf)
                   throws java.io.IOException
        Overrides:
        write in class java.io.FilterOutputStream
        Throws:
        java.io.IOException
      • getBytes

        public byte[] getBytes()
        Returns the bytes collected by this output stream.