Class LengthRestrictedInputStream

java.lang.Object
java.io.InputStream
net.targetr.wtm3.io.LengthRestrictedInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class LengthRestrictedInputStream extends InputStream
Prevents reading too much from an input stream.

This class simplifies reading a predefined length of data from a stream. Reading will return -1 when the specified length of data has been read, preventing over-reading and corruption of HTTP streams.

Author:
Dr Michael Gardiner
  • Constructor Details

    • LengthRestrictedInputStream

      public LengthRestrictedInputStream(InputStream in, long len)
      Decorates an input stream to limit how much is read from it.
      Parameters:
      in - The input stream to read from.
      len - The maximum number of bytes that should be read.
  • Method Details