code: public static byte[] toBytes(ByteBuffer bb) {
      int length = bb.limit();
      byte [] result = new byte[length];
      System.arraycopy(bb.array(), bb.arrayOffset(), result, 0, length);
      return result;
    }
docs: Returns a new byte array, copied from the passed ByteBuffer.
  @param bb A ByteBuffer
  @return the byte array