Package net.i2p.util

Class LookaheadInputStream

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class LookaheadInputStream
    extends FilterInputStream
    Simple lookahead buffer to keep the last K bytes in reserve, configured to easily be reused. Currently only used by the ResettableGZIPInputStream.
    • Constructor Detail

      • LookaheadInputStream

        public LookaheadInputStream​(int lookaheadSize)
        Configure a stream that hides a number of bytes from the reader. The last n bytes will never be available from read(), they can only be obtained from getFooter(). initialize() MUST be called before doing any read() calls.
        lookaheadSize - how many bytes to hide
    • Method Detail

      • getEOFReached

        public boolean getEOFReached()
      • initialize

        public void initialize​(InputStream src)
                        throws IOException
        Start the LookaheadInputStream with the given input stream. Resets everything if the LookaheadInputStream was previously used. WARNING - blocking until lookaheadSize bytes are read!
        IOException - if less than lookaheadSize bytes could be read.
      • getFooter

        public byte[] getFooter()
        Grab the lookahead footer. This will be of size lookaheadsize given in constructor. The last byte received will be in the last byte of the array.