mirror of https://github.com/apache/lucene.git
refactor: make javabin use ByteUtils for encoding/decoding
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1236860 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
02d4bd91df
commit
7784c42dd1
|
@ -16,6 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.solr.common.util;
|
package org.apache.solr.common.util;
|
||||||
|
|
||||||
|
import org.apache.noggit.CharArr;
|
||||||
import org.apache.solr.common.SolrDocument;
|
import org.apache.solr.common.SolrDocument;
|
||||||
import org.apache.solr.common.SolrDocumentList;
|
import org.apache.solr.common.SolrDocumentList;
|
||||||
import org.apache.solr.common.SolrInputDocument;
|
import org.apache.solr.common.SolrInputDocument;
|
||||||
|
@ -470,39 +471,16 @@ public class JavaBinCodec {
|
||||||
}
|
}
|
||||||
|
|
||||||
byte[] bytes;
|
byte[] bytes;
|
||||||
char[] chars;
|
CharArr arr = new CharArr();
|
||||||
|
|
||||||
public String readStr(FastInputStream dis) throws IOException {
|
public String readStr(FastInputStream dis) throws IOException {
|
||||||
int sz = readSize(dis);
|
int sz = readSize(dis);
|
||||||
if (chars == null || chars.length < sz) chars = new char[sz];
|
|
||||||
if (bytes == null || bytes.length < sz) bytes = new byte[sz];
|
if (bytes == null || bytes.length < sz) bytes = new byte[sz];
|
||||||
dis.readFully(bytes, 0, sz);
|
dis.readFully(bytes, 0, sz);
|
||||||
int outUpto=0;
|
|
||||||
for (int i = 0; i < sz;) {
|
arr.reset();
|
||||||
final int b = bytes[i++]&0xff;
|
ByteUtils.UTF8toUTF16(bytes, 0, sz, arr);
|
||||||
final int ch;
|
return arr.toString();
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeInt(int val) throws IOException {
|
public void writeInt(int val) throws IOException {
|
||||||
|
|
Loading…
Reference in New Issue