Class ForwardReadableInputStream

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

    public class ForwardReadableInputStream
    extends java.io.InputStream
    InputStream wrapper that allows one to read the first X bytes of an InputStream on non markable streams, and use the wrapped stream as if it wasn't ever read. This class will throw if the wrapped stream does not have enough bytes to read the wanted bytes.

    Calling read() will be passed through the wrapped stream directly.

    IMPORTANT NOTE: This class does NOT forward .close() to the wrapped input stream.

    • Constructor Summary

      Constructors 
      Constructor Description
      ForwardReadableInputStream​(java.io.InputStream is, int bytesToRead)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int[] getFirstBytes()
      Get the first bytes that have already been read
      int read()  
      • Methods inherited from class java.io.InputStream

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

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

      • ForwardReadableInputStream

        public ForwardReadableInputStream​(@NonNull
                                          java.io.InputStream is,
                                          int bytesToRead)
                                   throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • read

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

        public int[] getFirstBytes()
        Get the first bytes that have already been read