Java Convert via ByteBuffer toChars(byte[] bytes)

Here you can find the source of toChars(byte[] bytes)

Description

to Chars

License

Open Source License

Declaration

public static char[] toChars(byte[] bytes) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;
import java.nio.CharBuffer;

import java.nio.charset.StandardCharsets;

import java.util.Arrays;

public class Main {
    public static char[] toChars(byte[] bytes) {
        ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
        CharBuffer charBuffer = StandardCharsets.UTF_8.decode(byteBuffer);
        char[] chars = Arrays.copyOfRange(charBuffer.array(), charBuffer.position(), charBuffer.limit());
        Arrays.fill(byteBuffer.array(), (byte) 0);
        Arrays.fill(charBuffer.array(), '\u0000');
        return chars;
    }// w ww . j ava  2s  .  c  o  m
}

Related

  1. toBytes(String str, boolean wideChar)
  2. toBytes(String value)
  3. toBytes(UUID id)
  4. toBytesAsString(UUID uuid)
  5. toChars(byte[] bytes)
  6. toChars(byte[] bytes)
  7. toDirectBuffer(String s)
  8. toDoubleArray(byte[] data)
  9. toFile(URL url)