com.mysql.jdbc
Class ChannelBuffer

java.lang.Object
  extended bycom.mysql.jdbc.Buffer
      extended bycom.mysql.jdbc.ChannelBuffer

class ChannelBuffer
extends Buffer

Buffer contains code to read and write packets from/to the MySQL server.


Field Summary
(package private) static int MAX_BYTES_TO_DUMP
           
(package private) static int NO_LENGTH_LIMIT
           
(package private) static long NULL_LENGTH
           
protected  boolean wasMultiPacket
           
 
Constructor Summary
(package private) ChannelBuffer(byte[] buf)
           
(package private) ChannelBuffer(int size, boolean direct)
           
 
Method Summary
static Buffer allocateDirect(int size, boolean useNewIo)
           
static Buffer allocateNew(byte[] buf, boolean useNewIo)
           
static Buffer allocateNew(int size, boolean useNewIo)
           
(package private)  void clear()
           
(package private)  void dump()
           
(package private)  java.lang.String dump(int numBytes)
           
(package private)  java.lang.String dumpClampedBytes(int numBytes)
           
(package private)  void dumpHeader()
           
(package private)  void dumpNBytes(int start, int nBytes)
           
(package private)  void ensureCapacity(int additionalData)
           
 int fastSkipLenString()
          Skip over a length-encoded string
(package private)  int getBufLength()
           
 byte[] getByteBuffer()
          Returns the array of bytes this Buffer is using to read from.
(package private)  byte[] getBytes(int len)
           
(package private)  byte[] getBytes(int offset, int len)
           
(package private)  int getCapacity()
           
 java.nio.ByteBuffer getNioBuffer()
          Returns the Java NIO Buffer (if any)
 int getPosition()
          Returns the current position to write to/ read from
(package private)  boolean isLastDataPacket()
           
(package private)  long newReadLength()
           
(package private)  byte readByte()
           
(package private)  byte readByte(int readAt)
           
(package private)  long readFieldLength()
           
(package private)  int readInt()
           
(package private)  int readIntAsLong()
           
(package private)  byte[] readLenByteArray(int offset)
           
(package private)  long readLength()
           
(package private)  long readLong()
           
(package private)  int readLongInt()
           
(package private)  long readLongLong()
           
(package private)  int readnBytes()
           
(package private)  java.lang.String readString()
           
(package private)  java.lang.String readString(java.lang.String encoding)
           
(package private)  void setBufLength(int bufLengthToSet)
           
 void setByteBuffer(byte[] byteBuffer)
          Sets the array of bytes to use as a buffer to read from.
 void setPosition(int position)
          Set the current position to write to/ read from
 void setWasMultiPacket(boolean flag)
          Sets whether this packet was part of a multipacket
 java.lang.String toString()
           
 java.lang.String toSuperString()
           
 boolean wasMultiPacket()
          Was this packet part of a multipacket?
(package private)  void writeByte(byte b)
           
(package private)  void writeBytesNoNull(byte[] bytes)
           
(package private)  void writeBytesNoNull(byte[] bytes, int offset, int length)
           
(package private)  void writeDouble(double d)
           
(package private)  void writeFieldLength(long length)
           
(package private)  void writeFloat(float f)
           
(package private)  void writeInt(int i)
           
(package private)  void writeLenBytes(byte[] b)
           
(package private)  void writeLenString(java.lang.String s, java.lang.String encoding, java.lang.String serverEncoding, SingleByteCharsetConverter converter, boolean parserKnowsUnicode)
           
(package private)  void writeLong(long i)
           
(package private)  void writeLongInt(int i)
           
(package private)  void writeLongLong(long i)
           
(package private)  void writeString(java.lang.String s)
           
(package private)  void writeStringNoNull(java.lang.String s)
           
(package private)  void writeStringNoNull(java.lang.String s, java.lang.String encoding, java.lang.String serverEncoding, boolean parserKnowsUnicode)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MAX_BYTES_TO_DUMP

