Package io.pravega.common.io
Class BoundedInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- io.pravega.common.io.BoundedInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
@NotThreadSafe public class BoundedInputStream extends java.io.FilterInputStreamA wrapper for an InputStream that allows reading up to a specified number of bytes.
-
-
Constructor Summary
Constructors Constructor Description BoundedInputStream(java.io.InputStream inputStream, int bound)Creates a new instance of the BoundedInputStream class.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()voidclose()intgetBound()intgetRemaining()intread()intread(byte[] buffer, int offset, int length)longskip(long count)BoundedInputStreamsubStream(int bound)Creates a new BoundedInputStream wrapping the same InputStream as this one, starting at the current position, with the given bound.
-
-
-
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
-
read
public int read() throws java.io.IOException- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
read
public int read(byte[] buffer, int offset, int length) throws java.io.IOException- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
skip
public long skip(long count) throws java.io.IOException- Overrides:
skipin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
available
public int available() throws java.io.IOException- Overrides:
availablein classjava.io.FilterInputStream- Throws:
java.io.IOException
-
subStream
public BoundedInputStream subStream(int bound)
Creates a new BoundedInputStream wrapping the same InputStream as this one, starting at the current position, with the given bound. NOTE: both this instance and the result of this method should not be both used at the same time to read from the InputStream. When this method returns, this instance's remaining count will be reduced by the given bound (that's since upon closing, the BoundedInputStream will auto-advance to its bound position).- Parameters:
bound- The bound of the sub-stream.- Returns:
- A new instance of a BoundedInputStream.
-
getBound
public int getBound()
-
getRemaining
public int getRemaining()
-
-