|
|
|
@ -1,5 +1,14 @@
|
|
|
|
|
package cokr.xit.fims.cmmn;
|
|
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.io.IOUtils;
|
|
|
|
|
|
|
|
|
|
import com.ibm.icu.text.CharsetDetector;
|
|
|
|
|
import com.ibm.icu.text.CharsetMatch;
|
|
|
|
|
|
|
|
|
|
public class Hangul {
|
|
|
|
|
|
|
|
|
|
public Hangul(int hangulIsNByte){
|
|
|
|
@ -159,4 +168,50 @@ public class Hangul {
|
|
|
|
|
|
|
|
|
|
return str.substring(beginIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 텍스트 인코딩 확인
|
|
|
|
|
*
|
|
|
|
|
* @param path
|
|
|
|
|
* @return 캐릭터셋
|
|
|
|
|
*/
|
|
|
|
|
public String encodingDetect(String path) throws IOException {
|
|
|
|
|
File f = new File(path);
|
|
|
|
|
|
|
|
|
|
return encodingDetect(f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String encodingDetect(File f) throws IOException {
|
|
|
|
|
CharsetDetector detector;
|
|
|
|
|
CharsetMatch match;
|
|
|
|
|
|
|
|
|
|
FileInputStream fis = null;
|
|
|
|
|
try {
|
|
|
|
|
String result = "";
|
|
|
|
|
|
|
|
|
|
fis = new FileInputStream(f);
|
|
|
|
|
|
|
|
|
|
byte[] byteData = new byte[(int) f.length()];
|
|
|
|
|
|
|
|
|
|
fis.read(byteData);
|
|
|
|
|
fis.close();
|
|
|
|
|
detector = new CharsetDetector();
|
|
|
|
|
|
|
|
|
|
detector.setText(byteData);
|
|
|
|
|
match = detector.detect();
|
|
|
|
|
|
|
|
|
|
System.out.println("encoding is \"" + match.getName() + "\"");
|
|
|
|
|
|
|
|
|
|
if(match.getName().equals("UTF-8") || match.getName().equals("EUC-KR")) {
|
|
|
|
|
result = match.getName();
|
|
|
|
|
} else {
|
|
|
|
|
result = "EUC-KR";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
finally {
|
|
|
|
|
IOUtils.closeQuietly(fis);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|