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 intavailable()voidclose()voidenterBlock(int length)longfastSkip(long n)This method implements fast-forward skipping in the stream.voidfill(byte[] bytes, int offset, int length)intgetPosition()voidmark(int readlimit)booleanmarkSupported()intpeek()intread()byte[]read(int length)BitSetreadBitSet(int length, boolean bigEndian)intreadInteger(int length)Read int written in little-endian format.StringreadLengthEncodedString()Read variable-length string.longreadLong(int length)Read long written in little-endian format.intreadPackedInteger()NumberreadPackedNumber()Format (first-byte-based):
0-250 - The first byte is the number (in the range 0-250).StringreadString(int length)Read fixed length string.StringreadZeroTerminatedString()Read variable-length string.voidreset()voidskipToTheEndOfTheBlock()-
Methods inherited from class java.io.InputStream
nullInputStream, read, 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 IOExceptionRead 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 IOExceptionRead 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()
-
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:
availablein classInputStream- Throws:
IOException
-
peek
public int peek() throws IOException- Throws:
IOException
-
read
public int read() throws IOException- Specified by:
readin classInputStream- Throws:
IOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein 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:
markin classInputStream
-
markSupported
public boolean markSupported()
- Overrides:
markSupportedin classInputStream
-
reset
public void reset() throws IOException- Overrides:
resetin classInputStream- Throws:
IOException
-
fastSkip
public long fastSkip(long n) throws IOExceptionThis 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
-
-