Drive-by: a bit of modernization & warning cleanup, UTF-8 edition.

This commit is contained in:
Ray J. Greenwell
2026-03-21 15:18:39 -07:00
parent d7b4e10430
commit 99f797f66a
6 changed files with 18 additions and 20 deletions
@@ -5,6 +5,8 @@
package com.threerings.io;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -374,8 +376,7 @@ public class ObjectInputStream extends DataInputStream
// read precisely that many into a buffer
byte[] bbuf = new byte[utflen];
in.read(bbuf);
return new String(bbuf, "UTF-8");
//return new String(bbuf, Charsets.UTF_8); // TODO Java 6 (Charsets is from guava)
return new String(bbuf, UTF_8);
}
@Override
@@ -5,6 +5,8 @@
package com.threerings.io;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.util.Map;
import java.io.DataOutputStream;
@@ -288,8 +290,7 @@ public class ObjectOutputStream extends DataOutputStream
public void writeUnmodifiedUTF (String str)
throws IOException
{
// byte[] bytes = str.getBytes(Charsets.UTF_8); // TODO Java 6 (Charsets is from guava)
byte[] bytes = str.getBytes("UTF-8");
byte[] bytes = str.getBytes(UTF_8);
writeShort(bytes.length);
write(bytes);
}
@@ -5,14 +5,14 @@
package com.threerings.nio;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.util.Arrays;
import com.google.common.base.Charsets;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@@ -78,11 +78,7 @@ public class PolicyServer extends ConnectionManager
policy.append(" <allow-access-from domain=\"*\" to-ports=\"*\"/>\n");
policy.append("</cross-domain-policy>\n\n");
try {
_policy = policy.toString().getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException("UTF-8 encoding missing; this vm is broken", e);
}
_policy = policy.toString().getBytes(UTF_8);
start();
}
@@ -116,7 +112,7 @@ public class PolicyServer extends ConnectionManager
sendPolicy(this);
return buf.position();
}
log.warning("Bad policy request", "request", new String(buf.array(), Charsets.UTF_8));
log.warning("Bad policy request", "request", new String(buf.array(), UTF_8));
_cmgr.closeConnection(this);
} catch (IOException e) {
@@ -138,7 +134,7 @@ public class PolicyServer extends ConnectionManager
protected byte[] _policy;
protected static final byte[] REQUEST = "<policy-file-request/>\0".getBytes(Charsets.UTF_8);
protected static final byte[] REQUEST = "<policy-file-request/>\0".getBytes(UTF_8);
protected static final int MASTER_PORT = 843;
}
@@ -5,6 +5,8 @@
package com.threerings.presents.client;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.EOFException;
import java.io.IOException;
import java.io.InterruptedIOException;
@@ -823,7 +825,7 @@ public class BlockingCommunicator extends Communicator
shutdown();
return;
}
_secret = _client.getCredentials().getDatagramSecret().getBytes("UTF-8");
_secret = _client.getCredentials().getDatagramSecret().getBytes(UTF_8);
// create our various streams
_bout = new ByteBufferOutputStream();
@@ -5,6 +5,8 @@
package com.threerings.presents.server.net;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
@@ -126,11 +128,7 @@ public class PresentsConnection extends Connection
*/
public void setDatagramSecret (String secret)
{
try {
_datagramSecret = secret.getBytes("UTF-8");
} catch (Exception e) {
_datagramSecret = new byte[0]; // shouldn't happen
}
_datagramSecret = secret.getBytes(UTF_8);
}
/**
@@ -163,7 +163,7 @@ public abstract class GenTask extends Task
}
log("Writing file " + outputPath, Project.MSG_VERBOSE);
new PrintWriter(dest, "UTF-8").append(output).close();
new PrintWriter(dest, UTF_8).append(output).close();
}
/**