static String decodeString ( ByteBuf in ) throws UnsupportedEncodingException { if ( in . readableBytes ( ) < 2 ) { return null ; } //int strLen = Utils.readWord(in); int strLen = in . readUnsignedShort ( ) ; if ( in . readableBytes ( ) < strLen ) { return null ; } byte [ ] strRaw = new byte [ strLen ] ; in . readBytes ( strRaw ) ; return new String ( strRaw , "UTF-8" ) ; }
Load a string from the given buffer reading first the two bytes of len and then the UTF - 8 bytes of the string .