- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- kala.compress.utils.BoundedInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public class BoundedInputStream extends java.io.FilterInputStreamA stream that limits reading from a wrapped stream to a given number of bytes.- Since:
- 1.6
-
-
Field Summary
Fields Modifier and Type Field Description private longcountThe current count of bytes counted.private longmarkThe current mark.private longmaxCountThe max count of bytes to read.private booleanpropagateCloseFlag if close should be propagated.
-
Constructor Summary
Constructors Constructor Description BoundedInputStream(java.io.InputStream in, long maxCount)Creates the stream that will at most read the given amount of bytes from the given stream.BoundedInputStream(java.io.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()longgetBytesRead()Returns the current number of bytes read from this stream.longgetBytesRemaining()Gets how many bytes remain to read.longgetMaxCount()Gets the max count of bytes to read.voidmark(int readLimit)intread()intread(byte[] b, int off, int len)voidreset()longskip(long n)
-
-
-
Constructor Detail
-
BoundedInputStream
public BoundedInputStream(java.io.InputStream in, long maxCount)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
public BoundedInputStream(java.io.InputStream in, long maxCount, boolean propagateClose)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 Detail
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.FilterInputStream- Throws:
java.io.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
public int read() throws java.io.IOException- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
skip
public long skip(long n) throws java.io.IOException- Overrides:
skipin classjava.io.FilterInputStream- Throws:
java.io.IOException- Since:
- 1.20
-
mark
public void mark(int readLimit)
- Overrides:
markin classjava.io.FilterInputStream- Since:
- 1.27.1-0
-
reset
public void reset() throws java.io.IOException- Overrides:
resetin classjava.io.FilterInputStream- Throws:
java.io.IOException- Since:
- 1.27.1-0
-
-