public static byte [ ] byteBufToArray ( ByteBuf byteBuf ) { int length = byteBuf . readableBytes ( ) ; byte [ ] byteArray = new byte [ length ] ; byteBuf . getBytes ( byteBuf . readerIndex ( ) , byteArray ) ; return byteArray ; }
Gets the content of the provided ByteBuf as a byte array . This method will create a new byte array even if the ByteBuf can have optionally backing array .