Class LimitInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- org.apache.derby.iapi.services.io.LimitInputStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,Limit
- Direct Known Subclasses:
RawToBinaryFormatStream
public class LimitInputStream extends java.io.FilterInputStream implements Limit
An abstract InputStream that provides abstract methods to limit the range that can be read from the stream.
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
limitInPlace
protected int
remainingBytes
-
Constructor Summary
Constructors Constructor Description LimitInputStream(java.io.InputStream in)
Construct a LimitInputStream and call the clearLimit() method.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
int
clearLimit()
Clear any limit set by setLimit.boolean
markSupported()
This stream doesn't support mark/reset, independent of whether the underlying stream does so or not.int
read()
int
read(byte[] b, int off, int len)
void
setInput(java.io.InputStream in)
void
setLimit(int length)
Set the limit of the stream that can be read.long
skip(long count)
-
-
-
Method Detail
-
read
public int read() throws java.io.IOException
- Overrides:
read
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException
- Overrides:
read
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
-
skip
public long skip(long count) throws java.io.IOException
- Overrides:
skip
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
-
available
public int available() throws java.io.IOException
- Overrides:
available
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
-
setLimit
public void setLimit(int length)
Set the limit of the stream that can be read. After this call up to and including length bytes can be read from or skipped in the stream. Any attempt to read more than length bytes will result in an EOFException
-
clearLimit
public int clearLimit()
Clear any limit set by setLimit. After this call no limit checking will be made on any read until a setLimit()) call is made.- Specified by:
clearLimit
in interfaceLimit
- Returns:
- the number of bytes within the limit that have not been read. -1 if no limit was set.
-
setInput
public void setInput(java.io.InputStream in)
-
markSupported
public boolean markSupported()
This stream doesn't support mark/reset, independent of whether the underlying stream does so or not.The reason for not supporting mark/reset, is that it is hard to combine with the limit functionality without always keeping track of the number of bytes read.
- Overrides:
markSupported
in classjava.io.FilterInputStream
- Returns:
false
-
-