List of usage examples for org.apache.lucene.analysis.tokenattributes CharTermAttribute setLength
public CharTermAttribute setLength(int length);
From source file:com.sindicetech.siren.analysis.attributes.NodeNumericTermAttributeImpl.java
License:Open Source License
private void bytesRefToChar(final CharTermAttribute termAtt) { final char[] buffer; final int prefixSize = numericTypeCharArray.length + precisionStepCharArray.length; switch (valueSize) { case 64:/* w ww. j a va 2 s.co m*/ NumericUtils.longToPrefixCoded(value, shift, bytesRef); buffer = termAtt.resizeBuffer(NumericUtils.BUF_SIZE_LONG + prefixSize); break; case 32: NumericUtils.intToPrefixCoded((int) value, shift, bytesRef); buffer = termAtt.resizeBuffer(NumericUtils.BUF_SIZE_INT + prefixSize); break; default: // should not happen throw new IllegalArgumentException("valueSize must be 32 or 64"); } // Prepend the numericType System.arraycopy(numericTypeCharArray, 0, buffer, 0, numericTypeCharArray.length); // Prepend the precision step System.arraycopy(precisionStepCharArray, 0, buffer, numericTypeCharArray.length, precisionStepCharArray.length); // append the numeric encoded value for (int i = bytesRef.offset; i < bytesRef.length; i++) { buffer[prefixSize + i] = (char) bytesRef.bytes[i]; } termAtt.setLength(prefixSize + bytesRef.length); }
From source file:si.virag.solr.UnicodeUtil.java
License:Apache License
public static int UTF8toUTF16(ByteBuffer utf8, int length, CharTermAttribute outputAttr) { char[] output = outputAttr.buffer(); int offset = 0; int out_offset = 0; final int limit = length; while (offset < limit) { int b = utf8.get() & 0xff; // Check for NUL terminator if (b == 0x0) break; // Resize output buffer if necessary if (out_offset == output.length) { output = outputAttr.resizeBuffer(output.length * 2); }//from w ww . j av a 2 s .c o m if (b < 0xc0) { assert b < 0x80; output[out_offset++] = (char) b; } else if (b < 0xe0) { output[out_offset++] = (char) (((b & 0x1f) << 6) + (utf8.get() & 0x3f)); } else if (b < 0xf0) { output[out_offset++] = (char) (((b & 0xf) << 12) + ((utf8.get() & 0x3f) << 6) + (utf8.get() & 0x3f)); offset += 2; } else { assert b < 0xf8 : "b = 0x" + Integer.toHexString(b); int ch = ((b & 0x7) << 18) + ((utf8.get() & 0x3f) << 12) + ((utf8.get() & 0x3f) << 6) + (utf8.get() & 0x3f); if (ch < UNI_MAX_BMP) { output[out_offset++] = (char) ch; } else { int chHalf = ch - 0x0010000; output[out_offset++] = (char) ((chHalf >> 10) + 0xD800); output[out_offset++] = (char) ((chHalf & HALF_MASK) + 0xDC00); } } } outputAttr.setLength(out_offset); return out_offset; }