private static byte[] readRawBytes(ByteBuf buffer) {
    if (buffer.hasArray() && buffer.readableBytes() == buffer.array().length) {
      // Move the readerIndex just so we consistently consume the input
      buffer.readerIndex(buffer.writerIndex());
      return buffer.array();
    }

    // Otherwise, just read the bytes in a new array
    byte[] bytes = new byte[buffer.readableBytes()];
    buffer.readBytes(bytes);
    return bytes;
  }
private static byte [ ] readRawBytes ( ByteBuf buffer ) { if ( buffer . hasArray ( ) && buffer . readableBytes ( ) == buffer . array ( ) . length ) { buffer . readerIndex ( buffer . writerIndex ( ) ) ; return buffer . array ( ) ; } byte [ ] bytes = new byte [ buffer . readableBytes ( ) ] ; buffer . readBytes ( bytes ) ; return bytes ; }
copy.