Class LookAheadBufferedReader

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

    public class LookAheadBufferedReader
    extends java.io.BufferedReader
    This is an enhanced BufferedReader used for transparently collect data from the incoming stream before it gets consumed by the usual buffered reader logic. The data is not actually consumed, it is just buffered beside and it can be printed in case we want to debug the underlying stream content. The name refers to the usage pattern: this reader is used for wrapping a character stream coming from a remote call and, in case of issues, it collects the remaining (i.e. unread) part of the stream so it will be available for debugging purposes. It provides two different collecting modes:
    • windowing: the collected data is a window of the original stream (about 500 chars), and the character that caused a stop in the reading is more or less in the middle of that window.
    • everything: the collected data is the whole character stream
    The two modes are activated on each instance depending on the level of the Logger passed in input. Specifically:
    • DEBUG: enables the windowing mode
    • TRACE: enables the "collect everything" mode
    • other levels simply disables the buffering behaviour (i.e. nothing is collected)
    • Field Summary

      • Fields inherited from class java.io.Reader

        lock
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String lookAheadAndGetBufferedContent()  
      int read()  
      • Methods inherited from class java.io.BufferedReader

        close, lines, mark, markSupported, read, readLine, 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

      • LookAheadBufferedReader

        public LookAheadBufferedReader​(java.io.Reader in,
                                       int windowSize,
                                       org.slf4j.Logger logger)
      • LookAheadBufferedReader

        public LookAheadBufferedReader​(java.io.Reader in,
                                       org.slf4j.Logger logger)
    • Method Detail

      • read

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

        public java.lang.String lookAheadAndGetBufferedContent()