한글 인코딩 관련 유틸 수정

main
이범준 11 months ago
parent a9ef449a34
commit 54ac3a167e

@ -57,86 +57,6 @@ public class CmmnUtil {
return Pattern.matches(REGEXP_PATTERN_KOR, str);
}
/**
* substring
*
* new String(str.getBytes(), 0, endBytes)
* .
*
* UTF-8 3, 1 .
*
* @param str
* @param beginBytes
* @param endBytes
* @return
*/
public static 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 += ch.getBytes().length;
if (beginIndex == -1 && curBytes >= beginBytes) {
beginIndex = i;
}
if (curBytes > endBytes) {
break;
} else {
endIndex = i + 1;
}
}
return str.substring(beginIndex, endIndex);
}
public static 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 += ch.getBytes().length;
if (beginIndex == -1 && curBytes >= beginBytes) {
beginIndex = i;
}
}
return str.substring(beginIndex);
}
/**
* .

@ -0,0 +1,140 @@
package cokr.xit.fims.cmmn;
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) {
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 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);
}
}

@ -14,8 +14,8 @@ import java.util.stream.Collectors;
import org.apache.commons.io.FilenameUtils;
import cokr.xit.base.code.CommonCode;
import cokr.xit.fims.cmmn.CmmnUtil;
import cokr.xit.fims.cmmn.CodeConverter;
import cokr.xit.fims.cmmn.Hangul;
import cokr.xit.foundation.data.DataObject;
import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
@ -369,6 +369,7 @@ abstract public class LayoutParser {
* @return
*/
public String[] smartSplit(String string, JSONArray jsonArray) {
Hangul hangul = new Hangul(2);
List<Integer> byteNums = new ArrayList();
for(int i=0; i<jsonArray.size(); i++) {
@ -383,7 +384,7 @@ abstract public class LayoutParser {
int cursor = 1;
for(int i=0; i<byteNums.size(); i++) {
int byteNum = byteNums.get(i);
result[i] = CmmnUtil.substringByBytes(string, cursor, cursor+(byteNum-1));
result[i] = hangul.substringByBytes(string, cursor, cursor+(byteNum-1));
cursor += byteNum;
}

@ -12,7 +12,7 @@ import java.util.Base64.Decoder;
import java.util.Base64.Encoder;
import cokr.xit.base.file.FileInfo;
import cokr.xit.fims.cmmn.CmmnUtil;
import cokr.xit.fims.cmmn.Hangul;
import cokr.xit.foundation.data.DataObject;
import net.minidev.json.JSONArray;
import net.minidev.json.JSONObject;
@ -38,8 +38,8 @@ public class SingleFileParser extends LayoutParser {
//텍스트 영역 파싱
BufferedReader textReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), Charset.forName("EUC-KR")));
String textConent = CmmnUtil.substringByBytes(org.apache.commons.io.IOUtils.toString(textReader), 1, this.getSumByte(jsonArray));
Hangul hangul = new Hangul(2);
String textConent = hangul.substringByBytes(org.apache.commons.io.IOUtils.toString(textReader), 1, this.getSumByte(jsonArray));
String[] contentSplit = {};

@ -265,7 +265,10 @@ public class Crdn05Controller extends ApplicationController {
int nextTempGroupSeq = 1;
for(int i=0; i < layoutDescriptors.size(); i++) {
String workPath = layoutDescriptors.get(i).getLinkFileLocation();
File file = new File(workPath);
if(!file.exists()) {
file.mkdirs();
}
List<Path> fileList = null;
try {
//폴더는 제외하고 파일만 필터링

Loading…
Cancel
Save