From: Mark Slee Date: Sat, 3 Nov 2007 04:48:43 +0000 (+0000) Subject: Make Java TbinaryProtocol enfore UTF-8 X-Git-Tag: 0.2.0~1151 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=52182d674eff80ac99da38b34273279bce9a327b;p=common%2Fthrift.git Make Java TbinaryProtocol enfore UTF-8 Summary: Java Strings have to have an encoding, they can't just be binary. The constructor and getBytes() method enforce this, so we are standardizing on UTF-8 to avoid string-mangling. Reviewed By: dreiss Test Plan: Code all works the exact same in the normal case, and doesn't mangle characters beyond ASCII or ISO-LATIN-1 git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665321 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/java/src/protocol/TBinaryProtocol.java b/lib/java/src/protocol/TBinaryProtocol.java index 7dff4858..feb05f98 100644 --- a/lib/java/src/protocol/TBinaryProtocol.java +++ b/lib/java/src/protocol/TBinaryProtocol.java @@ -153,7 +153,7 @@ public class TBinaryProtocol extends TProtocol { } public void writeString(String str) throws TException { - byte[] dat = str.getBytes(); + byte[] dat = str.getBytes("UTF-8"); writeI32(dat.length); trans_.write(dat, 0, dat.length); } @@ -292,7 +292,7 @@ public class TBinaryProtocol extends TProtocol { public String readStringBody(int size) throws TException { byte[] buf = new byte[size]; trans_.readAll(buf, 0, size); - return new String(buf); + return new String(buf, "UTF-8"); } public byte[] readBinary() throws TException {