Here you can find the source of toString(final ByteBuffer buffer)
Parameter | Description |
---|---|
buffer | buffer to convert |
public static String toString(final ByteBuffer buffer)
//package com.java2s; /*// ww w . j a va2s. c o m * jndn-management * Copyright (c) 2015-2016, Intel Corporation. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU Lesser General Public License, * version 3, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for * more details. */ import java.nio.ByteBuffer; import java.nio.charset.Charset; public class Main { /** * Convert ByteBuffer to string, assuming UTF-8 encoding in the buffer. * * @param buffer buffer to convert * @return String representation of ByteBuffer (UTF-8 encoding) */ public static String toString(final ByteBuffer buffer) { byte[] array = new byte[buffer.remaining()]; buffer.get(array); return new String(array, Charset.forName("UTF-8")); } }