Class LogReader

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

    public class LogReader
    extends java.io.FilterReader
    A reader that logs any char read.

    The reader is piped in the reading process, any characters read are written to an associated writer object.

     Client -> LogReader -> Reader -> Source
                |
                v
               Writer
     
    todo make closing of associated writer configurable
    • Field Summary

      • Fields inherited from class java.io.FilterReader

        in
      • Fields inherited from class java.io.Reader

        lock
    • Constructor Summary

      Constructors 
      Constructor Description
      LogReader​(java.io.Reader in, java.io.Writer w)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      java.io.Writer getLog()  
      int read()  
      int read​(char[] cbuf, int off, int len)
      Read characters into a portion of an array.
      void setLog​(java.io.Writer newLog)  
      • Methods inherited from class java.io.FilterReader

        mark, markSupported, ready, reset, skip
      • Methods inherited from class java.io.Reader

        nullReader, read, read, transferTo
      • Methods inherited from class java.lang.Object

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

      • LogReader

        public LogReader​(java.io.Reader in,
                         java.io.Writer w)
    • Method Detail

      • 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.FilterReader
        Throws:
        java.io.IOException
      • getLog

        public java.io.Writer getLog()
      • read

        public int read()
                 throws java.io.IOException
        Overrides:
        read in class java.io.FilterReader
        Throws:
        java.io.IOException
      • read

        public int read​(char[] cbuf,
                        int off,
                        int len)
                 throws java.io.IOException
        Read characters into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.
        Overrides:
        read in class java.io.FilterReader
        Parameters:
        cbuf - Destination buffer
        off - Offset at which to start storing characters
        len - Maximum number of characters to read
        Returns:
        The number of characters read, or -1 if the end of the stream has been reached
        Throws:
        java.io.IOException - If an I/O error occurs
      • setLog

        public void setLog​(java.io.Writer newLog)