Java ByteBuffer to String byteBufferToString(ByteBuffer buffer)

Here you can find the source of byteBufferToString(ByteBuffer buffer)

Description

byte Buffer To String

License

Apache License

Declaration

public static String byteBufferToString(ByteBuffer buffer) 

Method Source Code

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

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

public class Main {
    public static String byteBufferToString(ByteBuffer buffer) {
        String data = "";
        CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder();
        try {/*ww  w  .  j  a v a 2s  . c  o  m*/
            int old_position = buffer.position();
            data = decoder.decode(buffer).toString();
            buffer.position(old_position);
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
        return data;
    }
}

Related

  1. bufferToString(ByteBuffer buff)
  2. bufferToString(ByteBuffer buffer)
  3. byteBufferToString(ByteBuffer buf)
  4. byteBufferToString(ByteBuffer buffer)
  5. byteBufferToString(ByteBuffer buffer)
  6. byteBufferToString(ByteBuffer buffer)
  7. byteBufferToString(ByteBuffer buffer)
  8. ByteBufferToString(ByteBuffer buffer, Charset charset)
  9. byteBufferToString(ByteBuffer buffer, String encoding)