엠

String 을 UTF8 encoding 하기

ZipOutputStream 에 있는 private method 입니다.

String을 UTF8 encoding 해서 bytes array 로 만들어 주는군요. --;

/*
* Returns an array of bytes representing the UTF8 encoding
* of the specified String.
*/
private static byte[] getUTF8Bytes(String s) {
char[] c = s.toCharArray();
int len = c.length;
// Count the number of encoded bytes...
int count = 0;
for (int i = 0; i < len; i++) {
int ch = c[i];
if (ch <= 0x7f) {
count++;
} else if (ch <= 0x7ff) {
count += 2;
} else {
count += 3;
}
}
// Now return the encoded bytes...
byte[] b = new byte[count];
int off = 0;
for (int i = 0; i < len; i++) {
int ch = c[i];
if (ch <= 0x7f) {
b[off++] = (byte)ch;
} else if (ch <= 0x7ff) {
b[off++] = (byte)((ch >> 6) | 0xc0);
b[off++] = (byte)((ch & 0x3f) | 0x80);
} else {
b[off++] = (byte)((ch >> 12) | 0xe0);
b[off++] = (byte)(((ch >> 6) & 0x3f) | 0x80);
b[off++] = (byte)((ch & 0x3f) | 0x80);
}
}
return b;
}<div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 16:57:14 JavaScript에서 이동 됨]</div>
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

8,188건
+
제목 글쓴이 날짜 조회
12-01-11 조회 2,755
12-01-11 조회 1.2만
12-01-10 조회 2,852
12-01-08 조회 3,444
12-01-05 조회 5,335
11-12-29 조회 3,053
11-12-27 조회 2,839
11-12-25 조회 3,021
11-12-22 조회 3,454
11-12-14 조회 2,919
11-12-12 조회 3,540
11-11-28 조회 3,377
10-10-19 조회 2,835
08-09-05 조회 3,756
08-09-05 조회 3,571
08-06-14 조회 3,315
08-04-22 조회 3,591
08-04-17 조회 3,596
07-10-03 조회 4,212
07-10-03 조회 3,607
07-10-03 조회 7,289
07-10-03 조회 4,568
07-10-03 조회 3,265
07-10-03 조회 2,855
07-10-02 조회 3,571
07-10-02 조회 3,100
07-09-27 조회 5,021
07-09-27 조회 3,845
06-09-26 조회 3,515
06-09-26 조회 4,732
06-09-22 조회 3,908
06-09-22 조회 3,522
06-09-22 조회 4,268
06-09-21 조회 4,204
06-08-18 조회 3,693
05-11-30 조회 4,743
05-07-15 조회 4,591
05-03-23 조회 4,655
05-03-14 조회 3,321
05-03-13 조회 2,696
04-08-05 조회 5,769