Package gov.usgs.earthquake.util
Class SizeLimitInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- gov.usgs.earthquake.util.SizeLimitInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class SizeLimitInputStream extends java.io.FilterInputStreamStream that only allows a certain number of bytes to be read. Current implementation only tracks read bytes, and ignores any mark or reset calls.
-
-
Constructor Summary
Constructors Constructor Description SizeLimitInputStream(java.io.InputStream in, long limit)Construct a new SizeLimitInputStream.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckLimit()Check how many bytes have been read.longgetRead()Return number of bytes read.intread()Read one byte.intread(byte[] b)Read into an array of bytes.intread(byte[] b, int off, int len)Read into an array of bytes.-
Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, reset, skip
-
-
-
-
Method Detail
-
getRead
public long getRead()
Return number of bytes read.- Returns:
- bytes read
-
read
public int read() throws java.io.IOExceptionRead one byte.- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
read
public int read(byte[] b) throws java.io.IOExceptionRead into an array of bytes.- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOExceptionRead into an array of bytes.- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
checkLimit
protected void checkLimit() throws java.io.IOExceptionCheck how many bytes have been read.- Throws:
java.io.IOException- if more bytes than the limit allows have been read.
-
-