캐릭터셋 확인 메소드 추가

main
이범준 4 months ago
parent b1e66bb21d
commit 9d12d9ca14

@ -94,6 +94,13 @@
<scope>runtime</scope>
</dependency>
<!-- 유니코드, 캐릭터셋 탐지 -->
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>75.1</version>
</dependency>
<!-- 자망연계 -->
<dependency>
<groupId>cokr.xit.interfaces</groupId>

@ -27,6 +27,7 @@ import cokr.xit.fims.base.Backup;
import cokr.xit.fims.base.service.bean.AdminBean;
import cokr.xit.fims.cmmn.DirectoryStructureToJson;
import cokr.xit.fims.cmmn.DirectoryStructureToJson.Node;
import cokr.xit.fims.cmmn.Hangul;
import cokr.xit.fims.crdn.service.ImportService;
import cokr.xit.foundation.data.DataObject;
import cokr.xit.interfaces.smg.service.SmgService;
@ -181,8 +182,9 @@ public class AdminController extends ApplicationController {
int inputData = 0;
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(path),Charset.forName("EUC-KR")));
Hangul hangul = new Hangul(3);
String detect = hangul.detect(path);
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(path),Charset.forName(detect)));
while ((inputData = br.read()) != -1) {
sb.append((char)inputData) ;

@ -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);
}
}
}

Loading…
Cancel
Save