2929import java .io .*;
3030import java .lang .reflect .*;
3131import java .net .*;
32+ import java .nio .charset .StandardCharsets ;
3233
3334/**
3435 *
@@ -596,11 +597,10 @@ public int readBytesUntil(int interesting, byte byteBuffer[]) {
596597
597598 /**
598599 *
599- * Returns the all the data from the buffer as a <b>String</b>. This method
600- * assumes the incoming characters are ASCII. If you want to transfer
601- * Unicode data, first convert the String to a byte stream in the
602- * representation of your choice (i.e. UTF8 or two-byte Unicode data), and
603- * send it as a byte array.
600+ * Returns the all the data from the buffer as a <b>String</b>.
601+ *
602+ * In 4.0 beta 3, changed to using UTF-8 as the encoding,
603+ * otherwise the behavior is platform-dependent.
604604 *
605605 * @webref client
606606 * @usage application
@@ -609,7 +609,7 @@ public int readBytesUntil(int interesting, byte byteBuffer[]) {
609609 public String readString () {
610610 byte b [] = readBytes ();
611611 if (b == null ) return null ;
612- return new String (b );
612+ return new String (b , StandardCharsets . UTF_8 );
613613 }
614614
615615
@@ -619,10 +619,8 @@ public String readString() {
619619 * <b>null</b> if it doesn't find what you're looking for.
620620 *
621621 * <h3>Advanced</h3>
622- * <p/>
623- * If you want to move Unicode data, you can first convert the
624- * String to a byte stream in the representation of your choice
625- * (i.e. UTF8 or two-byte Unicode data), and send it as a byte array.
622+ * In 4.0 beta 3, changed to using UTF-8 as the encoding,
623+ * otherwise the behavior is platform-dependent.
626624 *
627625 * @webref client
628626 * @usage application
@@ -632,7 +630,7 @@ public String readString() {
632630 public String readStringUntil (int interesting ) {
633631 byte b [] = readBytesUntil (interesting );
634632 if (b == null ) return null ;
635- return new String (b );
633+ return new String (b , StandardCharsets . UTF_8 );
636634 }
637635
638636
@@ -679,20 +677,11 @@ public void write(byte data[]) {
679677
680678
681679 /**
682- * <h3>Advanced</h3>
683- * Write a String to the output. Note that this doesn't account
684- * for Unicode (two bytes per char), nor will it send UTF8
685- * characters.. It assumes that you mean to send a byte buffer
686- * (most often the case for networking and serial i/o) and
687- * will only use the bottom 8 bits of each char in the string.
688- * (Meaning that internally it uses String.getBytes)
689- *
690- * If you want to move Unicode data, you can first convert the
691- * String to a byte stream in the representation of your choice
692- * (i.e. UTF8 or two-byte Unicode data), and send it as a byte array.
680+ * In 4.0 beta 3, changed to using UTF-8 as the encoding,
681+ * otherwise the behavior is platform-dependent.
693682 */
694683 public void write (String data ) {
695- write (data .getBytes ());
684+ write (data .getBytes (StandardCharsets . UTF_8 ));
696685 }
697686
698687
0 commit comments