Package org.mariadb.jdbc.client.socket
Class ReadAheadBufferedStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- org.mariadb.jdbc.client.socket.ReadAheadBufferedStream
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class ReadAheadBufferedStream extends java.io.FilterInputStream
Permit to buf socket data, reading not only asked bytes, but available number of bytes when possible.
-
-
Constructor Summary
Constructors Constructor Description ReadAheadBufferedStream(java.io.InputStream in)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
void
close()
private void
fillbuf(int minNeededBytes)
Fill buf with required length, or available bytes.boolean
markSupported()
int
read()
Reading one byte from cache of socket if needed.int
read(byte[] externalBuf, int off, int len)
Returing byte array, from cache of reading socket if needed.void
reset()
long
skip(long n)
-
-
-
Field Detail
-
BUF_SIZE
private static final int BUF_SIZE
- See Also:
- Constant Field Values
-
buf
private final byte[] buf
-
end
private int end
-
pos
private int pos
-
-
Method Detail
-
read
public int read() throws java.io.IOException
Reading one byte from cache of socket if needed.- Overrides:
read
in classjava.io.FilterInputStream
- Returns:
- byte value
- Throws:
java.io.IOException
- if socket reading error.
-
read
public int read(byte[] externalBuf, int off, int len) throws java.io.IOException
Returing byte array, from cache of reading socket if needed.- Overrides:
read
in classjava.io.FilterInputStream
- Parameters:
externalBuf
- buf to filloff
- offsetlen
- length to read- Returns:
- number of added bytes
- Throws:
java.io.IOException
- if exception during socket reading
-
fillbuf
private void fillbuf(int minNeededBytes) throws java.io.IOException
Fill buf with required length, or available bytes.- Parameters:
minNeededBytes
- asked number of bytes- Throws:
java.io.IOException
- in case of failing reading stream.
-
skip
public long skip(long n) 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
-
reset
public void reset() throws java.io.IOException
- Overrides:
reset
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
-
markSupported
public boolean markSupported()
- Overrides:
markSupported
in classjava.io.FilterInputStream
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Overrides:
close
in classjava.io.FilterInputStream
- Throws:
java.io.IOException
-
-