Occam's razor.

These String methods have been around since jdk1.1...
This commit is contained in:
Ray J. Greenwell
2015-01-20 17:22:46 -08:00
parent 34f98e1c46
commit 39d1356e56
2 changed files with 4 additions and 24 deletions
@@ -24,11 +24,9 @@ package com.threerings.io;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.io.ByteArrayInputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
@@ -319,13 +317,7 @@ public class ObjectInputStream extends DataInputStream
// read precisely that many into a buffer // read precisely that many into a buffer
byte[] bbuf = new byte[utflen]; byte[] bbuf = new byte[utflen];
in.read(bbuf); in.read(bbuf);
return new String(bbuf, "UTF-8");
// decode the UTF-8 stream into a character buffer
char[] cbuf = new char[utflen];
int read = new InputStreamReader(new ByteArrayInputStream(bbuf), "UTF-8").read(cbuf);
// create and return the string given the number of decoded characters
return String.copyValueOf(cbuf, 0, read);
} }
@Override @Override
@@ -23,11 +23,9 @@ package com.threerings.io;
import java.util.Map; import java.util.Map;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.OutputStreamWriter;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
@@ -306,19 +304,9 @@ public class ObjectOutputStream extends DataOutputStream
public void writeUnmodifiedUTF (String str) public void writeUnmodifiedUTF (String str)
throws IOException throws IOException
{ {
// prepare a buffer to accept the encoded UTF-8 byte[] bytes = str.getBytes("UTF-8");
ByteArrayOutputStream baos = new ByteArrayOutputStream(); writeShort(bytes.length);
OutputStreamWriter osw = new OutputStreamWriter(baos, "UTF-8"); write(bytes);
// do the deed
osw.write(str);
osw.flush();
// now that we know how many bytes we'll need, write that number to the stream
writeShort(baos.size());
// then finally the bytes themselves
write(baos.toByteArray());
} }
/** Used to map classes to numeric codes and the {@link Streamer} instance used to write /** Used to map classes to numeric codes and the {@link Streamer} instance used to write