티스토리 툴바


웹과 같은 환경에서 외부로 부터 전달받은 한글문자열이 EUC-KR인지 UTF-8인지 판단이 필요할때
사용될수 있는 소스 입니다.

해당 소스는 자동으로 LocalString으로 변경해 줍니다.

 public static String LocalString( String val)
 {
  if (val == null)
   return null;
  else {
   byte[] b;

   try {
    b = val.getBytes("8859_1");
    CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder();
    try {
     CharBuffer r = decoder.decode( ByteBuffer.wrap( b));
     return r.toString();
    } catch (CharacterCodingException e) {
     return new String( b, "EUC-KR");
    }
   } catch (UnsupportedEncodingException e1) {
    e1.printStackTrace();
   }
  } return null;
 }

크리에이티브 커먼즈 라이선스
Creative Commons License
Posted by symlink