You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by yo...@apache.org on 2012/01/27 20:45:26 UTC

svn commit: r1236860 - /lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java

Author: yonik
Date: Fri Jan 27 19:45:26 2012
New Revision: 1236860

URL: http://svn.apache.org/viewvc?rev=1236860&view=rev
Log:
refactor: make javabin use ByteUtils for encoding/decoding

Modified:
    lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java

Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java?rev=1236860&r1=1236859&r2=1236860&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java (original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/util/JavaBinCodec.java Fri Jan 27 19:45:26 2012
@@ -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 {