Package gov.usgs.earthquake.util
Class SizeLimitInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
gov.usgs.earthquake.util.SizeLimitInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
Stream that only allows a certain number of bytes to be read.
Current implementation only tracks read bytes, and ignores any mark or reset
calls.
-
Field Summary
Fields inherited from class java.io.FilterInputStream
in
-
Constructor Summary
ConstructorsConstructorDescriptionSizeLimitInputStream
(InputStream in, long limit) Construct a new SizeLimitInputStream. -
Method Summary
Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, reset, skip
Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
SizeLimitInputStream
Construct a new SizeLimitInputStream.- Parameters:
in
- stream to limit.limit
- maximum number of bytes allowed to read.
-
-
Method Details
-
getRead
public long getRead()Return number of bytes read.- Returns:
- bytes read
-
read
Read one byte.- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
read
Read into an array of bytes.- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
read
Read into an array of bytes.- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
checkLimit
Check how many bytes have been read.- Throws:
IOException
- if more bytes than the limit allows have been read.
-