|
4 | 4 |
|
5 | 5 | import java.nio.ByteBuffer; |
6 | 6 | import java.nio.ByteOrder; |
| 7 | +import java.nio.CharBuffer; |
| 8 | +import java.nio.charset.Charset; |
| 9 | +import java.nio.charset.CharsetEncoder; |
7 | 10 | import java.nio.charset.StandardCharsets; |
8 | 11 |
|
9 | 12 | public class Client { |
@@ -438,12 +441,18 @@ public class Event { |
438 | 441 | public int eventStringCount() { return sharedMemory.getInt(StringOffset); } |
439 | 442 | public String eventString(int s) { return parseString(StringOffset + 4 + 256 * s, 256); } |
440 | 443 |
|
| 444 | + |
| 445 | + private final CharsetEncoder enc = Charset.forName("ISO-8859-1").newEncoder(); |
| 446 | + |
441 | 447 | public int addString(String s) { |
442 | | - if(s.length() >= 1024) |
| 448 | + int len = s.length() + 1; |
| 449 | + if(len >= 1024) |
443 | 450 | throw new StringIndexOutOfBoundsException(); |
444 | 451 | int at = sharedMemory.getInt(StringOffset + 256004); |
| 452 | + byte b[] = new byte[len]; |
| 453 | + enc.encode(CharBuffer.wrap(s), ByteBuffer.wrap(b), true); |
445 | 454 | sharedMemory.position(StringOffset + 256008 + at * 1024); |
446 | | - sharedMemory.put(s.getBytes(StandardCharsets.ISO_8859_1), 0, s.length()); |
| 455 | + sharedMemory.put(b, 0, len); |
447 | 456 | sharedMemory.position(0); |
448 | 457 | sharedMemory.putInt(StringOffset + 256004, at + 1); |
449 | 458 | return at; |
|
0 commit comments