Class SkipShieldingInputStream

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

    public class SkipShieldingInputStream
    extends java.io.FilterInputStream
    A wrapper that overwrites skip(long) and delegates to FilterInputStream.read() instead.

    Some implementations of InputStream implement InputStream.skip(long) in a way that throws an exception if the stream is not seekable - System.in is known to behave that way. For such a stream it is impossible to invoke skip at all and you have to read from the stream (and discard the data read) instead. Skipping is potentially much faster than reading so we do want to invoke skip when possible. We provide this class so you can wrap your own InputStream in it if you encounter problems with skip throwing an excpetion.

    Since:
    1.17
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static byte[] SKIP_BUFFER  
      private static int SKIP_BUFFER_SIZE  
      • Fields inherited from class java.io.FilterInputStream

        in
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long skip​(long n)  
      • Methods inherited from class java.io.FilterInputStream

        available, close, mark, markSupported, read, read, read, reset
      • Methods inherited from class java.io.InputStream

        nullInputStream, readAllBytes, readNBytes, readNBytes, transferTo
      • Methods inherited from class java.lang.Object

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

      • SKIP_BUFFER

        private static final byte[] SKIP_BUFFER
    • Constructor Detail

      • SkipShieldingInputStream

        public SkipShieldingInputStream​(java.io.InputStream in)
    • Method Detail

      • skip

        public long skip​(long n)
                  throws java.io.IOException
        Overrides:
        skip in class java.io.FilterInputStream
        Throws:
        java.io.IOException