java.lang.Object
java.io.InputStream
java.io.FilterInputStream
i2p.susi.util.CountingInputStream
i2p.susi.util.LimitInputStream
- All Implemented Interfaces:
ReadCounter, Closeable, AutoCloseable
InputStream that limits total bytes read to a specified maximum.
Field Summary
FieldsFields inherited from class CountingInputStream
countFields inherited from class FilterInputStream
inConstructor Summary
ConstructorsConstructorDescriptionLimitInputStream(InputStream in, long max) Create a LimitInputStream that limits total bytes read.Method Summary
All MethodsModifier and TypeMethodDescriptionintReturn the number of bytes available, limited by the remaining quota.intread()Read a single byte, returning -1 if the limit has been reached.intread(byte[] buf, int off, int len) Read bytes into a buffer, limited by the remaining quota.longskip(long n) Skip bytes, limited by the remaining quota.Methods inherited from class CountingInputStream
getReadModifier and TypeMethodDescriptionlonggetRead()Get the total number of bytes read or skipped so far.Methods inherited from class FilterInputStream
close, mark, markSupported, read, resetMethods inherited from class InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
Field Details
maxx
private final long maxxMost bytes the stream will read.
Constructor Details
LimitInputStream
Create a LimitInputStream that limits total bytes read.- Parameters:
in- the underlying input streammax- the maximum number of bytes that may be read
Method Details
available
Return the number of bytes available, limited by the remaining quota.- Overrides:
availablein classFilterInputStream- Returns:
- the number of readable bytes, capped by the remaining quota
- Throws:
IOException- on I/O error
skip
Skip bytes, limited by the remaining quota.- Overrides:
skipin classCountingInputStream- Parameters:
n- number of bytes to skip- Returns:
- actual bytes skipped
- Throws:
IOException- on I/O error
read
Read a single byte, returning -1 if the limit has been reached.- Overrides:
readin classCountingInputStream- Returns:
- the byte read, or -1 on end of stream or limit reached
- Throws:
IOException- on I/O error
read
Read bytes into a buffer, limited by the remaining quota.- Overrides:
readin classCountingInputStream- Parameters:
buf- the buffer to read intooff- the start offset in the bufferlen- the maximum number of bytes to read- Returns:
- the number of bytes read, or -1 on end of stream or limit reached
- Throws:
IOException- on I/O error