Android UTF8 to String Convert utf8decoder(byte[] data, int offset, int length)

Here you can find the source of utf8decoder(byte[] data, int offset, int length)

Description

utfdecoder

Declaration

public static String utf8decoder(byte[] data, int offset, int length) 

Method Source Code

//package com.java2s;
import java.nio.ByteBuffer;

import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;

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

    public static String utf8decoder(byte[] data, int offset, int length) {
        try {/*from   ww w. j  a  va  2s .  c  o m*/
            return UTF8_DECODER.decode(
                    ByteBuffer.wrap(data, offset, length)).toString();
        } catch (CharacterCodingException ex) {
            throw new RuntimeException(ex);
        }
    }
}

Related

  1. utf8BytesToString(byte[] bytes, int start, int length)
  2. utf8BytesWithUtf16LengthToString( @Nonnull byte[] bytes, int start, int utf16Length)
  3. utf8BytesWithUtf16LengthToString( @Nonnull byte[] bytes, int start, int utf16Length, @Nullable int[] readLength)