Java ByteBuffer to UTF readUTF8(ByteBuffer buf)

Here you can find the source of readUTF8(ByteBuffer buf)

Description

read UTF

License

Apache License

Declaration

public static String readUTF8(ByteBuffer buf) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;

public class Main {
    public static String readUTF8(ByteBuffer buf) {
        short len = buf.getShort();
        byte[] str = new byte[len];
        buf.get(str);//from  w  w w  .j a va 2  s .  com
        String res = null;
        try {
            res = new String(str, "UTF-8");
        } catch (UnsupportedEncodingException ex) {
            res = "";
        }
        return res;
    }
}

Related

  1. readUTF(ByteBuffer bb)
  2. readUTFString(MappedByteBuffer mmap)
  3. toUtf8CharBuffer(ByteBuffer buffer)
  4. toUtf8String(ByteBuffer buffer)
  5. toUTF8String(ByteBuffer buffer)