public static byte[] packByteBufferIntoSingleByteArray(byte[][] byteBufferArr){
  if (null == byteBufferArr || byteBufferArr.length == 0) {
    return null;
  }
  int noOfCol=byteBufferArr.length;
  short toDetermineLengthOfByteArr=2;
  short offsetLen=(short)(noOfCol * 2 + toDetermineLengthOfByteArr);
  int totalBytes=calculateTotalBytes(byteBufferArr) + offsetLen;
  ByteBuffer buffer=ByteBuffer.allocate(totalBytes);
  buffer.putShort((short)(totalBytes - toDetermineLengthOfByteArr));
  buffer.putShort(offsetLen);
  for (int index=0; index < byteBufferArr.length - 1; index++) {
    int noOfBytes=byteBufferArr[index].length;
    buffer.putShort((short)(offsetLen + noOfBytes));
    offsetLen+=noOfBytes;
  }
  for (int index=0; index < byteBufferArr.length; index++) {
    buffer.put(byteBufferArr[index]);
  }
  buffer.rewind();
  return buffer.array();
}

public static byte [ ] packByteBufferIntoSingleByteArray ( byte [ ] [ ] byteBufferArr ) { if ( null == byteBufferArr || byteBufferArr . length == 0 ) { return null ; } int noOfCol = byteBufferArr . length ; short toDetermineLengthOfByteArr = 2 ; short offsetLen = ( short ) ( noOfCol * 2 + toDetermineLengthOfByteArr ) ; int totalBytes = calculateTotalBytes ( byteBufferArr ) + offsetLen ; ByteBuffer buffer = ByteBuffer . allocate ( totalBytes ) ; buffer . putShort ( ( short ) ( totalBytes - toDetermineLengthOfByteArr ) ) ; buffer . putShort ( offsetLen ) ; for ( int index = 0 ; index < byteBufferArr . length - 1 ; index ++ ) { int noOfBytes = byteBufferArr [ index ] . length ; buffer . putShort ( ( short ) ( offsetLen + noOfBytes ) ) ; offsetLen += noOfBytes ; } for ( int index = 0 ; index < byteBufferArr . length ; index ++ ) { buffer . put ( byteBufferArr [ index ] ) ; } buffer . rewind ( ) ; return buffer . array ( ) ; }
this method will form one single byte [ ] for all the high card dims . for example if you need to pack 2 columns c1 and c2 , it stores in following way < total_len ( short ) > < offsetlen ( short ) > < offsetlen + c1_len ( short ) > < c1 ( byte [ ] ) > < c2 ( byte [ ] ) >
