|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.continuent.tungsten.common.mysql.MySQLPacket
public class MySQLPacket
A MySQL packet with helper functions to ease the reading and writting of bytes, integers, long integers, strings...
| Field Summary | |
|---|---|
static int |
EOF_SERVER_STATUS_OFFSET
EOF packet server status appears as a short at this offset |
static int |
EOF_WARNING_COUNT_OFFSET
EOF warning count appears as a short starting at this offset |
static int |
ERROR_MESSAGE_OFFSET
ODBC/JDBC SQL state appears as a byte at this offset |
static int |
ERROR_NUMBER_OFFSET
MySQL Errorno appears as a short at this offset |
static int |
ERROR_SQL_STATE_OFFSET
ODBC/JDBC SQL state appears as a byte at this offset |
static int |
HEADER_LENGTH
Length of the packet header |
static int |
MAX_LENGTH
Maximum packet length (16M) |
static int |
PACKET_TYPE_OFFSET
Packet type is a single byte at this offset |
| Constructor Summary | |
|---|---|
MySQLPacket(int size,
byte packetNumber)
Creates a new MySQLPacket object |
|
MySQLPacket(int dataLength,
byte[] buffer,
byte packetNumber)
Creates a new MySQLPacket object |
|
| Method Summary | |
|---|---|
byte |
getByte()
Returns one byte from the buffer. |
byte[] |
getByteBuffer()
Returns the raw byte buffer. |
byte[] |
getBytes(int len)
Returns len bytes from the buffer. |
int |
getDataLength()
Gets the current length of the byteBuffer |
java.sql.Date |
getDate(int length)
Reads a date from stream given its length and returns the corresponding Date |
double |
getDouble()
Returns eight bytes from the buffer as a float |
long |
getFieldLength()
|
float |
getFloat()
Returns four bytes from the buffer as a float |
long |
getHourMinSec()
Reads hours, minutes and seconds from stream and returns the corresponding number of milliseconds |
java.io.InputStream |
getInputStream()
Retrieves the input stream that created this packet |
int |
getInt24()
Returns three consecutive bytes as an integer (MySQL longint) from the buffer. |
int |
getInt32()
Returns four consecutive bytes as an integer (MySQL long) from the buffer. |
byte[] |
getLenEncodedBytes()
Returns a len encoded byte array from the buffer. |
java.lang.String |
getLenEncodedString(boolean stopAtNullChar)
Returns a string from the buffer, where the encoded size is right before the actual string |
long |
getLong()
Returns eight consecutive bytes as a long (MySQL longlong) from the buffer. |
byte |
getPacketNumber()
Returns the packet number. |
int |
getPacketPosition()
Retrieves the current byte buffer cursor position |
int |
getRemainingBytes()
Returns the number of bytes remaining in the buffer |
short |
getShort()
Aka. |
java.lang.String |
getString()
Returns a string from the buffer. |
java.lang.String |
getString(int len)
Returns a len length string from the buffer. |
java.sql.Time |
getTime(int length)
Reads a time from stream given its length and returns the corresponding Time |
short |
getUnsignedByte()
Reads one byte from the buffer considering it as an unsigned value and returns a corresponding short |
int |
getUnsignedInt24()
Returns three consecutive bytes as an integer (MySQL longint) from the buffer considering it as an unsigned. |
long |
getUnsignedInt32()
Returns four consecutive bytes as an integer (MySQL long) from the buffer. |
java.math.BigInteger |
getUnsignedLong()
Returns eight consecutive bytes from the buffer (MySQL longlong) treated as unsigned value into a big integer . |
int |
getUnsignedShort()
Aka. |
boolean |
hasCursor()
Tells whether or not a cursor exists. |
boolean |
hasLastRowSent()
Tells whether the end of a result set has been reached upon COM_STMT_FETCH command |
boolean |
hasMoreResults()
Tells whether or not more results exist on the server. |
boolean |
isEmpty()
Empty packets have a zero size data |
boolean |
isEOF()
Whether or not this packet is a MySQL "EOF" packet |
boolean |
isError()
Whether or not this packet is a MySQL "ERROR" packet |
boolean |
isLargePacket()
Whether or not this packet is a large packet, thus part of a large query or result |
boolean |
isOK()
Whether or not this packet is a MySQL "OK" packet |
boolean |
isServerFlagSet(short flag)
Tests "server status" bytes in a OK or EOF packet to tell whether or not the given flag is set. |
static MySQLPacket |
mysqlReadPacket(java.io.InputStream in,
boolean dropLargePackets)
|
int |
peekEOFServerStatus()
Returns the bit mask for the server status from the MySQL "EOF" packet |
int |
peekEOFWarningCount()
Returns the warning count from the MySQL "EOF" packet |
int |
peekErrorErrno()
Returns the MySQL error number from the MySQL "ERROR" packet without modifying the packet |
java.lang.String |
peekErrorErrorMessage()
Returns the MySQL error message from the MySQL "ERROR" packet without modifying the packet |
int |
peekErrorSQLState()
Returns the MySQL error number from the MySQL "ERROR" packet without modifying the packet |
long |
peekFieldCount()
|
java.lang.String |
peekString(int offset,
int len)
Returns a len length string from the buffer. |
java.lang.String |
peekStringAtOffset(int startPosition)
Returns a string from the buffer. |
void |
preparePacketForStreaming()
When streaming a packet, some data has possibly been already read in it. |
void |
putByte(byte b)
Put a byte in the buffer. |
void |
putBytes(byte[] bytes)
Put an array of bytes in the buffer. |
long |
putDate(java.sql.Date d)
Puts a Date to the buffer as:two bytes year one byte month one byte day |
void |
putDouble(double d)
Puts a double in the buffer |
void |
putFieldLength(long length)
Put a long as a len encoded value in the buffer. |
void |
putFloat(float f)
Puts a float in the buffer |
long |
putHourMinSec(long millis)
Converts a time in millis to hours, minutes and seconds and put it in the buffer |
void |
putInt16(int i)
Put an integer in the buffer. |
void |
putInt24(int i)
Put an integer (MySQL longint) in the buffer |
void |
putInt32(int i)
Put an integer (MySQL long) in the buffer. |
void |
putLenBytes(byte[] bytes)
Put a byte array as a len encoded bytes in the buffer. |
void |
putLenString(java.lang.String s)
Put a string as a len encoded bytes in the buffer. |
void |
putLong(long i)
Put a long (MySQL longlong) in the buffer. |
void |
putString(java.lang.String s)
Put a string in the buffer. |
void |
putStringNoNull(java.lang.String s)
Put a string in the buffer. |
void |
putTime(java.sql.Time t)
Puts a jdbc Time in the buffer as:Send sign (0 for > EPOCH, 1 for < EPOCH) Then day (always zero for a time) Finally Hour Minutes and Seconds using putHourMinSec(long)Note that MySQL jdbc driver doesn't care about days and millis, so it is most probably unnecessary to send them... |
void |
putUnsignedInt32(long i)
Put an unsigned integer (MySQL long) in the buffer. |
long |
readFieldLength()
Returns the len encoded value as a long from buffer. |
static MySQLPacket |
readPacket(java.io.InputStream in)
Reads a MySQL packet from the input stream using a default partial read timeout of 5 seconds. |
static MySQLPacket |
readPacket(java.io.InputStream in,
boolean dropLargePackets)
Reads a MySQL packet from the input stream. |
static MySQLPacket |
readPacket(java.io.InputStream in,
long timeoutMillis)
Reads a MySQL packet from the input stream. |
void |
readRemainingPackets()
Provided this packet is a large packet > 16M, reads the remaining packets and and adds their data to this packet data. |
void |
reset()
Rewinds data buffer pointer to the first data byte. |
void |
setInputStream(java.io.InputStream inputStream)
Retain creation input stream for further re-reads |
void |
setPacketPosition(int pos)
Changes the byte buffer cursor position |
java.lang.String |
toString()
|
void |
write(java.io.OutputStream out)
Write out the content of the buffer to the output stream. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int HEADER_LENGTH
public static final int MAX_LENGTH
public static final int PACKET_TYPE_OFFSET
public static final int EOF_WARNING_COUNT_OFFSET
public static final int EOF_SERVER_STATUS_OFFSET
public static final int ERROR_NUMBER_OFFSET
public static final int ERROR_SQL_STATE_OFFSET
public static final int ERROR_MESSAGE_OFFSET
| Constructor Detail |
|---|
public MySQLPacket(int dataLength,
byte[] buffer,
byte packetNumber)
MySQLPacket object
buffer - the bufferpacketNumber - the packet number
public MySQLPacket(int size,
byte packetNumber)
MySQLPacket object
size - the size of the bufferpacketNumber - the packet number| Method Detail |
|---|
public static MySQLPacket readPacket(java.io.InputStream in,
boolean dropLargePackets)
in - the data input stream from where we read the MySQL packetdropLargePackets - whether or not to return null when a packet of
16Mb is read
public static MySQLPacket mysqlReadPacket(java.io.InputStream in,
boolean dropLargePackets)
throws java.io.IOException,
java.io.EOFException
java.io.IOException
java.io.EOFException
public static MySQLPacket readPacket(java.io.InputStream in,
long timeoutMillis)
in - the data input stream from where we read the MySQL packettimeoutMillis - Number of milliseconds we will pause while waiting
for data from the the network during a packet.
public static MySQLPacket readPacket(java.io.InputStream in)
in - the data input stream from where we read the MySQL packet
public byte[] getByteBuffer()
public byte getPacketNumber()
public int getDataLength()
public boolean isLargePacket()
public boolean isEmpty()
public int getPacketPosition()
public void setPacketPosition(int pos)
pos - the new positionpublic int peekErrorErrno()
public int peekErrorSQLState()
public java.lang.String peekErrorErrorMessage()
public int peekEOFServerStatus()
public int peekEOFWarningCount()
public void preparePacketForStreaming()
public boolean isOK()
public boolean isError()
public boolean isEOF()
public boolean isServerFlagSet(short flag)
public boolean hasMoreResults()
public boolean hasCursor()
public boolean hasLastRowSent()
public long peekFieldCount()
public int getRemainingBytes()
public byte getByte()
public short getUnsignedByte()
public byte[] getBytes(int len)
len - the number of bytes to return
public int getUnsignedShort()
public short getShort()
public byte[] getLenEncodedBytes()
public int getInt32()
public long getUnsignedInt32()
public int getUnsignedInt24()
public int getInt24()
public long getLong()
public java.math.BigInteger getUnsignedLong()
public float getFloat()
public double getDouble()
public java.lang.String getString()
public java.lang.String peekStringAtOffset(int startPosition)
public java.lang.String peekString(int offset,
int len)
len - the length of the string
public java.lang.String getString(int len)
len - the length of the string
public java.lang.String getLenEncodedString(boolean stopAtNullChar)
stopAtNullChar - whether or not to consider the string ends with the
null character. When false, the string length will always be
the decoded length
public java.sql.Time getTime(int length)
Time
length - size of the time data
public long getHourMinSec()
public java.sql.Date getDate(int length)
Date
length - size of the date data
public void putByte(byte b)
b - the byte to put in the bufferpublic void putBytes(byte[] bytes)
bytes - the byte arraypublic void putFieldLength(long length)
length - the value to put in the bufferpublic long getFieldLength()
public void putInt16(int i)
i - the integer to put in the bufferpublic void putLenBytes(byte[] bytes)
bytes - the byte array to put in the bufferpublic void putLenString(java.lang.String s)
s - the string to put in the bufferpublic void putInt32(int i)
i - the value to put in the bufferpublic void putUnsignedInt32(long i)
i - the value to put in the bufferpublic void putInt24(int i)
i - the value to put in the bufferpublic void putLong(long i)
i - the value to put in the bufferpublic void putFloat(float f)
public void putDouble(double d)
public void putString(java.lang.String s)
s - the value to put in the bufferpublic void putStringNoNull(java.lang.String s)
s - the value to put in the bufferpublic long putHourMinSec(long millis)
millis - milliseconds since EPOCH
public void putTime(java.sql.Time t)
Time in the buffer as:putHourMinSec(long)
t - the Time object to writepublic long putDate(java.sql.Date d)
Date to the buffer as:
d - jdbc date to write
public void reset()
public void write(java.io.OutputStream out)
throws java.io.IOException
out - the output stream
java.io.IOException - if an error happens when writting to the output
streampublic long readFieldLength()
public java.io.InputStream getInputStream()
public void setInputStream(java.io.InputStream inputStream)
inputStream - the input stream that created this packetpublic void readRemainingPackets()
public java.lang.String toString()
toString in class java.lang.Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||