Class LimitedInputStream

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

    public class LimitedInputStream
    extends java.io.InputStream
    A filtering InputStream for proper handling of the Content-Length header: It guarantees to return at most a given number of bytes.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private long available  
      private java.io.InputStream in  
      private long markedAvailable  
    • Constructor Summary

      Constructors 
      Constructor Description
      LimitedInputStream​(java.io.InputStream pIn, int pAvailable)
      Creates a new instance, reading from the given input stream and returning at most the given number of bytes.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void mark​(int readlimit)  
      boolean markSupported()  
      int read()  
      int read​(byte[] b, int off, int len)  
      void reset()  
      long skip​(long n)  
      • Methods inherited from class java.io.InputStream

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

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

      • available

        private long available
      • markedAvailable

        private long markedAvailable
      • in

        private java.io.InputStream in
    • Constructor Detail

      • LimitedInputStream

        public LimitedInputStream​(java.io.InputStream pIn,
                                  int pAvailable)
        Creates a new instance, reading from the given input stream and returning at most the given number of bytes.
        Parameters:
        pIn - Input stream being read.
        pAvailable - Number of bytes available in pIn.
    • Method Detail

      • read

        public int read()
                 throws java.io.IOException
        Specified by:
        read 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
      • skip

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

        public void mark​(int readlimit)
        Overrides:
        mark in class java.io.InputStream
      • reset

        public void reset()
                   throws java.io.IOException
        Overrides:
        reset in class java.io.InputStream
        Throws:
        java.io.IOException
      • markSupported

        public boolean markSupported()
        Overrides:
        markSupported in class java.io.InputStream