In theory, this should work as well to read strings.
It could be more effecient w/r/t generating garbage. I would have just replaced readUTF() in ObjectInputStream and switch us to unmodified-UTF8 for all streaming needs. Wouldn't that be simpler? git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6041 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -24,14 +24,15 @@ package com.threerings.io;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
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 java.io.InputStreamReader;
|
||||||
|
|
||||||
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.common.io.LineReader;
|
||||||
|
|
||||||
import com.samskivert.util.StringUtil;
|
import com.samskivert.util.StringUtil;
|
||||||
|
|
||||||
@@ -314,18 +315,10 @@ public class ObjectInputStream extends DataInputStream
|
|||||||
public String readUnmodifiedUTF ()
|
public String readUnmodifiedUTF ()
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
// find out how many raw bytes of UTF8 data there is
|
if (_reader == null) {
|
||||||
int utflen = readUnsignedShort();
|
_reader = new LineReader(new InputStreamReader(this, Charsets.UTF_8));
|
||||||
// read precisely that many into a buffer
|
}
|
||||||
byte[] bbuf = new byte[utflen];
|
return _reader.readLine();
|
||||||
in.read(bbuf);
|
|
||||||
|
|
||||||
// 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
|
||||||
@@ -354,6 +347,8 @@ public class ObjectInputStream extends DataInputStream
|
|||||||
/** An optional set of class name translations to use when unserializing objects. */
|
/** An optional set of class name translations to use when unserializing objects. */
|
||||||
protected HashMap<String, String> _translations;
|
protected HashMap<String, String> _translations;
|
||||||
|
|
||||||
|
protected LineReader _reader;
|
||||||
|
|
||||||
/** Used to activate verbose debug logging. */
|
/** Used to activate verbose debug logging. */
|
||||||
protected static final boolean STREAM_DEBUG = false;
|
protected static final boolean STREAM_DEBUG = false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user