Here you can find the source of convertToCharacterSet(byte[] input, Charset fromCharset, Charset toCharSet)
Parameter | Description |
---|---|
input | The input text as a byte array. |
fromCharset | The source character set. |
toCharSet | The destination character set. |
public static byte[] convertToCharacterSet(byte[] input, Charset fromCharset, Charset toCharSet)
//package com.java2s; //License from project: Apache License import java.nio.ByteBuffer; import java.nio.CharBuffer; import java.nio.charset.Charset; import java.util.Arrays; public class Main { /**//from w w w . j a v a 2s .co m * Converts the input text between the two specified character sets. * @param input The input text as a byte array. * @param fromCharset The source character set. * @param toCharSet The destination character set. * @return The input text, converted from the source to the destination character set. */ public static byte[] convertToCharacterSet(byte[] input, Charset fromCharset, Charset toCharSet) { if (input == null) { return null; } CharBuffer decodedData = fromCharset.decode(ByteBuffer.wrap(input)); ByteBuffer encodedData = toCharSet.encode(decodedData); return Arrays.copyOf(encodedData.array(), encodedData.limit()); } }