public static String asString(ByteBuffer buffer, int length)
    {
        char[] chars = new char[length];

        for (int i = 0; i < length; i++)
        {
            chars[i] = (char) buffer.get(i);
        }

        return String.valueOf(chars);
    }
public static String asString ( ByteBuffer buffer , int length ) { char [ ] chars = new char [ length ] ; for ( int i = 0 ; i < length ; i ++ ) { chars [ i ] = ( char ) buffer . get ( i ) ; } return String . valueOf ( chars ) ; }
Returns the contents of a buffer as a string, converting ASCII characters in the buffer, into unicode string
characters.

@param  buffer The buffer.
@param  length The length of the string to get from the buffer.

@return The buffer as a string.