Here you can find the source of decode(final byte[] pData, final int pOffset, final int pLength, final String pCharset)
Parameter | Description |
---|---|
pData | the bytes to be decoded to characters |
pOffset | the index of the first byte to decode |
pLength | the number of bytes to decode |
pCharset | the name of a supported character set |
Parameter | Description |
---|---|
UnsupportedCharsetException | an exception |
public static String decode(final byte[] pData, final int pOffset, final int pLength, final String pCharset)
//package com.java2s; import java.io.UnsupportedEncodingException; import java.nio.charset.UnsupportedCharsetException; public class Main { /**//from w w w . j a v a 2 s . c om * Constructs a new {@link String} by decoding the specified sub array of bytes using the specified charset. * Replacement for {@link String#String(byte[], int, int, String) new String(byte[], int, int, String)}, that does * not throw the checked {@link UnsupportedEncodingException}, * but instead the unchecked {@link UnsupportedCharsetException} if the character set is not supported. * * @param pData the bytes to be decoded to characters * @param pOffset the index of the first byte to decode * @param pLength the number of bytes to decode * @param pCharset the name of a supported character set * @return a newly created string. * @throws UnsupportedCharsetException * * @see String#String(byte[], int, int, String) */ public static String decode(final byte[] pData, final int pOffset, final int pLength, final String pCharset) { try { return new String(pData, pOffset, pLength, pCharset); } catch (UnsupportedEncodingException e) { throw new UnsupportedCharsetException(pCharset); } } }