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

voidsort(String inFile, int keyIndex, String outFile)
sort
TreeMap<Integer, ArrayList<String>> tmap = new TreeMap<>();
try {
    List<String> list = Files.readAllLines(Paths.get(inFile), StandardCharsets.UTF_8);
    String prevKey = "";
    ArrayList<String> sameKeyLines = new ArrayList<>();
    for (int i = 0; i < list.size(); i++) {
        String[] str = list.get(i).split("\t");
        String currentKey = str[keyIndex];
...
StringstringFromBytesUTF8(byte[] bytes)
string From Bytes UTF
return stringFromBytes(bytes, _utf8_charset);
byte[]stringToUtf8(String str)
Encodes the specified string as a UTF-8 sequence.
try {
    return str.getBytes(ENCODING_NAME_UTF8);
} catch (UnsupportedEncodingException e) {
    throw new UnsupportedCharsetException(ENCODING_NAME_UTF8);
byte[]stringToUTF8Bytes(String str)
string To UTF Bytes
if (str == null)
    return null;
return str.getBytes(UTF8_CHARSET);
byte[]toBytesUTF8(String s)
Creates a byte array from a given string, using the UTF-8 encoding.
try {
    return s.getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
    throw new RuntimeException("JVM does not support UTF-8 encoding.", e);
byte[]toBytesUTF8(String str)
to Bytes UTF
return toBytes(str, StandardCharsets.UTF_8.name());
voidunZip(String zipFile, String outputFolder, boolean skipDirectory)
un Zip
byte[] buffer = new byte[1024];
try {
    ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile), Charset.forName("EUC-KR"));
    ZipEntry ze = zis.getNextEntry();
    while (ze != null) {
        String fileName = ze.getName();
        if (!ze.isDirectory() && isAllowedFileName(fileName)) {
            String path = "";
...
byte[]utf8(String string)
utf
try {
    return string.getBytes("UTF-8");
} catch (Exception e) {
    e.printStackTrace();
    return null;
intutf8BufferByteLen(CharSequence str)
utf Buffer Byte Len
return str.length() * UTF8_MAX_BYTES_PER_CHAR;
longutf8ByteLength(String string)
Calculates the byte length of a UTF-8 encoded string.
if (string == null) {
    return 0;
return string.getBytes(UTF_8).length;