Package com.mysql.cj.protocol.x
Class ConfinedInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
com.mysql.cj.protocol.x.ConfinedInputStream
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class ConfinedInputStream
extends java.io.FilterInputStream
An
InputStream
wrapper that limits the number of bytes that can be read form the underlying InputStream
.-
Field Summary
-
Constructor Summary
Constructors Modifier Constructor Description protected
ConfinedInputStream(java.io.InputStream in)
protected
ConfinedInputStream(java.io.InputStream in, int lim)
-
Method Summary
Modifier and Type Method Description int
available()
Returns the number of bytes not yet consumed.void
close()
Closes this stream and throws away any bytes not consumed from the underlyingInputStream
.protected long
dumpLeftovers()
Skips the number bytes not yet consumed from the underlyingInputStream
.int
read()
int
read(byte[] b)
Forwards the read toread(byte[], int, int)
.int
read(byte[] b, int off, int len)
Reads bytes from the underlyingInputStream
up to the number of bytes defined in thisConfinedInputStream
limit.int
resetLimit(int len)
Resets thisConfinedInputStream
limit so that it can be reused over the same underlyingInputStream
.
-
Constructor Details
-
ConfinedInputStream
protected ConfinedInputStream(java.io.InputStream in) -
ConfinedInputStream
protected ConfinedInputStream(java.io.InputStream in, int lim)
-
-
Method Details
-
available
public int available() throws java.io.IOExceptionReturns the number of bytes not yet consumed. Note that this method doen't care about the exact number of bytes that may or may not be available in the underlyingInputStream
- Overrides:
available
in classjava.io.FilterInputStream
- Returns:
- the number of bytes available.
- Throws:
java.io.IOException
- See Also:
FilterInputStream.available()
-
close
public void close() throws java.io.IOExceptionCloses this stream and throws away any bytes not consumed from the underlyingInputStream
.- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
- See Also:
FilterInputStream.close()
-
read
public int read() throws java.io.IOException- Overrides:
read
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
- See Also:
FilterInputStream.read()
-
read
public int read(byte[] b) throws java.io.IOExceptionForwards the read toread(byte[], int, int)
.- Overrides:
read
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
- See Also:
FilterInputStream.read(byte[])
-
read
public int read(byte[] b, int off, int len) throws java.io.IOExceptionReads bytes from the underlyingInputStream
up to the number of bytes defined in thisConfinedInputStream
limit.- Overrides:
read
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
- See Also:
FilterInputStream.read(byte[], int, int)
-
resetLimit
public int resetLimit(int len)Resets thisConfinedInputStream
limit so that it can be reused over the same underlyingInputStream
.- Parameters:
len
- the new length to set.- Returns:
- the number of bytes not consumed before reseting the limit.
-
dumpLeftovers
protected long dumpLeftovers() throws java.io.IOExceptionSkips the number bytes not yet consumed from the underlyingInputStream
.- Returns:
- the number of bytes skipped.
- Throws:
java.io.IOException
- if any of the underlying I/O operations fail.
-