Java ByteBuffer to String bufferToString(ByteBuffer buff)

Here you can find the source of bufferToString(ByteBuffer buff)

Description

buffer To String

License

Open Source License

Declaration

public static String bufferToString(ByteBuffer buff) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;

public class Main {
    public static String bufferToString(ByteBuffer buff) {
        Charset charset = Charset.forName("UTF-8");
        CharsetDecoder decoder = charset.newDecoder();

        String message = "";

        try {//w w w  .  ja  v  a2  s.com
            message = decoder.decode(buff).toString();
        } catch (Exception e) {
            message = e.getMessage();
        }

        return message;
    }
}

Related

  1. asString(Map headers)
  2. bbToString(ByteBuffer bb)
  3. buffer2String(ByteBuffer buff, String charsetName)
  4. bufferToString(ByteBuffer buf)
  5. bufferToString(ByteBuffer buf)
  6. bufferToString(ByteBuffer buffer)
  7. byteBufferToString(ByteBuffer buf)
  8. byteBufferToString(ByteBuffer buffer)
  9. byteBufferToString(ByteBuffer buffer)