public static String readString( ByteBuffer data ) throws IOException {
        int length = -1;
        byte type = data.get();
        if (type == (byte)0) {
            return null;
        } else if (type == (byte)1) {
            // Byte
            length = data.get();
        } else if (type == (byte)2) {
            // Short
            length = data.getShort();
        } else if (type == (byte)3) {
            // Int
            length = data.getInt();
        }
        if (length == -1) throw new IOException("Could not read String: Invalid length identifier.");

        byte[] buffer = new byte[length];
        data.get(buffer);
        return new String(buffer, "UTF-8");
    }
String serializer.

@author Lars Wesselius, Paul Speed
jme3-networking/src/main/java/com/jme3/network/serializing/serializers/StringSerializer.java