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.FilterInputStream
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.
-
-
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 void
checkLimit()
Check how many bytes have been read.long
getRead()
Return number of bytes read.int
read()
Read one byte.int
read(byte[] b)
Read into an array of bytes.int
read(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.IOException
Read one byte.- Overrides:
read
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
-
read
public int read(byte[] b) throws java.io.IOException
Read into an array of bytes.- Overrides:
read
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException
Read into an array of bytes.- Overrides:
read
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
-
checkLimit
protected void checkLimit() throws java.io.IOException
Check how many bytes have been read.- Throws:
java.io.IOException
- if more bytes than the limit allows have been read.
-
-