Java Byte Array to String by Charset decodeBytes(byte[] data, Charset charset, boolean report)

Here you can find the source of decodeBytes(byte[] data, Charset charset, boolean report)

Description

decode Bytes

License

Open Source License

Declaration

public static CharBuffer decodeBytes(byte[] data, Charset charset, boolean report)
            throws CharacterCodingException, IOException 

Method Source Code

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

import java.io.IOException;

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CodingErrorAction;

public class Main {
    public static CharBuffer decodeBytes(byte[] data, Charset charset, boolean report)
            throws CharacterCodingException, IOException {
        CodingErrorAction action = (report) ? CodingErrorAction.REPORT : CodingErrorAction.REPLACE;
        CharsetDecoder decoder = charset.newDecoder();
        decoder.onMalformedInput(action);
        decoder.onUnmappableCharacter(action);
        return decoder.decode(ByteBuffer.wrap(data));
    }/*from   w  ww.ja v  a  2s.c om*/
}

Related

  1. convertToString(final byte[] bytes, final Charset charset)
  2. decode(CharsetDecoder decoder, byte[] in)
  3. decode(final byte[] binaryValue, final Charset charset)
  4. decode(final byte[] binaryValue, final Charset charset)
  5. decode(final byte[] pData, final int pOffset, final int pLength, final String pCharset)
  6. decodeCHARSET(byte[] bytes, Charset charset)
  7. decodeHelper(byte[] byteArray, int numberOfBytes, java.nio.charset.Charset charset)
  8. decodeOrDefault(byte[] data, Charset charset, String defaultValue)
  9. decodeWithReplacement(byte[] bytes, Charset cs)