static final int MAX_BYTES_TO_DUMP
See Also:
Constant Field Values

NO_LENGTH_LIMIT

static final int NO_LENGTH_LIMIT
See Also:
Constant Field Values

NULL_LENGTH

static final long NULL_LENGTH
See Also:
Constant Field Values

wasMultiPacket

protected boolean wasMultiPacket
Constructor Detail

ChannelBuffer

ChannelBuffer(byte[] buf)

ChannelBuffer

ChannelBuffer(int size,
              boolean direct)
Method Detail

clear

final void clear()
Specified by:
clear in class Buffer

ensureCapacity

final void ensureCapacity(int additionalData)
                   throws java.sql.SQLException
Specified by:
ensureCapacity in class Buffer
Throws:
java.sql.SQLException

fastSkipLenString

public int fastSkipLenString()
Skip over a length-encoded string

Specified by:
fastSkipLenString in class Buffer
Returns:
The position past the end of the string

getBufLength

int getBufLength()
Specified by:
getBufLength in class Buffer

getByteBuffer

public byte[] getByteBuffer()
Returns the array of bytes this Buffer is using to read from.

Specified by:
getByteBuffer in class Buffer
Returns:
byte array being read from

getBytes

final byte[] getBytes(int len)
Specified by:
getBytes in class Buffer

getBytes

byte[] getBytes(int offset,
                int len)
Specified by:
getBytes in class Buffer

getCapacity

int getCapacity()
Specified by:
getCapacity in class Buffer

getNioBuffer

public java.nio.ByteBuffer getNioBuffer()
Description copied from class: Buffer
Returns the Java NIO Buffer (if any)

Specified by:
getNioBuffer in class Buffer

getPosition

public int getPosition()
Returns the current position to write to/ read from

Specified by:
getPosition in class Buffer
Returns:
the current position to write to/ read from

isLastDataPacket

final boolean isLastDataPacket()
Specified by:
isLastDataPacket in class Buffer

newReadLength

final long newReadLength()
Specified by:
newReadLength in class Buffer

readByte

final byte readByte()
Specified by:
readByte in class Buffer

readByte

final byte readByte(int readAt)
Specified by:
readByte in class Buffer

readFieldLength

final long readFieldLength()
Specified by:
readFieldLength in class Buffer

readInt

final int readInt()
Specified by:
readInt in class Buffer

readIntAsLong

final int readIntAsLong()
Specified by:
readIntAsLong in class Buffer

readLenByteArray

final byte[] readLenByteArray(int offset)
Specified by:
readLenByteArray in class Buffer

readLength

final long readLength()
Specified by:
readLength in class Buffer

readLong

final long readLong()
Specified by:
readLong in class Buffer

readLongInt

final int readLongInt()
Specified by:
readLongInt in class Buffer

readLongLong

final long readLongLong()
Specified by:
readLongLong in class Buffer

readnBytes

final int readnBytes()
Specified by:
readnBytes in class Buffer

readString

final java.lang.String readString()
Specified by:
readString in class Buffer

readString

final java.lang.String readString(java.lang.String encoding)
                           throws java.sql.SQLException
Specified by:
readString in class Buffer
Throws:
java.sql.SQLException

setBufLength

void setBufLength(int bufLengthToSet)
Specified by:
setBufLength in class Buffer

setByteBuffer

public void setByteBuffer(byte[] byteBuffer)
Sets the array of bytes to use as a buffer to read from.

Specified by:
setByteBuffer in class Buffer
Parameters:
byteBuffer - the array of bytes to use as a buffer

setPosition

public void setPosition(int position)
Set the current position to write to/ read from

Specified by:
setPosition in class Buffer
Parameters:
position - the position (0-based index)

writeByte

final void writeByte(byte b)
              throws java.sql.SQLException
Specified by:
writeByte in class Buffer
Throws:
java.sql.SQLException

