Files
elink-online-common/src/main/java/com/eactive/eai/util/CharsetDecoderUtil.java
T
Rinjae aacc1a389e init
2025-09-05 18:57:45 +09:00

58 lines
1.5 KiB
Java

package com.eactive.eai.util;
import java.nio.ByteBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
public class CharsetDecoderUtil {
private Charset charset = null;
private CharsetDecoder decoder = null;
public CharsetDecoderUtil(String encoding) {
this.charset = Charset.forName(encoding);
this.decoder = charset.newDecoder();
}
public static String toKor(String s) {
if (s != null) {
return changeCode(s, "iso_8859-1", "KSC5601");
} else {
return null;
}
}
public static String changeCode(String s, String s1, String s2) {
String convString = null;
if (s != null) {
try {
convString = new String(s.getBytes(s1), s2);
} catch (Exception exception) {
//Log.errorlog(exception.toString());
return null;
}
}
return convString;
}
public String decode(ByteBuffer buffer) {
String string = null;
// buffer가 null일 경우 return한다.
if (buffer == null) {
return "";
}
try {
// buffer를 decode한다.
string = decoder.decode(buffer).toString();
} catch (CharacterCodingException e) {
string = "";
}
// decode한 값이 null일 경우 ""를 리턴 한다.
if (string == null) {
return "";
} else {
return string;
}
}
}