Java ByteBuffer to String toTextAll(ByteBuffer bytes)

Here you can find the source of toTextAll(ByteBuffer bytes)

Description

Convert whole byte buffer to UTF-8 String.

License

MIT License

Parameter

Parameter Description
bytes Source byte buffer.

Return

String expression of the bytes.

Declaration

public static String toTextAll(ByteBuffer bytes) 

Method Source Code


//package com.java2s;
/*//from  w w  w  . jav  a 2 s  .  c  om
 * WireSpider
 *
 * Copyright (c) 2015 kazyx
 *
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */

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

public class Main {
    private static final Charset UTF8 = Charset.forName("UTF-8");

    /**
     * Convert whole byte buffer to UTF-8 String.
     *
     * @param bytes Source byte buffer.
     * @return String expression of the bytes.
     */
    public static String toTextAll(ByteBuffer bytes) {
        return new String(bytes.array(), UTF8);
    }
}

Related

  1. toString(final ByteBuffer buffer)
  2. toString(final ByteBuffer buffer)
  3. toStringBinary(ByteBuffer buf)
  4. toStringBinary(ByteBuffer buf)
  5. toText(ByteBuffer data, StringBuilder result, int cnt)