Java Utililty Methods UTF8

List of utility methods to do UTF8

Description

The list of methods to do UTF8 are organized into topic(s).

Method

booleanbackup(String inputFile, String backupFile)
backup
return backup(new File(inputFile), new File(backupFile));
StringcodeListToString(List utf8CodeList)
convert utf8 code list to string
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
for (int code : utf8CodeList) {
    codeToString(buffer, code);
return new String(buffer.toByteArray(), DEFAULT_CHARSET);
StringcodesToString(int[] utf8Codes)
convert utf8 codes to string
List<Integer> codeList = new ArrayList<>(utf8Codes.length);
for (int code : utf8Codes) {
    codeList.add(code);
return codeListToString(codeList);
StringcodeToString(int utf8Code)
convert utf8 code to string
return codesToString(new int[] { utf8Code });
booleancompareWithGold(String goldfile, String outputfile)
Compare contents of golden file with test output file line by line.
return compareWithGold(goldfile, outputfile, StandardCharsets.UTF_8);
StringconvertISO8859_1_to_UTF_8(String s)
convert IStUT_
if (s == null) {
    return null;
} else {
    return new String(s.getBytes(Charset.forName(ISO_8859_1)), Charset.forName(UTF_8));
java.lang.StringConvertUTF8(byte[] buffer)
Convert UTF
return new String(buffer, java.nio.charset.StandardCharsets.UTF_8);
voidcreateFileAndExport(String inputFileName, String outputFileName, String outputStr)
create File And Export
FileChannel inputChannel = null;
FileChannel outputChannel = null;
try {
    File input = new File(inputFileName);
    File output = new File(outputFileName);
    inputChannel = new FileInputStream(input).getChannel();
    outputChannel = new FileOutputStream(output).getChannel();
    outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
...
DatagramPacketcreateFromUTF8String(DatagramPacket packet, String str)
create From UTF String
byte[] b = str.getBytes(utf8);
return new DatagramPacket(b, b.length);
PathcreateTemporaryOutputFolder()
create Temporary Output Folder
Path tmp = Files.createTempDirectory("glove-test-dir");
tmp.toFile().deleteOnExit();
return tmp;