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

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

@ -9,14 +9,14 @@
<version>2.7.18</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>cokr.xit.app</groupId>
<artifactId>fims-java-all</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>fims-java-all</name>
<description>과태료통합관리시스템java전체</description>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>17</java.version>
@ -28,7 +28,7 @@
<url>https://nas.xit.co.kr:8888/repository/maven-public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>maven-public</id>
@ -41,9 +41,9 @@
</releases>
</pluginRepository>
</pluginRepositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.egovframe.rte</groupId>
@ -65,7 +65,7 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>3rd-party</groupId>
<artifactId>echelon</artifactId>
@ -76,7 +76,7 @@
<artifactId>dguard</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
</dependencyManagement>
@ -93,13 +93,6 @@
<artifactId>fims-java-rent</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<!-- 유니코드, 캐릭터셋 탐지 -->
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>75.1</version>
</dependency>
<!-- 장애인 표지 조회 -->
<dependency>
@ -107,35 +100,35 @@
<artifactId>xit-disabled-parking</artifactId>
<version>23.04.01-SNAPSHOT</version>
</dependency>
<!-- TODO : 전기차 여부 연계 -->
<!-- <dependency>
<groupId></groupId>
<artifactId></artifactId>
<version></version>
</dependency> -->
<!-- TODO : 미세먼지(mecar) 연계 -->
<!-- <dependency>
<groupId></groupId>
<artifactId></artifactId>
<version></version>
</dependency> -->
<!-- 국민신문고 -->
<dependency>
<groupId>cokr.xit.interfaces</groupId>
<artifactId>xit-smg</artifactId>
<version>23.04.01-SNAPSHOT</version>
</dependency>
<!-- TODO : 새올 민원 연계 -->
<!-- <dependency>
<groupId></groupId>
<artifactId></artifactId>
<version></version>
</dependency> -->
<!-- 차세대세외수입 개별시스템 연계 -->
<dependency>
<groupId>cokr.xit.interfaces.lntris</groupId>
@ -148,14 +141,14 @@
<artifactId>xit-lntris-special</artifactId>
<version>23.04.01-SNAPSHOT</version>
</dependency>
<!-- epost 연계 -->
<dependency>
<groupId>cokr.xit.interfaces</groupId>
<artifactId>xit-epost</artifactId>
<version>23.04.01-SNAPSHOT</version>
</dependency>
<!-- PDF 라이브러리 -->
<dependency>
<groupId>org.apache.pdfbox</groupId>
@ -295,6 +288,6 @@
</repository>
</distributionManagement>
<!-- Nexus deploy -->
</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