Index: src/java/com/thoughtworks/xstream/io/binary/Token.java =================================================================== --- src/java/com/thoughtworks/xstream/io/binary/Token.java (revision 1688) +++ src/java/com/thoughtworks/xstream/io/binary/Token.java (working copy) @@ -121,7 +121,15 @@ } protected void writeString(DataOutput out, String string) throws IOException { - out.writeUTF(string); + if (string == null) { + out.writeInt(-1); + } else { + final int length = string.length(); + out.writeInt(length); + if(length > 0) { + out.write(string.getBytes()); + } + } } protected long readId(DataInput in, byte idType) throws IOException { @@ -140,8 +148,17 @@ } protected String readString(DataInput in) throws IOException { - return in.readUTF(); - } + final int length = in.readInt(); + if (length == -1) { + return null; + } else if (length == 0) { + return ""; + } else { + final byte[] buf = new byte[length]; + in.readFully(buf); + return new String(buf); + } + } public static class Formatter { Index: src/test/com/thoughtworks/xstream/io/binary/TokenTest.java =================================================================== --- src/test/com/thoughtworks/xstream/io/binary/TokenTest.java (revision 1688) +++ src/test/com/thoughtworks/xstream/io/binary/TokenTest.java (working copy) @@ -70,6 +70,15 @@ assertEquals(9, buffer.size()); // One byte already written for token type. assertEquals(token, readOneToken()); } + + public void testValueTokenSupportsStringOver65K() throws IOException { + StringBuffer sb = new StringBuffer(); + for(int i=0; i<75000; i++) { + sb.append('X'); + } + tokenFormatter.write(out, new Token.Value(sb.toString())); + tokenFormatter.read(new DataInputStream(new ByteArrayInputStream(buffer.toByteArray()))); + } private Token readOneToken() throws IOException { return tokenFormatter.read(new DataInputStream(new ByteArrayInputStream(buffer.toByteArray())));