문자열 인코딩 관련 처리 기능 프로젝트이동

main
이범준 1 week ago
parent 3cf3339b21
commit be7e818ce9

@ -9,14 +9,14 @@
<version>2.7.18</version> <version>2.7.18</version>
<relativePath/> <!-- lookup parent from repository --> <relativePath/> <!-- lookup parent from repository -->
</parent> </parent>
<groupId>cokr.xit.app</groupId> <groupId>cokr.xit.app</groupId>
<artifactId>fims-java-public</artifactId> <artifactId>fims-java-public</artifactId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<name>fims-java-public</name> <name>fims-java-public</name>
<description>과태료통합관리시스템java-public</description> <description>과태료통합관리시스템java-public</description>
<packaging>jar</packaging> <packaging>jar</packaging>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>17</java.version> <java.version>17</java.version>
@ -28,7 +28,7 @@
<url>https://nas.xit.co.kr:8888/repository/maven-public/</url> <url>https://nas.xit.co.kr:8888/repository/maven-public/</url>
</repository> </repository>
</repositories> </repositories>
<pluginRepositories> <pluginRepositories>
<pluginRepository> <pluginRepository>
<id>maven-public</id> <id>maven-public</id>
@ -41,9 +41,9 @@
</releases> </releases>
</pluginRepository> </pluginRepository>
</pluginRepositories> </pluginRepositories>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.egovframe.rte</groupId> <groupId>org.egovframe.rte</groupId>
@ -65,7 +65,7 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>3rd-party</groupId> <groupId>3rd-party</groupId>
<artifactId>echelon</artifactId> <artifactId>echelon</artifactId>
@ -76,19 +76,19 @@
<artifactId>dguard</artifactId> <artifactId>dguard</artifactId>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>cokr.xit.boot</groupId> <groupId>cokr.xit.boot</groupId>
<artifactId>xit-base-starter</artifactId> <artifactId>xit-base-starter</artifactId>
<version>23.04.01-SNAPSHOT</version> <version>23.04.01-SNAPSHOT</version>
</dependency> </dependency>
<!-- 시스템로그 --> <!-- 시스템로그 -->
<dependency> <dependency>
@ -96,7 +96,7 @@
<artifactId>xit-syslog</artifactId> <artifactId>xit-syslog</artifactId>
<version>23.04.01-SNAPSHOT</version> <version>23.04.01-SNAPSHOT</version>
</dependency> </dependency>
<!-- 암복호화 --> <!-- 암복호화 -->
<dependency> <dependency>
<groupId>org.egovframe.rte</groupId> <groupId>org.egovframe.rte</groupId>
@ -115,14 +115,14 @@
<artifactId>mariadb-java-client</artifactId> <artifactId>mariadb-java-client</artifactId>
<scope>runtime</scope> <scope>runtime</scope>
</dependency> </dependency>
<!-- 앱 지원 --> <!-- 앱 지원 -->
<dependency> <dependency>
<groupId>cokr.xit.app</groupId> <groupId>cokr.xit.app</groupId>
<artifactId>app-support-java</artifactId> <artifactId>app-support-java</artifactId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
</dependency> </dependency>
<!-- FTP 라이브러리 --> <!-- FTP 라이브러리 -->
<dependency> <dependency>
<groupId>commons-net</groupId> <groupId>commons-net</groupId>
@ -140,14 +140,20 @@
<artifactId>jsch</artifactId> <artifactId>jsch</artifactId>
<version>0.1.72</version> <version>0.1.72</version>
</dependency> </dependency>
<!-- 자망연계 --> <!-- 자망연계 -->
<dependency> <dependency>
<groupId>cokr.xit.interfaces</groupId> <groupId>cokr.xit.interfaces</groupId>
<artifactId>xit-lvis</artifactId> <artifactId>xit-lvis</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
</dependency> </dependency>
<!-- 유니코드, 캐릭터셋 탐지 -->
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>75.1</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
@ -268,6 +274,6 @@
</repository> </repository>
</distributionManagement> </distributionManagement>
<!-- Nexus deploy --> <!-- Nexus deploy -->
</project> </project>

@ -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<str.length();i++) {
char ch = str.charAt(i);
if((ch > 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);
}
}
}
Loading…
Cancel
Save