From be7e818ce90727e8d01ed496c8024a89d73c4d40 Mon Sep 17 00:00:00 2001 From: leebj Date: Tue, 5 Nov 2024 14:52:12 +0900 Subject: [PATCH] =?UTF-8?q?=EB=AC=B8=EC=9E=90=EC=97=B4=20=EC=9D=B8?= =?UTF-8?q?=EC=BD=94=EB=94=A9=20=EA=B4=80=EB=A0=A8=20=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=ED=94=84=EB=A1=9C=EC=A0=9D=ED=8A=B8?= =?UTF-8?q?=EC=9D=B4=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 40 ++-- src/main/java/cokr/xit/fims/cmmn/Hangul.java | 223 +++++++++++++++++++ 2 files changed, 246 insertions(+), 17 deletions(-) create mode 100644 src/main/java/cokr/xit/fims/cmmn/Hangul.java diff --git a/pom.xml b/pom.xml index 4323a389..4c78457b 100644 --- a/pom.xml +++ b/pom.xml @@ -9,14 +9,14 @@ 2.7.18 - + cokr.xit.app fims-java-public 1.0.0-SNAPSHOT fims-java-public 과태료통합관리시스템java-public jar - + UTF-8 17 @@ -28,7 +28,7 @@ https://nas.xit.co.kr:8888/repository/maven-public/ - + maven-public @@ -41,9 +41,9 @@ - + - + org.egovframe.rte @@ -65,7 +65,7 @@ - + 3rd-party echelon @@ -76,19 +76,19 @@ dguard compile - + - - + + cokr.xit.boot xit-base-starter 23.04.01-SNAPSHOT - + @@ -96,7 +96,7 @@ xit-syslog 23.04.01-SNAPSHOT - + org.egovframe.rte @@ -115,14 +115,14 @@ mariadb-java-client runtime - + cokr.xit.app app-support-java 1.0.0-SNAPSHOT - + commons-net @@ -140,14 +140,20 @@ jsch 0.1.72 - + cokr.xit.interfaces xit-lvis 0.0.1-SNAPSHOT - + + + + com.ibm.icu + icu4j + 75.1 + @@ -268,6 +274,6 @@ - - + + \ No newline at end of file diff --git a/src/main/java/cokr/xit/fims/cmmn/Hangul.java b/src/main/java/cokr/xit/fims/cmmn/Hangul.java new file mode 100644 index 00000000..41cebee3 --- /dev/null +++ b/src/main/java/cokr/xit/fims/cmmn/Hangul.java @@ -0,0 +1,223 @@ +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){ + this.hangulIsNByte = hangulIsNByte; + } + + private int hangulIsNByte; + + public int is() { + return this.hangulIsNByte; + } + + /** + * 문자열의 바이트 수 구하기 + * + * @param str + * @return + */ + public int getByteLength(String str) { + if(str == null) { + return 0; + } + int byteLen = 0; + + for(int i=0;i 127) || (ch < 0)) { + byteLen += this.is(); + } else { + byteLen += 1; + } + } + + return byteLen; + } + + /** + * 문자열을 바이트 단위로 패딩 + * + * @param str + * @param byteLen + * @param ch + * @return + */ + public String lpadByte(String str, int byteLen, String ch) { + String result = str; + + int strLen = this.getByteLength(str); + + for(int i=0; i < byteLen - strLen ; i++) { + result = ch + result; + } + + return result; + } + + /** + * 문자열을 바이트 단위로 패딩 + * + * @param str + * @param byteLen + * @param ch + * @return + */ + public String rpadByte(String str, int byteLen, String ch) { + String result = str; + + int strLen = this.getByteLength(str); + + for(int i=0; i < byteLen - strLen ; i++) { + result += ch; + } + + return result; + } + + /** + * 문자열을 바이트 단위로 substring하기 + * + * @param str + * @param beginBytes + * @param endBytes + * @return + */ + public String substringByBytes(String str, int beginBytes, int endBytes) { + if (str == null || str.length() == 0) { + return ""; + } + + if (beginBytes < 0) { + beginBytes = 0; + } + + if (endBytes < 1) { + return ""; + } + + int len = str.length(); + + int beginIndex = -1; + int endIndex = 0; + + int curBytes = 0; + String ch = null; + for (int i = 0; i < len; i++) { + ch = str.substring(i, i + 1); + curBytes += this.getByteLength(ch); + + + if (beginIndex == -1 && curBytes >= beginBytes) { + beginIndex = i; + } + + if (curBytes > endBytes) { + break; + } else { + endIndex = i + 1; + } + } + + return str.substring(beginIndex, endIndex); + } + + /** + * 문자열을 바이트 단위로 substring하기 + * + * @param str + * @param beginBytes + * @return + */ + public String substringByBytes(String str, int beginBytes) { + if (str == null || str.length() == 0) { + return ""; + } + + if (beginBytes < 0) { + beginBytes = 0; + } + + int len = str.length(); + + int beginIndex = -1; + + int curBytes = 0; + String ch = null; + for (int i = 0; i < len; i++) { + ch = str.substring(i, i + 1); + curBytes += this.getByteLength(ch); + + + if (beginIndex == -1 && curBytes >= beginBytes) { + beginIndex = i; + } + + } + + return str.substring(beginIndex); + } + + /** + * 텍스트파일 인코딩 확인 + * + * @param path 파일경로 + * @return 캐릭터셋 + */ + public String encodingDetect(String path) throws IOException { + File f = new File(path); + + return encodingDetect(f); + } + + /** + * 텍스트파일 인코딩 확인 + * + * @param file 파일 + * @return 캐릭터셋 + */ + public String encodingDetect(File file) throws IOException { + CharsetDetector detector; + CharsetMatch match; + + FileInputStream fis = null; + try { + String result = ""; + + fis = new FileInputStream(file); + + byte[] byteData = new byte[(int) file.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); + } + } +}