init
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user