Here you can find the source of toString(final ByteBuffer buffer)
Parameter | Description |
---|---|
buffer | Byte buffer to convert. |
public static String toString(final ByteBuffer buffer)
//package com.java2s; /* See LICENSE for licensing and NOTICE for copyright. */ import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; public class Main { /** Default character set for bytes is UTF-8. */ public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); /**//from w ww . j ava2s. c o m * Converts a byte array into a string in the UTF-8 character set. * * @param bytes Byte array to convert. * * @return UTF-8 string representation of bytes. */ public static String toString(final byte[] bytes) { return new String(bytes, DEFAULT_CHARSET); } /** * Converts a byte buffer into a string in the UTF-8 character set. * * @param buffer Byte buffer to convert. * * @return UTF-8 string representation of bytes. */ public static String toString(final ByteBuffer buffer) { return toCharBuffer(buffer).toString(); } /** * Converts a byte buffer into a character buffer. * * @param buffer Byte buffer to convert. * * @return Character buffer containing UTF-8 string representation of bytes. */ public static CharBuffer toCharBuffer(final ByteBuffer buffer) { return DEFAULT_CHARSET.decode(buffer); } }