문자열 인코딩 관련 처리 기능 프로젝트이동(fims-java-public)

main
이범준 1 week ago
parent 8ef747cecc
commit 83cb9b9bd5

@ -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-all</artifactId> <artifactId>fims-java-all</artifactId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
<name>fims-java-all</name> <name>fims-java-all</name>
<description>과태료통합관리시스템java전체</description> <description>과태료통합관리시스템java전체</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,7 +76,7 @@
<artifactId>dguard</artifactId> <artifactId>dguard</artifactId>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
@ -93,13 +93,6 @@
<artifactId>fims-java-rent</artifactId> <artifactId>fims-java-rent</artifactId>
<version>1.0.0-SNAPSHOT</version> <version>1.0.0-SNAPSHOT</version>
</dependency> </dependency>
<!-- 유니코드, 캐릭터셋 탐지 -->
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>75.1</version>
</dependency>
<!-- 장애인 표지 조회 --> <!-- 장애인 표지 조회 -->
<dependency> <dependency>
@ -107,35 +100,35 @@
<artifactId>xit-disabled-parking</artifactId> <artifactId>xit-disabled-parking</artifactId>
<version>23.04.01-SNAPSHOT</version> <version>23.04.01-SNAPSHOT</version>
</dependency> </dependency>
<!-- TODO : 전기차 여부 연계 --> <!-- TODO : 전기차 여부 연계 -->
<!-- <dependency> <!-- <dependency>
<groupId></groupId> <groupId></groupId>
<artifactId></artifactId> <artifactId></artifactId>
<version></version> <version></version>
</dependency> --> </dependency> -->
<!-- TODO : 미세먼지(mecar) 연계 --> <!-- TODO : 미세먼지(mecar) 연계 -->
<!-- <dependency> <!-- <dependency>
<groupId></groupId> <groupId></groupId>
<artifactId></artifactId> <artifactId></artifactId>
<version></version> <version></version>
</dependency> --> </dependency> -->
<!-- 국민신문고 --> <!-- 국민신문고 -->
<dependency> <dependency>
<groupId>cokr.xit.interfaces</groupId> <groupId>cokr.xit.interfaces</groupId>
<artifactId>xit-smg</artifactId> <artifactId>xit-smg</artifactId>
<version>23.04.01-SNAPSHOT</version> <version>23.04.01-SNAPSHOT</version>
</dependency> </dependency>
<!-- TODO : 새올 민원 연계 --> <!-- TODO : 새올 민원 연계 -->
<!-- <dependency> <!-- <dependency>
<groupId></groupId> <groupId></groupId>
<artifactId></artifactId> <artifactId></artifactId>
<version></version> <version></version>
</dependency> --> </dependency> -->
<!-- 차세대세외수입 개별시스템 연계 --> <!-- 차세대세외수입 개별시스템 연계 -->
<dependency> <dependency>
<groupId>cokr.xit.interfaces.lntris</groupId> <groupId>cokr.xit.interfaces.lntris</groupId>
@ -148,14 +141,14 @@
<artifactId>xit-lntris-special</artifactId> <artifactId>xit-lntris-special</artifactId>
<version>23.04.01-SNAPSHOT</version> <version>23.04.01-SNAPSHOT</version>
</dependency> </dependency>
<!-- epost 연계 --> <!-- epost 연계 -->
<dependency> <dependency>
<groupId>cokr.xit.interfaces</groupId> <groupId>cokr.xit.interfaces</groupId>
<artifactId>xit-epost</artifactId> <artifactId>xit-epost</artifactId>
<version>23.04.01-SNAPSHOT</version> <version>23.04.01-SNAPSHOT</version>
</dependency> </dependency>
<!-- PDF 라이브러리 --> <!-- PDF 라이브러리 -->
<dependency> <dependency>
<groupId>org.apache.pdfbox</groupId> <groupId>org.apache.pdfbox</groupId>
@ -295,6 +288,6 @@
</repository> </repository>
</distributionManagement> </distributionManagement>
<!-- Nexus deploy --> <!-- Nexus deploy -->
</project> </project>

@ -1,217 +0,0 @@
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);
}
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