File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
src/main/java/JavaBWAPIBackend Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 44
55import java .nio .ByteBuffer ;
66import java .nio .ByteOrder ;
7+ import java .nio .CharBuffer ;
8+ import java .nio .charset .Charset ;
9+ import java .nio .charset .CharsetEncoder ;
710import java .nio .charset .StandardCharsets ;
811
912public class Client {
@@ -438,12 +441,18 @@ public class Event {
438441 public int eventStringCount () { return sharedMemory .getInt (StringOffset ); }
439442 public String eventString (int s ) { return parseString (StringOffset + 4 + 256 * s , 256 ); }
440443
444+
445+ private final CharsetEncoder enc = Charset .forName ("ISO-8859-1" ).newEncoder ();
446+
441447 public int addString (String s ) {
442- if (s .length () >= 1024 )
448+ int len = s .length () + 1 ;
449+ if (len >= 1024 )
443450 throw new StringIndexOutOfBoundsException ();
444451 int at = sharedMemory .getInt (StringOffset + 256004 );
452+ byte b [] = new byte [len ];
453+ enc .encode (CharBuffer .wrap (s ), ByteBuffer .wrap (b ), true );
445454 sharedMemory .position (StringOffset + 256008 + at * 1024 );
446- sharedMemory .put (s . getBytes ( StandardCharsets . ISO_8859_1 ) , 0 , s . length () );
455+ sharedMemory .put (b , 0 , len );
447456 sharedMemory .position (0 );
448457 sharedMemory .putInt (StringOffset + 256004 , at + 1 );
449458 return at ;
You can’t perform that action at this time.
0 commit comments