public void readRemainingPackets(){
  if (getDataLength() != MAX_LENGTH) {
    logger.error("readRemainingPackets() is only relevant for large packets!");
    return;
  }
  ArrayList<MySQLPacket> nextPackets=new ArrayList<MySQLPacket>();
  MySQLPacket nextPacket=readPacket(getInputStream());
  while (nextPacket.getDataLength() == MAX_LENGTH) {
    nextPackets.add(nextPacket);
    nextPacket=readPacket(getInputStream());
  }
  nextPackets.add(nextPacket);
  int newSize=getDataLength();
  for (  MySQLPacket packet : nextPackets) {
    newSize+=packet.getDataLength();
  }
  byte[] newBytes=new byte[newSize + HEADER_LENGTH];
  System.arraycopy(byteBuffer,0,newBytes,0,getDataLength() + HEADER_LENGTH);
  int cursor=getDataLength() + HEADER_LENGTH;
  for (  MySQLPacket packet : nextPackets) {
    System.arraycopy(packet.getByteBuffer(),HEADER_LENGTH,newBytes,cursor,packet.getDataLength());
    cursor+=packet.getDataLength();
  }
  byteBuffer=newBytes;
  dataLength=newSize;
}

public void readRemainingPackets ( ) { if ( getDataLength ( ) != MAX_LENGTH ) { logger . error ( "readRemainingPackets() is only relevant for large packets!" ) ; return ; } ArrayList < MySQLPacket > nextPackets = new ArrayList < MySQLPacket > ( ) ; MySQLPacket nextPacket = readPacket ( getInputStream ( ) ) ; while ( nextPacket . getDataLength ( ) == MAX_LENGTH ) { nextPackets . add ( nextPacket ) ; nextPacket = readPacket ( getInputStream ( ) ) ; } nextPackets . add ( nextPacket ) ; int newSize = getDataLength ( ) ; for ( MySQLPacket packet : nextPackets ) { newSize += packet . getDataLength ( ) ; } byte [ ] newBytes = new byte [ newSize + HEADER_LENGTH ] ; System . arraycopy ( byteBuffer , 0 , newBytes , 0 , getDataLength ( ) + HEADER_LENGTH ) ; int cursor = getDataLength ( ) + HEADER_LENGTH ; for ( MySQLPacket packet : nextPackets ) { System . arraycopy ( packet . getByteBuffer ( ) , HEADER_LENGTH , newBytes , cursor , packet . getDataLength ( ) ) ; cursor += packet . getDataLength ( ) ; } byteBuffer = newBytes ; dataLength = newSize ; }
provided this packet is a large packet > 16m , reads the remaining packets and and adds their data to this packet data . the result will consist in one large packet with all data in . note that the new packet ' s header will be invalid
