423 |
if (sum > 65535) |
if (sum > 65535) |
424 |
throw new UTFDataFormatException (); |
throw new UTFDataFormatException (); |
425 |
|
|
426 |
writeShort (sum); |
int pos = 0; |
427 |
|
byte[] buf = new byte[sum]; |
428 |
|
|
429 |
for (int i = 0; i < len; ++i) |
for (int i = 0; i < len; ++i) |
430 |
{ |
{ |
431 |
char c = value.charAt(i); |
char c = value.charAt(i); |
432 |
if (c >= '\u0001' && c <= '\u007f') |
if (c >= '\u0001' && c <= '\u007f') |
433 |
write (c); |
buf[pos++] = (byte) c; |
434 |
else if (c == '\u0000' || (c >= '\u0080' && c <= '\u07ff')) |
else if (c == '\u0000' || (c >= '\u0080' && c <= '\u07ff')) |
435 |
{ |
{ |
436 |
write (0xc0 | (0x1f & (c >> 6))); |
buf[pos++] = (byte) (0xc0 | (0x1f & (c >> 6))); |
437 |
write (0x80 | (0x3f & c)); |
buf[pos++] = (byte) (0x80 | (0x3f & c)); |
438 |
} |
} |
439 |
else |
else |
440 |
{ |
{ |
441 |
// JSL says the first byte should be or'd with 0xc0, but |
// JSL says the first byte should be or'd with 0xc0, but |
442 |
// that is a typo. Unicode says 0xe0, and that is what is |
// that is a typo. Unicode says 0xe0, and that is what is |
443 |
// consistent with DataInputStream. |
// consistent with DataInputStream. |
444 |
write (0xe0 | (0x0f & (c >> 12))); |
buf[pos++] = (byte) (0xe0 | (0x0f & (c >> 12))); |
445 |
write (0x80 | (0x3f & (c >> 6))); |
buf[pos++] = (byte) (0x80 | (0x3f & (c >> 6))); |
446 |
write (0x80 | (0x3f & c)); |
buf[pos++] = (byte) (0x80 | (0x3f & c)); |
447 |
} |
} |
448 |
} |
} |
449 |
|
|
450 |
|
writeShort (sum); |
451 |
|
write(buf, 0, sum); |
452 |
} |
} |
453 |
|
|
454 |
} // class DataOutputStream |
} // class DataOutputStream |