class AkServerUtil {

    static String decodeString(ByteBuffer buffer, String charset) {
        if (buffer == null) {
            return null;
        }
        if (charset == null) {
            throw new IllegalArgumentException("charset");
        }
        // Note: String(.., Charset) has *very* different behavior than String(.., "charset")
        // Think carefully, and read the String docs, before changing.
        try {
            return new String(buffer.array(), buffer.position(), buffer.limit() - buffer.position(), charset);
        } catch(UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }

}