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 protectedConfinedInputStream(java.io.InputStream in)protectedConfinedInputStream(java.io.InputStream in, int lim) -
Method Summary
Modifier and Type Method Description intavailable()Returns the number of bytes not yet consumed.voidclose()Closes this stream and throws away any bytes not consumed from the underlyingInputStream.protected longdumpLeftovers()Skips the number bytes not yet consumed from the underlyingInputStream.intread()intread(byte[] b)Forwards the read toread(byte[], int, int).intread(byte[] b, int off, int len)Reads bytes from the underlyingInputStreamup to the number of bytes defined in thisConfinedInputStreamlimit.intresetLimit(int len)Resets thisConfinedInputStreamlimit 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:
availablein 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:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.FilterInputStream- Throws:
java.io.IOException- See Also:
FilterInputStream.close()
-
read
public int read() throws java.io.IOException- Overrides:
readin 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:
readin 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 underlyingInputStreamup to the number of bytes defined in thisConfinedInputStreamlimit.- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException- See Also:
FilterInputStream.read(byte[], int, int)
-
resetLimit
public int resetLimit(int len)Resets thisConfinedInputStreamlimit 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.
-