Java ByteBuffer to CharBuffer toCharBuffer(final ByteBuffer buffer)

Here you can find the source of toCharBuffer(final ByteBuffer buffer)

Description

Converts a byte buffer into a character buffer.

License

Open Source License

Parameter

Parameter Description
buffer Byte buffer to convert.

Return

Character buffer containing UTF-8 string representation of bytes.

Declaration

public static CharBuffer toCharBuffer(final ByteBuffer buffer) 

Method Source Code

//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  w w.  j ava 2 s  .  co  m
     * 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);
    }
}