/** * Copies the given {@link CharsRef} referenced content into this instance. * * @param other * the {@link CharsRef} to copy */ public void copyChars(CharsRef other) { copyChars(other.chars, other.offset, other.length); }
/** * Creates a new CharsRef that points to a copy of the chars from * <code>other</code> * <p> * The returned CharsRef will have a length of other.length * and an offset of zero. */ public static CharsRef deepCopyOf(CharsRef other) { CharsRef clone = new CharsRef(); clone.copyChars(other); return clone; }
public void add(char[] output, int offset, int len, int endOffset, int posLength) { if (count == outputs.length) { final CharsRef[] next = new CharsRef[ArrayUtil.oversize(1+count, RamUsageEstimator.NUM_BYTES_OBJECT_REF)]; System.arraycopy(outputs, 0, next, 0, count); outputs = next; } if (count == endOffsets.length) { final int[] next = new int[ArrayUtil.oversize(1+count, RamUsageEstimator.NUM_BYTES_INT)]; System.arraycopy(endOffsets, 0, next, 0, count); endOffsets = next; } if (count == posLengths.length) { final int[] next = new int[ArrayUtil.oversize(1+count, RamUsageEstimator.NUM_BYTES_INT)]; System.arraycopy(posLengths, 0, next, 0, count); posLengths = next; } if (outputs[count] == null) { outputs[count] = new CharsRef(); } outputs[count].copyChars(output, offset, len); // endOffset can be -1, in which case we should simply // use the endOffset of the input token, or X >= 0, in // which case we use X as the endOffset for this output endOffsets[count] = endOffset; posLengths[count] = posLength; count++; } };
private void capture() { captureCount++; //System.out.println(" capture slot=" + nextWrite); final PendingInput input = futureInputs[nextWrite]; input.state = captureState(); input.consumed = false; input.term.copyChars(termAtt.buffer(), 0, termAtt.length()); nextWrite = rollIncr(nextWrite); // Buffer head should never catch up to tail: assert nextWrite != nextRead; }
@Override public boolean incrementToken() throws IOException { if ((! qnameAtt.hasNext()) || qnameAtt.onFirst()) { if (!input.incrementToken()) { return false; } // make a copy of the current term so we can prefix it below term.copyChars(termAtt.buffer(), 0, termAtt.length()); } else { // set posIncr = 0 if this is not the first token emitted for this term posAtt.setPositionIncrement(0); } // emit <qname>:<term> QName qname = qnameAtt.next(); termAtt.setEmpty(); if (namespaceAware) { termAtt.append(qname.getEncodedName()); } else { if (qname.getPrefix().length() > 0) { termAtt.append(qname.getPrefix()).append(':'); } termAtt.append(qname.getLocalPart()); } termAtt.append(':'); termAtt.append(term); return true; }