java.lang.Object
java.io.InputStream
java.io.FilterInputStream
kala.compress.utils.BoundedInputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
A stream that limits reading from a wrapped stream to a given number of bytes.
- Since:
- 1.6
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate longThe current count of bytes counted.private longThe current mark.private final longThe max count of bytes to read.private final booleanFlag if close should be propagated.Fields inherited from class java.io.FilterInputStream
in -
Constructor Summary
ConstructorsConstructorDescriptionBoundedInputStream(InputStream in, long maxCount) Creates the stream that will at most read the given amount of bytes from the given stream.BoundedInputStream(InputStream in, long maxCount, boolean propagateClose) Creates the stream that will at most read the given amount of bytes from the given stream. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()longReturns the current number of bytes read from this stream.longGets how many bytes remain to read.longGets the max count of bytes to read.voidmark(int readLimit) intread()intread(byte[] b, int off, int len) voidreset()longskip(long n) Methods inherited from class java.io.FilterInputStream
available, markSupported, readMethods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Field Details
-
count
private long countThe current count of bytes counted. -
maxCount
private final long maxCountThe max count of bytes to read. -
propagateClose
private final boolean propagateCloseFlag if close should be propagated. -
mark
private long markThe current mark.
-
-
Constructor Details
-
BoundedInputStream
Creates the stream that will at most read the given amount of bytes from the given stream.- Parameters:
in- the stream to read frommaxCount- the maximum amount of bytes to read
-
BoundedInputStream
Creates the stream that will at most read the given amount of bytes from the given stream.- Parameters:
in- the stream to read frommaxCount- the maximum amount of bytes to readpropagateClose-trueif callingclose()propagates to theclose()method of the underlying stream orfalseif it does not.- Since:
- 1.27.1-0
-
-
Method Details
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterInputStream- Throws:
IOException
-
getBytesRead
public long getBytesRead()Returns the current number of bytes read from this stream.- Returns:
- the number of read bytes
- Since:
- 1.27.1-0
-
getMaxCount
public long getMaxCount()Gets the max count of bytes to read.- Returns:
- The max count of bytes to read.
- Since:
- 1.27.1-0
-
getBytesRemaining
public long getBytesRemaining()Gets how many bytes remain to read.- Returns:
- bytes how many bytes remain to read.
- Since:
- 1.21
-
read
- Overrides:
readin classFilterInputStream- Throws:
IOException
-
read
- Overrides:
readin classFilterInputStream- Throws:
IOException
-
skip
- Overrides:
skipin classFilterInputStream- Throws:
IOException- Since:
- 1.20
-
mark
public void mark(int readLimit) - Overrides:
markin classFilterInputStream- Since:
- 1.27.1-0
-
reset
- Overrides:
resetin classFilterInputStream- Throws:
IOException- Since:
- 1.27.1-0
-