Class BufferedDelegateInputStream

  • All Implemented Interfaces:
    Closeable, AutoCloseable
    Direct Known Subclasses:
    LZ4CompressingInputStream

    public abstract class BufferedDelegateInputStream
    extends InputStream
    InputStream that wraps a delegate InputStream, buffering reads to the delegate. Allows a customized strategy for refilling the internal buffer from the delegate stream for use cases such as decompressing a compressed stream.
    • Constructor Detail

      • BufferedDelegateInputStream

        public BufferedDelegateInputStream​(InputStream delegate,
                                           int bufferLength)
    • Method Detail

      • read

        public final int read​(byte[] b,
                              int off,
                              int len)
                       throws IOException
        Reads up to len bytes into the provided byte array b. If no remaining unread bytes are available in the internal buffer, refill is called to refill the internal buffer. Otherwise, either len bytes or the number of bytes available in the buffer are read, whichever is smaller. To read from the buffer until either the end of the stream is reached or len bytes have been read, use ByteStreams.read.
        Overrides:
        read in class InputStream
        Throws:
        IOException
      • refill

        protected abstract int refill()
                               throws IOException
        Refills the internal buffer from the delegate InputStream.
        Returns:
        The number of bytes written to the buffer while refilling it.
        Throws:
        IOException