Package net.targetr.wtm3.io
Class LengthRestrictedInputStream
java.lang.Object
java.io.InputStream
net.targetr.wtm3.io.LengthRestrictedInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
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 Summary
ConstructorsConstructorDescriptionLengthRestrictedInputStream
(InputStream in, long len) Decorates an input stream to limit how much is read from it. -
Method Summary
Methods inherited from class java.io.InputStream
available, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
-
Constructor Details
-
LengthRestrictedInputStream
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
-
read
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classInputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
isFinished
public boolean isFinished()
-