Class ByteArrayInputStream
- java.lang.Object
-
- java.io.InputStream
-
- com.github.shyiko.mysql.binlog.io.ByteArrayInputStream
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class ByteArrayInputStream extends InputStream
- Author:
- Stanley Shyiko
-
-
Constructor Summary
Constructors Constructor Description ByteArrayInputStream(byte[] bytes)
ByteArrayInputStream(InputStream inputStream)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
void
close()
void
enterBlock(int length)
long
fastSkip(long n)
This method implements fast-forward skipping in the stream.void
fill(byte[] bytes, int offset, int length)
int
getPosition()
void
mark(int readlimit)
boolean
markSupported()
int
peek()
int
read()
int
read(byte[] b, int off, int len)
byte[]
read(int length)
BitSet
readBitSet(int length, boolean bigEndian)
int
readInteger(int length)
Read int written in little-endian format.String
readLengthEncodedString()
Read variable-length string.long
readLong(int length)
Read long written in little-endian format.int
readPackedInteger()
long
readPackedLong()
Number
readPackedNumber()
Format (first-byte-based):
0-250 - The first byte is the number (in the range 0-250).String
readString(int length)
Read fixed length string.String
readZeroTerminatedString()
Read variable-length string.void
reset()
void
skipToTheEndOfTheBlock()
-
Methods inherited from class java.io.InputStream
nullInputStream, read, readAllBytes, readNBytes, readNBytes, skip, transferTo
-
-
-
-
Constructor Detail
-
ByteArrayInputStream
public ByteArrayInputStream(InputStream inputStream)
-
ByteArrayInputStream
public ByteArrayInputStream(byte[] bytes)
-
-
Method Detail
-
readInteger
public int readInteger(int length) throws IOException
Read int written in little-endian format.- Parameters:
length
- length of the integer to read- Returns:
- the integer from the binlog
- Throws:
IOException
- in case of EOF
-
readLong
public long readLong(int length) throws IOException
Read long written in little-endian format.- Parameters:
length
- length of the long to read- Returns:
- the long from the binlog
- Throws:
IOException
- in case of EOF
-
readString
public String readString(int length) throws IOException
Read fixed length string.- Parameters:
length
- length of string to read- Returns:
- string
- Throws:
IOException
- in case of EOF
-
readLengthEncodedString
public String readLengthEncodedString() throws IOException
Read variable-length string. Preceding packed integer indicates the length of the string.- Returns:
- string
- Throws:
IOException
- in case of EOF
-
readZeroTerminatedString
public String readZeroTerminatedString() throws IOException
Read variable-length string. End is indicated by 0x00 byte.- Returns:
- string
- Throws:
IOException
- in case of EOF
-
read
public byte[] read(int length) throws IOException
- Throws:
IOException
-
fill
public void fill(byte[] bytes, int offset, int length) throws IOException
- Throws:
IOException
-
readBitSet
public BitSet readBitSet(int length, boolean bigEndian) throws IOException
- Throws:
IOException
-
readPackedInteger
public int readPackedInteger() throws IOException
- Returns:
- integer
- Throws:
IOException
- in case of malformed number, eof, null, or long- See Also:
readPackedNumber()
-
readPackedLong
public long readPackedLong() throws IOException
- Returns:
- long
- Throws:
IOException
- in case of malformed number, eof, null- See Also:
readPackedNumber()
-
readPackedNumber
public Number readPackedNumber() throws IOException
Format (first-byte-based):
0-250 - The first byte is the number (in the range 0-250). No additional bytes are used.
251 - SQL NULL value
252 - Two more bytes are used. The number is in the range 251-0xffff.
253 - Three more bytes are used. The number is in the range 0xffff-0xffffff.
254 - Eight more bytes are used. The number is in the range 0xffffff-0xffffffffffffffff.- Returns:
- long or null
- Throws:
IOException
- in case of malformed number or EOF
-
available
public int available() throws IOException
- Overrides:
available
in classInputStream
- Throws:
IOException
-
peek
public int peek() throws IOException
- Throws:
IOException
-
read
public int read() throws IOException
- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
public int read(byte[] b, int off, int len) throws IOException
- Overrides:
read
in classInputStream
- Throws:
IOException
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
enterBlock
public void enterBlock(int length)
-
skipToTheEndOfTheBlock
public void skipToTheEndOfTheBlock() throws IOException
- Throws:
IOException
-
getPosition
public int getPosition()
-
mark
public void mark(int readlimit)
- Overrides:
mark
in classInputStream
-
markSupported
public boolean markSupported()
- Overrides:
markSupported
in classInputStream
-
reset
public void reset() throws IOException
- Overrides:
reset
in classInputStream
- Throws:
IOException
-
fastSkip
public long fastSkip(long n) throws IOException
This method implements fast-forward skipping in the stream. It can be used if and only if the underlying stream is fully available till its end. In other cases the regularInputStream.skip(long)
method must be used.- Parameters:
n
- - number of bytes to skip- Returns:
- number of bytes skipped
- Throws:
IOException
-
-