Class LoggingInputStream

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

    public class LoggingInputStream
    extends java.io.FilterInputStream
    Thread-safe input stream wrapper that forwards all reads to a given input stream, while logging all reads to a LoggingByteArrayOutputStream.
    Since:
    1.9
    • Constructor Summary

      Constructors 
      Constructor Description
      LoggingInputStream​(java.io.InputStream inputStream, java.util.logging.Logger logger, java.util.logging.Level loggingLevel, int contentLoggingLimit)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      LoggingByteArrayOutputStream getLogStream()
      Returns the log stream.
      int read()  
      int read​(byte[] b, int off, int len)  
      • Methods inherited from class java.io.FilterInputStream

        available, mark, markSupported, read, reset, skip
      • Methods inherited from class java.lang.Object

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

      • LoggingInputStream

        public LoggingInputStream​(java.io.InputStream inputStream,
                                  java.util.logging.Logger logger,
                                  java.util.logging.Level loggingLevel,
                                  int contentLoggingLimit)
        Parameters:
        inputStream - input stream to forward all reads to
        logger - logger
        loggingLevel - logging level
        contentLoggingLimit - maximum number of bytes to log (may be 0 to avoid logging content)
    • Method Detail

      • read

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

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Overrides:
        read in class java.io.FilterInputStream
        Throws:
        java.io.IOException
      • 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.FilterInputStream
        Throws:
        java.io.IOException