Skip to content

Apache Lucene open-source search software

refactor: make javabin use ByteUtils for encoding/decoding

Yonik Seeley7784c42dd1ce
diff --git a/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java b/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java
index 4f506b766c8..0f31a1c76fa 100755
--- a/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java
+++ b/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java
@@ -16,6 +16,7 @@
*/
package org.apache.solr.common.util;
+import org.apache.noggit.CharArr;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.SolrInputDocument;
@@ -470,39 +471,16 @@ public class JavaBinCodec {
}
byte[] bytes;
- char[] chars;
+ CharArr arr = new CharArr();
public String readStr(FastInputStream dis) throws IOException {
int sz = readSize(dis);
- if (chars == null || chars.length < sz) chars = new char[sz];
if (bytes == null || bytes.length < sz) bytes = new byte[sz];
dis.readFully(bytes, 0, sz);
- int outUpto=0;
- for (int i = 0; i < sz;) {
- final int b = bytes[i++]&0xff;
- final int ch;
- if (b < 0xc0) {
- assert b < 0x80;
- ch = b;
- } else if (b < 0xe0) {
- ch = ((b&0x1f)<<6) + (bytes[i++]&0x3f);
- } else if (b < 0xf0) {
- ch = ((b&0xf)<<12) + ((bytes[i++]&0x3f)<<6) + (bytes[i++]&0x3f);
- } else {
- assert b < 0xf8;
- ch = ((b&0x7)<<18) + ((bytes[i++]&0x3f)<<12) + ((bytes[i++]&0x3f)<<6) + (bytes[i++]&0x3f);
- }
- if (ch <= 0xFFFF) {
- // target is a character <= 0xFFFF
- chars[outUpto++] = (char) ch;
- } else {
- // target is a character in range 0xFFFF - 0x10FFFF
- final int chHalf = ch - 0x10000;
- chars[outUpto++] = (char) ((chHalf >> 0xA) + 0xD800);
- chars[outUpto++] = (char) ((chHalf & 0x3FF) + 0xDC00);
- }
- }
- return new String(chars, 0, outUpto);
+
+ arr.reset();
+ ByteUtils.UTF8toUTF16(bytes, 0, sz, arr);
+ return arr.toString();
}
public void writeInt(int val) throws IOException {