diff --git a/java/libraries/net/src/processing/net/Client.java b/java/libraries/net/src/processing/net/Client.java
index 5598c355f..e9636fbe7 100644
--- a/java/libraries/net/src/processing/net/Client.java
+++ b/java/libraries/net/src/processing/net/Client.java
@@ -29,6 +29,7 @@ import processing.core.*;
import java.io.*;
import java.lang.reflect.*;
import java.net.*;
+import java.nio.charset.StandardCharsets;
/**
*
@@ -596,11 +597,10 @@ public class Client implements Runnable {
/**
*
- * Returns the all the data from the buffer as a String. This method
- * assumes the incoming characters are ASCII. If you want to transfer
- * Unicode data, first convert the String to a byte stream in the
- * representation of your choice (i.e. UTF8 or two-byte Unicode data), and
- * send it as a byte array.
+ * Returns the all the data from the buffer as a String.
+ *
+ * In 4.0 beta 3, changed to using UTF-8 as the encoding,
+ * otherwise the behavior is platform-dependent.
*
* @webref client
* @usage application
@@ -609,7 +609,7 @@ public class Client implements Runnable {
public String readString() {
byte b[] = readBytes();
if (b == null) return null;
- return new String(b);
+ return new String(b, StandardCharsets.UTF_8);
}
@@ -619,10 +619,8 @@ public class Client implements Runnable {
* null if it doesn't find what you're looking for.
*
*
Advanced
- *
- * If you want to move Unicode data, you can first convert the
- * String to a byte stream in the representation of your choice
- * (i.e. UTF8 or two-byte Unicode data), and send it as a byte array.
+ * In 4.0 beta 3, changed to using UTF-8 as the encoding,
+ * otherwise the behavior is platform-dependent.
*
* @webref client
* @usage application
@@ -632,7 +630,7 @@ public class Client implements Runnable {
public String readStringUntil(int interesting) {
byte b[] = readBytesUntil(interesting);
if (b == null) return null;
- return new String(b);
+ return new String(b, StandardCharsets.UTF_8);
}
@@ -679,20 +677,11 @@ public class Client implements Runnable {
/**
- * Advanced
- * Write a String to the output. Note that this doesn't account
- * for Unicode (two bytes per char), nor will it send UTF8
- * characters.. It assumes that you mean to send a byte buffer
- * (most often the case for networking and serial i/o) and
- * will only use the bottom 8 bits of each char in the string.
- * (Meaning that internally it uses String.getBytes)
- *
- * If you want to move Unicode data, you can first convert the
- * String to a byte stream in the representation of your choice
- * (i.e. UTF8 or two-byte Unicode data), and send it as a byte array.
+ * In 4.0 beta 3, changed to using UTF-8 as the encoding,
+ * otherwise the behavior is platform-dependent.
*/
public void write(String data) {
- write(data.getBytes());
+ write(data.getBytes(StandardCharsets.UTF_8));
}
diff --git a/todo.txt b/todo.txt
index cc97ea1e4..24b141696 100755
--- a/todo.txt
+++ b/todo.txt
@@ -12,6 +12,9 @@ X skip fonts starting . and # because they're likely to confuse users
X get rid of version numbers in the name of the batik.jar file
X ffmpeg not downloading correctly on M1 machines
X https://github.com/processing/processing4/issues/319
+X use UTF-8 for readString() and write() in net client
+X avoids platform-specific behavior; Java 18 also making UTF-8 the default
+X https://github.com/processing/processing4/issues/336
sam
X Error when calling smooth() on PGraphics
@@ -30,8 +33,6 @@ before release
_ disable Theme Engine from Tools (in build.xml)
-
-
before beta 3
_ Add support for localizing contributions
_ https://github.com/processing/processing4/pull/237 (updated by Andres)