writeBytesNoNull

final void writeBytesNoNull(byte[] bytes)
                     throws java.sql.SQLException
Specified by:
writeBytesNoNull in class Buffer
Throws:
java.sql.SQLException

writeBytesNoNull

final void writeBytesNoNull(byte[] bytes,
                            int offset,
                            int length)
                     throws java.sql.SQLException
Specified by:
writeBytesNoNull in class Buffer
Throws:
java.sql.SQLException

writeDouble

final void writeDouble(double d)
                throws java.sql.SQLException
Specified by:
writeDouble in class Buffer
Throws:
java.sql.SQLException

writeFieldLength

final void writeFieldLength(long length)
                     throws java.sql.SQLException
Specified by:
writeFieldLength in class Buffer
Throws:
java.sql.SQLException

writeFloat

final void writeFloat(float f)
               throws java.sql.SQLException
Specified by:
writeFloat in class Buffer
Throws:
java.sql.SQLException

writeInt

final void writeInt(int i)
             throws java.sql.SQLException
Specified by:
writeInt in class Buffer
Throws:
java.sql.SQLException

writeLenBytes

final void writeLenBytes(byte[] b)
                  throws java.sql.SQLException
Specified by:
writeLenBytes in class Buffer
Throws:
java.sql.SQLException

writeLenString

final void writeLenString(java.lang.String s,
                          java.lang.String encoding,
                          java.lang.String serverEncoding,
                          SingleByteCharsetConverter converter,
                          boolean parserKnowsUnicode)
                   throws java.io.UnsupportedEncodingException,
                          java.sql.SQLException
Specified by:
writeLenString in class Buffer
Throws:
java.io.UnsupportedEncodingException
java.sql.SQLException

writeLong

final void writeLong(long i)
              throws java.sql.SQLException
Specified by:
writeLong in class Buffer
Throws:
java.sql.SQLException

writeLongInt

final void writeLongInt(int i)
                 throws java.sql.SQLException
Specified by:
writeLongInt in class Buffer
Throws:
java.sql.SQLException

writeLongLong

final void writeLongLong(long i)
                  throws java.sql.SQLException
Specified by:
writeLongLong in class Buffer
Throws:
java.sql.SQLException

writeString

final void writeString(java.lang.String s)
                throws java.sql.SQLException
Specified by:
writeString in class Buffer
Throws:
java.sql.SQLException

writeStringNoNull

final void writeStringNoNull(java.lang.String s)
                      throws java.sql.SQLException
Specified by:
writeStringNoNull in class Buffer
Throws:
java.sql.SQLException

writeStringNoNull

final void writeStringNoNull(java.lang.String s,
                             java.lang.String encoding,
                             java.lang.String serverEncoding,
                             boolean parserKnowsUnicode)
                      throws java.io.UnsupportedEncodingException,
                             java.sql.SQLException
Specified by:
writeStringNoNull in class Buffer
Throws:
java.io.UnsupportedEncodingException
java.sql.SQLException

allocateDirect

public static Buffer allocateDirect(int size,
                                    boolean useNewIo)

allocateNew

public static Buffer allocateNew(byte[] buf,
                                 boolean useNewIo)

allocateNew

public static Buffer allocateNew(int size,
                                 boolean useNewIo)

dump

final void dump()

dump

final java.lang.String dump(int numBytes)

dumpClampedBytes

final java.lang.String dumpClampedBytes(int numBytes)

dumpHeader

final void dumpHeader()

dumpNBytes

final void dumpNBytes(int start,
                      int nBytes)

setWasMultiPacket

public void setWasMultiPacket(boolean flag)
Sets whether this packet was part of a multipacket

Parameters:
flag - was this packet part of a multipacket?

toString

public java.lang.String toString()

toSuperString

public java.lang.String toSuperString()

wasMultiPacket

public boolean wasMultiPacket()
Was this packet part of a multipacket?

Returns:
was this packet part of a multipacket?