Class TeeInputStream

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

    public class TeeInputStream
    extends java.io.InputStream
    Input stream that copies data read to another output stream. This stream is primarily useful with a TemporaryBuffer, where any data read or skipped by the caller is also duplicated into the temporary buffer. Later the temporary buffer can then be used instead of the original source stream. During close this stream copies any remaining data from the source stream into the destination stream.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.io.OutputStream dst  
      private byte[] skipBuffer  
      private java.io.InputStream src  
    • Constructor Summary

      Constructors 
      Constructor Description
      TeeInputStream​(java.io.InputStream src, java.io.OutputStream dst)
      Initialize a tee input stream.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      int read()
      int read​(byte[] b, int off, int len)
      long skip​(long count)
      private byte[] skipBuffer()  
      • Methods inherited from class java.io.InputStream

        available, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, transferTo
      • Methods inherited from class java.lang.Object

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

      • skipBuffer

        private byte[] skipBuffer
      • src

        private java.io.InputStream src
      • dst

        private java.io.OutputStream dst
    • Constructor Detail

      • TeeInputStream

        public TeeInputStream​(java.io.InputStream src,
                              java.io.OutputStream dst)
        Initialize a tee input stream.
        Parameters:
        src - source stream to consume.
        dst - destination to copy the source to as it is consumed. Typically this is a TemporaryBuffer.
    • Method Detail

      • read

        public int read()
                 throws java.io.IOException
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • skip

        public long skip​(long count)
                  throws java.io.IOException
        Overrides:
        skip in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

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

        private byte[] skipBuffer()