Queue Body 정의, 바이트 유틸, String 유틸, 메시지 처리 관련 유틸 추가, 큐성능 테스트 진행중
@1454c2658a38f3b1af717934208c14f25c537c76
+++ src/main/java/com/munjaon/server/queue/config/BodyCommonConfig.java
... | ... | @@ -0,0 +1,46 @@ |
| 1 | +package com.munjaon.server.queue.config; | |
| 2 | + | |
| 3 | +public final class BodyCommonConfig { | |
| 4 | + /* 회원 아이디 (Length : 20 / Position : 0) */ | |
| 5 | + public static final int USERID_BYTE_LENGTH = 20; | |
| 6 | + public static final int USERID_BYTE_POSITION = 0; | |
| 7 | + /* 요금제 정보 (Length : 1 / Position : 20) (선불 : P(Prepayment) / 후불 : D(Detered Payment)) */ | |
| 8 | + public static final int FEETYPE_BYTE_LENGTH = 1; | |
| 9 | + public static final int FEETYPE_BYTE_POSITION = USERID_BYTE_POSITION + USERID_BYTE_LENGTH; | |
| 10 | + /* 단가정보 (Length : 10 / Position : 21) */ | |
| 11 | + public static final int UNITCOST_BYTE_LENGTH = 10; | |
| 12 | + public static final int UNITCOST_BYTE_POSITION = FEETYPE_BYTE_POSITION + FEETYPE_BYTE_LENGTH; | |
| 13 | + /* 메시지 그룹 아이디 (문자온 메시지 테이블에서 그룹핑할 메시지ID) (Length : 20 / Position : 31) */ | |
| 14 | + public static final int MSGGROUPID_BYTE_LENGTH = 20; | |
| 15 | + public static final int MSGGROUPID_BYTE_POSITION = UNITCOST_BYTE_POSITION + UNITCOST_BYTE_LENGTH; | |
| 16 | + /* 고객사 메시지 ID 길이 (Length : 20 / Position : 51) */ | |
| 17 | + public static final int MSGID_BYTE_LENGTH = 20; | |
| 18 | + public static final int MSGID_BYTE_POSITION = MSGGROUPID_BYTE_POSITION + MSGGROUPID_BYTE_LENGTH; | |
| 19 | + /* 서비스타입(4:SMS / 6:LMS, MMS / 8:카카오 알림톡 / 9:카카오 친구톡) (Length : 1 / Position : 71) */ | |
| 20 | + public static final int SERVICETYPE_BYTE_LENGTH = 1; | |
| 21 | + public static final int SERVICETYPE_BYTE_POSITION = MSGID_BYTE_POSITION + MSGID_BYTE_LENGTH; | |
| 22 | + /* 결과코드 (Length : 5 / Position : 72) */ | |
| 23 | + public static final int SENDSTATUS_BYTE_LENGTH = 5; | |
| 24 | + public static final int SENDSTATUS_BYTE_POSITION = SERVICETYPE_BYTE_POSITION + SERVICETYPE_BYTE_LENGTH; | |
| 25 | + /* 회신번호 (Length : 12 / Position : 77) */ | |
| 26 | + public static final int SENDER_BYTE_LENGTH = 12; | |
| 27 | + public static final int SENDER_BYTE_POSITION = SENDSTATUS_BYTE_POSITION + SENDSTATUS_BYTE_LENGTH; | |
| 28 | + /* 수신번호 (Length : 12 / Position : 89) */ | |
| 29 | + public static final int RECEIVER_BYTE_LENGTH = 12; | |
| 30 | + public static final int RECEIVER_BYTE_POSITION = SENDER_BYTE_POSITION + SENDER_BYTE_LENGTH; | |
| 31 | + /* 예약시간 (Length : 15 / Position : 101) */ | |
| 32 | + public static final int RESERVEDT_BYTE_LENGTH = 15; | |
| 33 | + public static final int RESERVEDT_BYTE_POSITION = RECEIVER_BYTE_POSITION + RECEIVER_BYTE_LENGTH; | |
| 34 | + /* 요청시간 (Length : 15 / Position : 116) */ | |
| 35 | + public static final int REQUESTDT_BYTE_LENGTH = 15; | |
| 36 | + public static final int REQUESTDT_BYTE_POSITION = RESERVEDT_BYTE_POSITION + RESERVEDT_BYTE_LENGTH; | |
| 37 | + /* 원격접속지 주소 (Length : 25 / Position : 131) */ | |
| 38 | + public static final int REMOTEIP_BYTE_LENGTH = 25; | |
| 39 | + public static final int REMOTEIP_BYTE_POSITION = REQUESTDT_BYTE_POSITION + REQUESTDT_BYTE_LENGTH; | |
| 40 | + /* 에이전트 코드 (Length : 5 / Position : 156) */ | |
| 41 | + public static final int AGENT_CODE_BYTE_LENGTH = 5; | |
| 42 | + public static final int AGENT_CODE_BYTE_POSITION = REMOTEIP_BYTE_POSITION + REMOTEIP_BYTE_LENGTH; | |
| 43 | + | |
| 44 | + /* Body 전체 길이 */ | |
| 45 | + public static final int COMMON_SUM_BYTE_LENGTH = USERID_BYTE_LENGTH + FEETYPE_BYTE_LENGTH + UNITCOST_BYTE_LENGTH + MSGGROUPID_BYTE_LENGTH + MSGID_BYTE_LENGTH + SERVICETYPE_BYTE_LENGTH + SENDSTATUS_BYTE_LENGTH + SENDER_BYTE_LENGTH + RECEIVER_BYTE_LENGTH + RESERVEDT_BYTE_LENGTH + REQUESTDT_BYTE_LENGTH + REMOTEIP_BYTE_LENGTH + AGENT_CODE_BYTE_LENGTH; | |
| 46 | +} |
+++ src/main/java/com/munjaon/server/queue/config/MediaBodyConfig.java
... | ... | @@ -0,0 +1,25 @@ |
| 1 | +package com.munjaon.server.queue.config; | |
| 2 | + | |
| 3 | +public final class MediaBodyConfig { | |
| 4 | + /* 제목 (Length : 60 / Position : 161) */ | |
| 5 | + public static final int SUBJECT_BYTE_LENGTH = 60; | |
| 6 | + public static final int SUBJECT_BYTE_POSITION = BodyCommonConfig.AGENT_CODE_BYTE_POSITION + BodyCommonConfig.AGENT_CODE_BYTE_LENGTH; | |
| 7 | + /* LMS/MMS Message (Length : 2000 / Position : 221) */ | |
| 8 | + public static final int MEDIA_MSG_BYTE_LENGTH = 2000; | |
| 9 | + public static final int MEDIA_MSG_BYTE_POSITION = SUBJECT_BYTE_POSITION + SUBJECT_BYTE_LENGTH; | |
| 10 | + /* 파일카운트 (Length : 1 / Position : 2221) */ | |
| 11 | + public static final int FILECNT_BYTE_LENGTH = 1; | |
| 12 | + public static final int FILECNT_BYTE_POSITION = MEDIA_MSG_BYTE_POSITION + MEDIA_MSG_BYTE_LENGTH; | |
| 13 | + /* 파일명 #1 (Length : 128 / Position : 2222) */ | |
| 14 | + public static final int FILENAME_ONE_BYTE_LENGTH = 128; | |
| 15 | + public static final int FILENAME_ONE_BYTE_POSITION = FILECNT_BYTE_POSITION + FILECNT_BYTE_LENGTH; | |
| 16 | + /* 파일명 #2 (Length : 128 / Position : 2350) */ | |
| 17 | + public static final int FILENAME_TWO_BYTE_LENGTH = 128; | |
| 18 | + public static final int FILENAME_TWO_BYTE_POSITION = FILENAME_ONE_BYTE_POSITION + FILENAME_ONE_BYTE_LENGTH; | |
| 19 | + /* 파일명 #3 (Length : 128 / Position : 2478) */ | |
| 20 | + public static final int FILENAME_THREE_BYTE_LENGTH = 128; | |
| 21 | + public static final int FILENAME_THREE_BYTE_POSITION = FILENAME_TWO_BYTE_POSITION + FILENAME_TWO_BYTE_LENGTH; | |
| 22 | + | |
| 23 | + /* Media Body 길이 */ | |
| 24 | + public static final int MEDIA_SUM_BYTE_LENGTH = BodyCommonConfig.COMMON_SUM_BYTE_LENGTH + SUBJECT_BYTE_LENGTH + MEDIA_MSG_BYTE_LENGTH + FILECNT_BYTE_LENGTH + FILENAME_ONE_BYTE_LENGTH + FILENAME_TWO_BYTE_LENGTH + FILENAME_THREE_BYTE_LENGTH; | |
| 25 | +} |
--- src/main/java/com/munjaon/server/queue/config/QueueHeaderConfig.java
+++ src/main/java/com/munjaon/server/queue/config/QueueHeaderConfig.java
... | ... | @@ -1,14 +1,15 @@ |
| 1 | 1 |
package com.munjaon.server.queue.config; |
| 2 | 2 |
|
| 3 | 3 |
public final class QueueHeaderConfig {
|
| 4 |
- /** Queue File Header Length - [Create Date:10 Byte, Push Count:10 Byte] */ |
|
| 5 |
- public static final int QUEUE_HEADER_LENGTH = 20; |
|
| 6 |
- /* 큐생성일 읽을 위치값 */ |
|
| 4 |
+ /* 변수 정의 : 전체 길이 : 개별 변수 Length : 개별 변수 Position */ |
|
| 5 |
+ /* 큐생성일 읽을 위치값 : 0 */ |
|
| 7 | 6 |
public static final int CREATE_DATE_POSITION = 0; |
| 8 | 7 |
/* 큐생성일 읽을 크기 */ |
| 9 | 8 |
public static final int CREATE_DATE_LENGTH = 10; |
| 10 | 9 |
/* 큐 쓰기 카운트 읽을 위치값 */ |
| 11 |
- public static final int PUSH_COUNT_POSITION = 10; |
|
| 10 |
+ public static final int PUSH_COUNT_POSITION = CREATE_DATE_POSITION + CREATE_DATE_LENGTH; |
|
| 12 | 11 |
/* 큐 쓰기 카운트 읽을 크기 */ |
| 13 | 12 |
public static final int PUSH_COUNT_LENGTH = 10; |
| 13 |
+ /* Queue File Header Length - [Create Date:10 Byte, Push Count:10 Byte] */ |
|
| 14 |
+ public static final int QUEUE_HEADER_LENGTH = CREATE_DATE_LENGTH + PUSH_COUNT_LENGTH; |
|
| 14 | 15 |
} |
+++ src/main/java/com/munjaon/server/queue/config/SmsBodyConfig.java
... | ... | @@ -0,0 +1,10 @@ |
| 1 | +package com.munjaon.server.queue.config; | |
| 2 | + | |
| 3 | +public final class SmsBodyConfig { | |
| 4 | + /* SMS Message (Length : 160 / Position : 161) */ | |
| 5 | + public static final int SMS_MSG_BYTE_LENGTH = 160; | |
| 6 | + public static final int SMS_MSG_BYTE_POSITION = BodyCommonConfig.AGENT_CODE_BYTE_POSITION + BodyCommonConfig.AGENT_CODE_BYTE_LENGTH; | |
| 7 | + | |
| 8 | + /* SMS Body 길이 */ | |
| 9 | + public static final int SMS_SUM_BYTE_LENGTH = BodyCommonConfig.COMMON_SUM_BYTE_LENGTH + SMS_MSG_BYTE_LENGTH; | |
| 10 | +} |
--- src/main/java/com/munjaon/server/queue/dto/BasicMessageDto.java
+++ src/main/java/com/munjaon/server/queue/dto/BasicMessageDto.java
... | ... | @@ -8,11 +8,20 @@ |
| 8 | 8 |
@Setter |
| 9 | 9 |
@ToString |
| 10 | 10 |
public class BasicMessageDto {
|
| 11 |
+ protected String userId = ""; |
|
| 12 |
+ protected String feeType = ""; |
|
| 13 |
+ protected String unitCost = ""; |
|
| 14 |
+ protected String msgGroupID = "0"; |
|
| 11 | 15 |
protected String userMsgID = ""; |
| 16 |
+ protected String serviceType = ""; |
|
| 17 |
+ protected String sendStatus = "0"; |
|
| 12 | 18 |
protected String userSender = ""; |
| 13 | 19 |
protected String userReceiver = ""; |
| 20 |
+ protected String reserveDt = ""; |
|
| 21 |
+ protected String requestDt; |
|
| 22 |
+ protected String remoteIP = "127.0.0.1"; |
|
| 23 |
+ protected String routerSeq = "0"; |
|
| 24 |
+ |
|
| 14 | 25 |
protected String userMessage = ""; |
| 15 | 26 |
protected String userMsgType = ""; |
| 16 |
- protected String userRequestDate = ""; |
|
| 17 |
- protected String sendStatus = "0"; |
|
| 18 | 27 |
} |
+++ src/main/java/com/munjaon/server/util/ByteUtil.java
... | ... | @@ -0,0 +1,423 @@ |
| 1 | +/* | |
| 2 | + * To change this template, choose Tools | Templates | |
| 3 | + * and open the template in the editor. | |
| 4 | + */ | |
| 5 | + | |
| 6 | +package com.munjaon.server.util; | |
| 7 | + | |
| 8 | +/** | |
| 9 | + * bytes 관련 유틸리티 클래스 | |
| 10 | + * @author JDS | |
| 11 | + */ | |
| 12 | +public final class ByteUtil { | |
| 13 | + public static final int BYTE_SIZE = 128; | |
| 14 | + /* 큐에 저장하기전에 바이트를 채울 문자 */ | |
| 15 | + public static final byte SET_DEFAULT_BYTE = (byte) 0x00; | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * bytes 배열의 핵사값을 16자리씩 개행하여 반환한다.<BR> | |
| 19 | + * 핵사 로그 출력을 위해 사용한다. | |
| 20 | + * @param src | |
| 21 | + * @param isLine | |
| 22 | + * @return 16자리씩 개행된 핵사값 | |
| 23 | + */ | |
| 24 | + public static String byteToHex(byte[] src, boolean isLine) { | |
| 25 | + String hex = ""; | |
| 26 | + // if(src.length > 16) | |
| 27 | + hex = ""; | |
| 28 | + for (int i = 0, j = 1; i < src.length; i++, j++) { | |
| 29 | + hex += pad0(Integer.toHexString(src[i] & 0xff), 2) + " "; | |
| 30 | + | |
| 31 | + if (isLine && src.length > 16 && (j % 16) == 0) { | |
| 32 | + // hex += " " + new String(codes, j-16, 16); | |
| 33 | + hex += "\r\n"; | |
| 34 | + } | |
| 35 | + } | |
| 36 | + return hex; | |
| 37 | + } | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * bytes 배열의 핵사값을 16자리씩 개행하여 반환한다.<BR> | |
| 41 | + * 핵사 로그 출력을 위해 사용한다. | |
| 42 | + * @param src | |
| 43 | + * @return 16자리씩 개행된 핵사값 | |
| 44 | + */ | |
| 45 | + public static String byteToHex(byte[] src) { | |
| 46 | + String hex = ""; | |
| 47 | + // if(src.length > 16) | |
| 48 | + //hex = "\r\n"; | |
| 49 | + for (int i = 0, j = 1; i < src.length; i++, j++) { | |
| 50 | + hex += pad0(Integer.toHexString(src[i] & 0xff), 2) + " "; | |
| 51 | + | |
| 52 | + if (src.length > 16 && (j % 16) == 0) { | |
| 53 | + // hex += " " + new String(codes, j-16, 16); | |
| 54 | + hex += "\r\n"; | |
| 55 | + } | |
| 56 | + } | |
| 57 | + return hex; | |
| 58 | + } | |
| 59 | + | |
| 60 | + /** | |
| 61 | + * bytes 배열의 지정된 위치값에 대해 16자리씩 개행된 핵사값으로 반환한다.<BR> | |
| 62 | + * 핵사 로그 출력을 위해 사용한다. | |
| 63 | + * @param src | |
| 64 | + * @param srcPos | |
| 65 | + * @param length | |
| 66 | + * @return 16자리씩 개행된 핵사값 | |
| 67 | + */ | |
| 68 | + public static String byteToHex(byte[] src, int srcPos, int length) { | |
| 69 | + String hex = ""; | |
| 70 | + //if(src.length > 16) | |
| 71 | + hex = "\r\n"; | |
| 72 | + for (int i = srcPos, j = 1; i < srcPos + length; i++, j++) { | |
| 73 | + hex += pad0(Integer.toHexString(src[i] & 0xff), 2) + " "; | |
| 74 | + if (src.length > 16 && (j % 16) == 0) { | |
| 75 | + hex += "\r\n"; | |
| 76 | + } | |
| 77 | + } | |
| 78 | + return hex; | |
| 79 | + } | |
| 80 | + | |
| 81 | + public static String intToHex(int src) { | |
| 82 | + String hex = "0x"; | |
| 83 | + byte[] bSrc = ByteUtil.intToByte(src); | |
| 84 | + for (int i = 0, j = 1; i < bSrc.length; i++, j++) { | |
| 85 | + hex += pad0(Integer.toHexString(bSrc[i] & 0xff), 2); | |
| 86 | + } | |
| 87 | + return hex; | |
| 88 | + } | |
| 89 | + | |
| 90 | + public static byte[] shortToByte(short s) { | |
| 91 | + byte dest[] = new byte[2]; | |
| 92 | + dest[1] = (byte) (s & 0xff); | |
| 93 | + dest[0] = (byte) (s >>> 8 & 0xff); | |
| 94 | + return dest; | |
| 95 | + } | |
| 96 | + | |
| 97 | + public static byte[] intToByte(int i) { | |
| 98 | + byte dest[] = new byte[4]; | |
| 99 | + dest[3] = (byte) (i & 0xff); | |
| 100 | + dest[2] = (byte) (i >>> 8 & 0xff); | |
| 101 | + dest[1] = (byte) (i >>> 16 & 0xff); | |
| 102 | + dest[0] = (byte) (i >>> 24 & 0xff); | |
| 103 | + return dest; | |
| 104 | + } | |
| 105 | + | |
| 106 | + public static byte[] longToByte(long l) { | |
| 107 | + byte dest[] = new byte[8]; | |
| 108 | + dest[7] = (byte) (int) (l & 255L); | |
| 109 | + dest[6] = (byte) (int) (l >>> 8 & 255L); | |
| 110 | + dest[5] = (byte) (int) (l >>> 16 & 255L); | |
| 111 | + dest[4] = (byte) (int) (l >>> 24 & 255L); | |
| 112 | + dest[3] = (byte) (int) (l >>> 32 & 255L); | |
| 113 | + dest[2] = (byte) (int) (l >>> 40 & 255L); | |
| 114 | + dest[1] = (byte) (int) (l >>> 48 & 255L); | |
| 115 | + dest[0] = (byte) (int) (l >>> 56 & 255L); | |
| 116 | + return dest; | |
| 117 | + } | |
| 118 | + | |
| 119 | + public static byte[] floatToByte(float f) { | |
| 120 | + byte dest[] = new byte[4]; | |
| 121 | + return setFloat(dest, 0, f); | |
| 122 | + } | |
| 123 | + | |
| 124 | + public static byte[] doubleToByte(double d) { | |
| 125 | + byte dest[] = new byte[8]; | |
| 126 | + return setDouble(dest, 0, d); | |
| 127 | + } | |
| 128 | + | |
| 129 | + public static byte getByte(byte src[], int offset) { | |
| 130 | + return src[offset]; | |
| 131 | + } | |
| 132 | + | |
| 133 | + public static byte[] getBytes(String data) { | |
| 134 | + byte[] b = null; | |
| 135 | + | |
| 136 | + b = data.getBytes(); | |
| 137 | + | |
| 138 | + return (b); | |
| 139 | + } | |
| 140 | + | |
| 141 | + public static byte[] getBytes(byte src[], int offset, int length) { | |
| 142 | + byte dest[] = new byte[length]; | |
| 143 | + System.arraycopy(src, offset, dest, 0, length); | |
| 144 | + return dest; | |
| 145 | + } | |
| 146 | + | |
| 147 | + public static short getShort(byte src[], int offset) { | |
| 148 | + return (short) ((src[offset] & 0xff) << 8 | src[offset + 1] & 0xff); | |
| 149 | + } | |
| 150 | + | |
| 151 | + public static int getInt(byte src[], int offset) { | |
| 152 | + return (src[offset] & 0xff) << 24 | (src[offset + 1] & 0xff) << 16 | |
| 153 | + | (src[offset + 2] & 0xff) << 8 | src[offset + 3] & 0xff; | |
| 154 | + } | |
| 155 | + | |
| 156 | + public static long getLong(byte src[], int offset) { | |
| 157 | + return (long) getInt(src, offset) << 32 | |
| 158 | + | (long) getInt(src, offset + 4) & 0xffffffffL; | |
| 159 | + } | |
| 160 | + | |
| 161 | + public static float getfloat(byte src[], int offset) { | |
| 162 | + return Float.intBitsToFloat(getInt(src, offset)); | |
| 163 | + } | |
| 164 | + | |
| 165 | + public static double getdouble(byte src[], int offset) { | |
| 166 | + return Double.longBitsToDouble(getLong(src, offset)); | |
| 167 | + } | |
| 168 | + | |
| 169 | + public static byte[] setByte(byte dest[], int offset, byte b) { | |
| 170 | + dest[offset] = b; | |
| 171 | + return dest; | |
| 172 | + } | |
| 173 | + | |
| 174 | + public static void setBytes(byte[] dest, int offset, String s) { | |
| 175 | + setBytes(dest, offset, s.getBytes()); | |
| 176 | + } | |
| 177 | + | |
| 178 | + public static byte[] setBytes(byte dest[], int offset, byte src[]) { | |
| 179 | + System.arraycopy(src, 0, dest, offset, src.length); | |
| 180 | + return dest; | |
| 181 | + } | |
| 182 | + | |
| 183 | + public static byte[] setBytes(byte dest[], int offset, byte src[], | |
| 184 | + int len) { | |
| 185 | + System.arraycopy(src, 0, dest, offset, len); | |
| 186 | + return dest; | |
| 187 | + } | |
| 188 | + | |
| 189 | + public static byte[] setShort(byte dest[], int offset, short s) { | |
| 190 | + dest[offset] = (byte) (s >>> 8 & 0xff); | |
| 191 | + dest[offset + 1] = (byte) (s & 0xff); | |
| 192 | + return dest; | |
| 193 | + } | |
| 194 | + | |
| 195 | + public static byte[] setInt(byte dest[], int offset, int i) { | |
| 196 | + dest[offset] = (byte) (i >>> 24 & 0xff); | |
| 197 | + dest[offset + 1] = (byte) (i >>> 16 & 0xff); | |
| 198 | + dest[offset + 2] = (byte) (i >>> 8 & 0xff); | |
| 199 | + dest[offset + 3] = (byte) (i & 0xff); | |
| 200 | + return dest; | |
| 201 | + } | |
| 202 | + | |
| 203 | + public static byte[] setLong(byte dest[], int offset, long l) { | |
| 204 | + setInt(dest, offset, (int) (l >>> 32)); | |
| 205 | + setInt(dest, offset + 4, (int) (l & 0xffffffffL)); | |
| 206 | + return dest; | |
| 207 | + } | |
| 208 | + | |
| 209 | + public static byte[] setFloat(byte dest[], int offset, float f) { | |
| 210 | + return setInt(dest, offset, Float.floatToIntBits(f)); | |
| 211 | + } | |
| 212 | + | |
| 213 | + public static byte[] setDouble(byte dest[], int offset, double d) { | |
| 214 | + return setLong(dest, offset, Double.doubleToLongBits(d)); | |
| 215 | + } | |
| 216 | + | |
| 217 | + public static boolean isEquals(byte b[], String s) { | |
| 218 | + if (b == null || s == null) | |
| 219 | + return false; | |
| 220 | + int slen = s.length(); | |
| 221 | + if (b.length != slen) | |
| 222 | + return false; | |
| 223 | + for (int i = slen; i-- > 0;) | |
| 224 | + if (b[i] != s.charAt(i)) | |
| 225 | + return false; | |
| 226 | + | |
| 227 | + return true; | |
| 228 | + } | |
| 229 | + | |
| 230 | + public static boolean isEquals(byte a[], byte b[]) { | |
| 231 | + if (a == null || b == null) | |
| 232 | + return false; | |
| 233 | + if (a.length != b.length) | |
| 234 | + return false; | |
| 235 | + for (int i = a.length; i-- > 0;) | |
| 236 | + if (a[i] != b[i]) | |
| 237 | + return false; | |
| 238 | + | |
| 239 | + return true; | |
| 240 | + } | |
| 241 | + | |
| 242 | + public static int hexToInt(byte[] b) { | |
| 243 | + int sum = 0; | |
| 244 | + int len = 0; | |
| 245 | + int pos = 0; | |
| 246 | + | |
| 247 | + if (b != null) { | |
| 248 | + len = b.length; | |
| 249 | + | |
| 250 | + for (int i = len - 1; i > 0; i--) { | |
| 251 | + sum += sqrt(BYTE_SIZE, i) * (int) b[pos]; | |
| 252 | + pos++; | |
| 253 | + } | |
| 254 | + sum += b[pos]; | |
| 255 | + } | |
| 256 | + | |
| 257 | + return (sum); | |
| 258 | + } | |
| 259 | + | |
| 260 | + public static int hexToInt(byte[] b, int start, int len) { | |
| 261 | + int sum = 0; | |
| 262 | + int pos = start; | |
| 263 | + | |
| 264 | + if (b != null) { | |
| 265 | + for (int i = len - 1; i > 0; i--) { | |
| 266 | + sum += sqrt(BYTE_SIZE, i) * (int) b[pos]; | |
| 267 | + pos++; | |
| 268 | + } | |
| 269 | + sum += b[pos]; | |
| 270 | + } | |
| 271 | + | |
| 272 | + return (sum); | |
| 273 | + } | |
| 274 | + | |
| 275 | + public static byte[] intToHex(int num, int digit) { | |
| 276 | + byte[] b = new byte[digit]; | |
| 277 | + int[] intArr = makeFunction(num, digit, BYTE_SIZE); | |
| 278 | + | |
| 279 | + for (int i = 0; i < digit; i++) { | |
| 280 | + b[i] = (byte) intArr[i]; | |
| 281 | + } | |
| 282 | + | |
| 283 | + return (b); | |
| 284 | + } | |
| 285 | + | |
| 286 | + private static int[] makeFunction(int num, int digit, int jinso) { | |
| 287 | + int[] fun = new int[digit]; | |
| 288 | + int restNum = num; | |
| 289 | + int pos = 0; | |
| 290 | + | |
| 291 | + for (int i = digit - 1; i > 0; i--) { | |
| 292 | + int quotient = restNum / sqrt(jinso, i); | |
| 293 | + fun[pos++] = quotient; | |
| 294 | + restNum -= (quotient * sqrt(jinso, i)); | |
| 295 | + } | |
| 296 | + fun[pos++] = restNum; | |
| 297 | + | |
| 298 | + return (fun); | |
| 299 | + } | |
| 300 | + | |
| 301 | + private static int sqrt(int num, int count) { | |
| 302 | + int sum = 0; | |
| 303 | + | |
| 304 | + sum = (count >= 1) ? num : 0; | |
| 305 | + for (int i = 1; i < count; i++) { | |
| 306 | + sum = sum * num; | |
| 307 | + } | |
| 308 | + | |
| 309 | + return (sum); | |
| 310 | + } | |
| 311 | + | |
| 312 | + public static boolean arrayComp(byte[] src, byte[] obj) { | |
| 313 | + boolean isSame = true; | |
| 314 | + | |
| 315 | + if (src.length != obj.length) { | |
| 316 | + isSame = false; | |
| 317 | + } else { | |
| 318 | + for (int i = 0; i < src.length; i++) { | |
| 319 | + if (src[i] != obj[i]) { | |
| 320 | + isSame = false; | |
| 321 | + break; | |
| 322 | + } | |
| 323 | + } | |
| 324 | + } | |
| 325 | + | |
| 326 | + return (isSame); | |
| 327 | + } | |
| 328 | + | |
| 329 | + public static String pad0(String str, int size) { | |
| 330 | + char[] zeros = new char[size - str.length()]; | |
| 331 | + for (int i = 0; i < zeros.length; i++) | |
| 332 | + zeros[i] = '0'; | |
| 333 | + return new String(zeros) + str; | |
| 334 | + } | |
| 335 | + | |
| 336 | + public static byte[] convertCharArrayToByteArray(char[] ca) { | |
| 337 | + byte[] ba = new byte[ca.length*2]; | |
| 338 | + java.nio.ByteBuffer.wrap(ba).asCharBuffer().put(ca); | |
| 339 | + return ba; | |
| 340 | + } | |
| 341 | + | |
| 342 | + public static char[] convertByteArrayToCharArray(byte[] ba) { | |
| 343 | + char[] ca = new char[ba.length/2]; | |
| 344 | + java.nio.ByteBuffer.wrap(ba).asCharBuffer().get(ca); | |
| 345 | + return ca; | |
| 346 | + } | |
| 347 | + | |
| 348 | + public static byte[] setNull(byte[] b) { | |
| 349 | + for(int i=0; i<b.length; i++) { | |
| 350 | + b[i] = 0x00; | |
| 351 | + } | |
| 352 | + return b; | |
| 353 | + } | |
| 354 | + | |
| 355 | + | |
| 356 | + // Big Endian: network order | |
| 357 | + public static int toInt(byte[] value) { | |
| 358 | + return (int)( | |
| 359 | + (value[3] & 0xff) | | |
| 360 | + (value[2] & 0xff) << 8 | | |
| 361 | + (value[1] & 0xff) << 16 | | |
| 362 | + (value[0] & 0xff) << 24 ); | |
| 363 | + } | |
| 364 | + | |
| 365 | + // Big Endian: network order | |
| 366 | + public static byte[] toBytes(int value) { | |
| 367 | + byte[] ret = new byte[4]; | |
| 368 | + | |
| 369 | + ret[3] = (byte)(value & 0xff); | |
| 370 | + ret[2] = (byte)(value >> 8 & 0xff); | |
| 371 | + ret[1] = (byte)(value >> 16 & 0xff); | |
| 372 | + ret[0] = (byte)(value >> 24 & 0xff); | |
| 373 | + | |
| 374 | + return ret; | |
| 375 | + } | |
| 376 | + | |
| 377 | + // Little Endian | |
| 378 | + public static int toInt2(byte[] value) { | |
| 379 | + return (int)( | |
| 380 | + (value[0] & 0xff) | | |
| 381 | + (value[1] & 0xff) << 8 | | |
| 382 | + (value[2] & 0xff) << 16 | | |
| 383 | + (value[3] & 0xff) << 24 ); | |
| 384 | + } | |
| 385 | + | |
| 386 | + // Little Endian | |
| 387 | + public static byte[] toBytes2(int value) { | |
| 388 | + byte[] ret = new byte[4]; | |
| 389 | + | |
| 390 | + ret[0] = (byte)(value & 0xff); | |
| 391 | + ret[1] = (byte)(value >> 8 & 0xff); | |
| 392 | + ret[2] = (byte)(value >> 16 & 0xff); | |
| 393 | + ret[3] = (byte)(value >> 24 & 0xff); | |
| 394 | + | |
| 395 | + return ret; | |
| 396 | + } | |
| 397 | + | |
| 398 | + public static byte[] setSpaceAll(byte[] data) { | |
| 399 | + return setAll(data, (byte) ' '); | |
| 400 | + } | |
| 401 | + | |
| 402 | + public static byte[] setAll(byte[] data, byte bt) { | |
| 403 | + int len = data.length; | |
| 404 | + | |
| 405 | + for( int i=0; i<len; i++ ) { | |
| 406 | + data[i] = bt; | |
| 407 | + } | |
| 408 | + | |
| 409 | + return data; | |
| 410 | + } | |
| 411 | + | |
| 412 | + public static byte[] replaceAll(byte[] data, byte from, byte to) { | |
| 413 | + int len = data.length; | |
| 414 | + | |
| 415 | + for( int i=0; i<len; i++ ) { | |
| 416 | + if( data[i] == from ) { | |
| 417 | + data[i] = to; | |
| 418 | + } | |
| 419 | + } | |
| 420 | + | |
| 421 | + return data; | |
| 422 | + } | |
| 423 | +} |
+++ src/main/java/com/munjaon/server/util/MessageUtil.java
... | ... | @@ -0,0 +1,89 @@ |
| 1 | +package com.munjaon.server.util; | |
| 2 | + | |
| 3 | +import java.time.LocalDateTime; | |
| 4 | +import java.time.format.DateTimeFormatter; | |
| 5 | + | |
| 6 | +public final class MessageUtil { | |
| 7 | + public static String getDateFormat(String format) { | |
| 8 | + return LocalDateTime.now().format(DateTimeFormatter.ofPattern(format)); | |
| 9 | + } | |
| 10 | + | |
| 11 | + /** | |
| 12 | + * DateFormat : yyyyMMdd | |
| 13 | + * @return | |
| 14 | + */ | |
| 15 | + public static String getDate() { | |
| 16 | + return getDateFormat("yyyyMMdd"); | |
| 17 | + } | |
| 18 | + | |
| 19 | + /** | |
| 20 | + * DateFormat : yyyyMMddHHmmss | |
| 21 | + * @return | |
| 22 | + */ | |
| 23 | + public static String getTime() { | |
| 24 | + return getDateFormat("yyyyMMddHHmmss"); | |
| 25 | + } | |
| 26 | + | |
| 27 | + public static String doNumber(String spell){ | |
| 28 | + String phoneNumber = ""; | |
| 29 | + if(spell == null){ | |
| 30 | + return phoneNumber; | |
| 31 | + } | |
| 32 | + spell = spell.trim(); | |
| 33 | + int spell_Length = spell.length(); | |
| 34 | + if(spell_Length < 1){ | |
| 35 | + return phoneNumber; | |
| 36 | + } | |
| 37 | + for(int i=0;i<spell_Length;i++){ | |
| 38 | + char eachChar = spell.charAt(i); | |
| 39 | + if( 0x30 <= eachChar && eachChar <= 0x39 ){ | |
| 40 | + phoneNumber += eachChar; | |
| 41 | + } | |
| 42 | + } | |
| 43 | + return phoneNumber; | |
| 44 | + } | |
| 45 | + | |
| 46 | + // 소수점 뒤에 해당하는 자리만큼 자르기 | |
| 47 | + public static String cutFloatNumber(String srcNum, int digit){ | |
| 48 | + String headNum = ""; | |
| 49 | + String tailNum = ""; | |
| 50 | + String retNum = ""; | |
| 51 | + | |
| 52 | + if(!(srcNum == null || srcNum.trim().equals(""))){ | |
| 53 | + srcNum = srcNum.trim(); | |
| 54 | + int index = srcNum.indexOf("."); | |
| 55 | + // 소수점 위치가 0보다 큰경우만 처리 | |
| 56 | + if(index > 0){ | |
| 57 | + headNum = srcNum.substring(0, index); | |
| 58 | + tailNum = srcNum.substring((index + 1), srcNum.length()); | |
| 59 | + | |
| 60 | + if(tailNum.length() == 0){ | |
| 61 | + tailNum = "0"; | |
| 62 | + } | |
| 63 | + if(tailNum.length() > digit){ | |
| 64 | + tailNum = tailNum.substring(0, digit); | |
| 65 | + } | |
| 66 | + retNum = headNum + "." + tailNum; | |
| 67 | + } | |
| 68 | + } | |
| 69 | + | |
| 70 | + return retNum; | |
| 71 | + } | |
| 72 | + | |
| 73 | + // 수신번호 체크하기 | |
| 74 | + public static boolean CheckPhone(String src) { | |
| 75 | + if(src == null || src.trim().length() < 10) { | |
| 76 | + return false; | |
| 77 | + } | |
| 78 | + | |
| 79 | + if(!src.startsWith("0")) { | |
| 80 | + return false; | |
| 81 | + } | |
| 82 | + | |
| 83 | + return true; | |
| 84 | + } | |
| 85 | + // 문자열 공백 제거 | |
| 86 | + public static String trim(String obj) { | |
| 87 | + return StringUtil.trim(obj); | |
| 88 | + } | |
| 89 | +} |
+++ src/main/java/com/munjaon/server/util/StringUtil.java
... | ... | @@ -0,0 +1,167 @@ |
| 1 | +/* | |
| 2 | + * To change this template, choose Tools | Templates | |
| 3 | + * and open the template in the editor. | |
| 4 | + */ | |
| 5 | + | |
| 6 | +package com.munjaon.server.util; | |
| 7 | + | |
| 8 | +import java.text.DecimalFormat; | |
| 9 | +import java.util.ArrayList; | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * 문자열 관련 유틸리티 클래스 | |
| 13 | + * @author JDS | |
| 14 | + */ | |
| 15 | +public final class StringUtil { | |
| 16 | + | |
| 17 | + public static final String SystemEncoding = getSystemEncoding(); | |
| 18 | + | |
| 19 | + public static String getSystemEncoding() { | |
| 20 | + return (new java.io.OutputStreamWriter(System.out)).getEncoding(); | |
| 21 | + } | |
| 22 | + | |
| 23 | + public static String trim(byte[] obj) { | |
| 24 | + if( obj == null || obj.length == 0 ) { | |
| 25 | + return ""; | |
| 26 | + } | |
| 27 | + | |
| 28 | + return (new String(obj)).trim(); | |
| 29 | + } | |
| 30 | + | |
| 31 | + public static String trim(Object obj) { | |
| 32 | + return trim(obj, ""); | |
| 33 | + } | |
| 34 | + | |
| 35 | + public static String trim(Object obj, String dflt) { | |
| 36 | + if( obj == null ) { | |
| 37 | + return dflt; | |
| 38 | + } | |
| 39 | + | |
| 40 | + return ((String)obj).trim(); | |
| 41 | + } | |
| 42 | + | |
| 43 | + public static String ltrim(byte[] obj) { | |
| 44 | + return ltrim(new String(obj)); | |
| 45 | + } | |
| 46 | + | |
| 47 | + public static String ltrim(String obj) { | |
| 48 | + return ltrim(obj.toCharArray()); | |
| 49 | + } | |
| 50 | + | |
| 51 | + public static String ltrim(char[] obj) { | |
| 52 | + int len = obj.length; | |
| 53 | + int idx = 0; | |
| 54 | + | |
| 55 | + while( idx < len && obj[idx] <= ' ' ) { | |
| 56 | + idx++; | |
| 57 | + } | |
| 58 | + | |
| 59 | + return new String(obj, idx, len-idx); | |
| 60 | + } | |
| 61 | + | |
| 62 | + public static String rtrim(byte[] obj) { | |
| 63 | + return rtrim(new String(obj)); | |
| 64 | + } | |
| 65 | + | |
| 66 | + public static String rtrim(String obj) { | |
| 67 | + return rtrim(obj.toCharArray()); | |
| 68 | + } | |
| 69 | + | |
| 70 | + public static String rtrim(char[] obj) { | |
| 71 | + int len = obj.length; | |
| 72 | + int idx = len-1; | |
| 73 | + | |
| 74 | + while( idx >= 0 && obj[idx] <= ' ' ) { | |
| 75 | + idx--; | |
| 76 | + } | |
| 77 | + | |
| 78 | + return new String(obj, 0, idx+1); | |
| 79 | + } | |
| 80 | + | |
| 81 | + public static String replaceAll(String src, String from, String to) { | |
| 82 | + StringBuilder sbuf = new StringBuilder(); | |
| 83 | + | |
| 84 | + int len = from.length(); | |
| 85 | + int idx = 0; | |
| 86 | + int stx = 0; | |
| 87 | + | |
| 88 | + while( (idx=src.indexOf(from, stx)) > -1 ) { | |
| 89 | + sbuf.append(src.substring(stx, idx)); | |
| 90 | + sbuf.append(to); | |
| 91 | + stx=idx+len; | |
| 92 | + } | |
| 93 | + | |
| 94 | + sbuf.append(src.substring(stx)); | |
| 95 | + | |
| 96 | + return sbuf.toString(); | |
| 97 | + } | |
| 98 | + | |
| 99 | + public static String[] split(String sSrc, String sDelim) { | |
| 100 | + ArrayList aList = new ArrayList(); | |
| 101 | + | |
| 102 | + String sTmp; | |
| 103 | + int len = sDelim.length(); | |
| 104 | + int idx = 0; | |
| 105 | + int stx = 0; | |
| 106 | + | |
| 107 | + while( (idx=sSrc.indexOf(sDelim, stx)) > -1 ) { | |
| 108 | + sTmp = sSrc.substring(stx, idx); | |
| 109 | + aList.add(sTmp); | |
| 110 | + stx=idx+len; | |
| 111 | + } | |
| 112 | + | |
| 113 | + if( stx <= sSrc.length() ) { | |
| 114 | + aList.add(sSrc.substring(stx)); | |
| 115 | + } | |
| 116 | + | |
| 117 | + String[] sRet = new String[aList.size()]; | |
| 118 | + | |
| 119 | + for( int i=0; i<aList.size(); i++ ) { | |
| 120 | + sRet[i] = (String) aList.get(i); | |
| 121 | + } | |
| 122 | + | |
| 123 | + return sRet; | |
| 124 | + } | |
| 125 | + | |
| 126 | + public static String substring(String obj, int idx, int length) { | |
| 127 | + if( obj.getBytes().length <= idx ) { | |
| 128 | + return ""; | |
| 129 | + } | |
| 130 | + | |
| 131 | + if( obj.getBytes().length <= length ) { | |
| 132 | + return obj; | |
| 133 | + } | |
| 134 | + | |
| 135 | + int totallen=0; | |
| 136 | + int i=idx; | |
| 137 | + for( i=idx; i<obj.length(); i++ ) { | |
| 138 | + totallen += obj.substring(i, i+1).getBytes().length; | |
| 139 | + | |
| 140 | + if( length < totallen ) { | |
| 141 | + break; | |
| 142 | + } | |
| 143 | + } | |
| 144 | + | |
| 145 | + return obj.substring(idx, i); | |
| 146 | + } | |
| 147 | + | |
| 148 | + public static String substring(String obj, int length) { | |
| 149 | + return substring(obj, 0, length); | |
| 150 | + } | |
| 151 | + | |
| 152 | + public static String numFilter(String src) { | |
| 153 | + return src.replaceAll("[^0-9]", ""); | |
| 154 | + } | |
| 155 | + | |
| 156 | + public static String toNumberFormat(Object obj, String fmt) { | |
| 157 | + DecimalFormat df = new DecimalFormat(fmt); | |
| 158 | + return df.format(obj); | |
| 159 | + } | |
| 160 | + | |
| 161 | + public static String pad0(String str, int size) { | |
| 162 | + char[] zeros = new char[size - str.length()]; | |
| 163 | + for (int i = 0; i < zeros.length; i++) | |
| 164 | + zeros[i] = '0'; | |
| 165 | + return new String(zeros) + str; | |
| 166 | + } | |
| 167 | +} |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?