/** * Append a single byte to this builder. */ public void append(byte b) { grow(ref.length + 1); ref.bytes[ref.length++] = b; }
/** * Append the provided bytes to this builder. */ public void append(byte[] b, int off, int len) { grow(ref.length + len); System.arraycopy(b, off, ref.bytes, ref.length, len); ref.length += len; }
private void fillTerm() { final int termLength = prefix + suffix; ste.term.setLength(termLength); ste.term.grow(termLength); System.arraycopy(suffixBytes, startBytePos, ste.term.bytes(), prefix, suffix); } }
/** * Replace the content of this buffer with UTF-8 encoded bytes that would * represent the provided text. */ public void copyChars(CharSequence text, int off, int len) { grow(UnicodeUtil.maxUTF8Length(len)); ref.length = UnicodeUtil.UTF16toUTF8(text, off, len, ref.bytes); }
/** * Replace the content of this buffer with UTF-8 encoded bytes that would * represent the provided text. */ public void copyChars(char[] text, int off, int len) { grow(UnicodeUtil.maxUTF8Length(len)); ref.length = UnicodeUtil.UTF16toUTF8(text, off, len, ref.bytes); }
BufferedBinaryDocValues(PackedLongValues lengths, int maxLength, DataInput bytesIterator, DocIdSetIterator docsWithFields) { this.value = new BytesRefBuilder(); this.value.grow(maxLength); this.lengthsIterator = lengths.iterator(); this.bytesIterator = bytesIterator; this.docsWithField = docsWithFields; }
/** Fill the provided {@link BytesRef} with the bytes at the specified offset/length slice. * This will avoid copying the bytes, if the slice fits into a single block; otherwise, it uses * the provided {@link BytesRefBuilder} to copy bytes over. */ void setBytesRef(BytesRefBuilder builder, BytesRef result, long offset, int length) { result.length = length; int bufferIndex = (int) (offset >> BYTE_BLOCK_SHIFT); byte[] buffer = buffers[bufferIndex]; int pos = (int) (offset & BYTE_BLOCK_MASK); if (pos + length <= BYTE_BLOCK_SIZE) { // common case where the slice lives in a single block: just reference the buffer directly without copying result.bytes = buffer; result.offset = pos; } else { // uncommon case: the slice spans at least 2 blocks, so we must copy the bytes: builder.grow(length); result.bytes = builder.get().bytes; result.offset = 0; readBytes(offset, result.bytes, 0, length); } }
private void readTermBytes(int prefix, int suffix) throws IOException { builder.grow(prefix + suffix); input.readBytes(builder.bytes(), prefix, suffix); builder.setLength(prefix + suffix); }
/** Just converts IntsRef to BytesRef; you must ensure the * int values fit into a byte. */ public static BytesRef toBytesRef(IntsRef input, BytesRefBuilder scratch) { scratch.grow(input.length); for(int i=0;i<input.length;i++) { int value = input.ints[i+input.offset]; // NOTE: we allow -128 to 255 assert value >= Byte.MIN_VALUE && value <= 255: "value " + value + " doesn't fit into byte"; scratch.setByteAt(i, (byte) value); } scratch.setLength(input.length); return scratch.get(); }
public void nextLeaf() { //if (DEBUG) System.out.println(" frame.next ord=" + ord + " nextEnt=" + nextEnt + " entCount=" + entCount); assert nextEnt != -1 && nextEnt < entCount: "nextEnt=" + nextEnt + " entCount=" + entCount + " fp=" + fp; nextEnt++; suffix = suffixesReader.readVInt(); startBytePos = suffixesReader.getPosition(); ste.term.setLength(prefix + suffix); ste.term.grow(ste.term.length()); suffixesReader.readBytes(ste.term.bytes(), prefix, suffix); ste.termExists = true; }
/** * Returns the <i>n'th</i> element of this {@link BytesRefArray} * @param spare a spare {@link BytesRef} instance * @param index the elements index to retrieve * @return the <i>n'th</i> element of this {@link BytesRefArray} */ public BytesRef get(BytesRefBuilder spare, int index) { FutureObjects.checkIndex(index, lastElement); int offset = offsets[index]; int length = index == lastElement - 1 ? currentOffset - offset : offsets[index + 1] - offset; spare.grow(length); spare.setLength(length); pool.readBytes(offset, spare.bytes(), 0, spare.length()); return spare.get(); }
/** * Reads the next entry into the provided {@link BytesRef}. The internal * storage is resized if needed. * * @return Returns <code>false</code> if EOF occurred when trying to read * the header of the next sequence. Returns <code>true</code> otherwise. * @throws EOFException if the file ends before the full sequence is read. */ public BytesRef next() throws IOException { if (in.getFilePointer() >= end) { return null; } short length = in.readShort(); ref.grow(length); ref.setLength(length); in.readBytes(ref.bytes(), 0, length); return ref.get(); }
@Override public int nextPosition() throws IOException { assert posLeft > 0; posLeft--; int code = posReader.readVInt(); pos += code >>> 1; if ((code & 1) != 0) { hasPayload = true; // has a payload payload.setLength(posReader.readVInt()); payload.grow(payload.length()); posReader.readBytes(payload.bytes(), 0, payload.length()); } else { hasPayload = false; } if (readOffsets) { startOffset += posReader.readVInt(); endOffset = startOffset + posReader.readVInt(); } return pos; }
startBytePos = suffixesReader.getPosition(); ste.term.setLength(prefix + suffix); ste.term.grow(ste.term.length()); suffixesReader.readBytes(ste.term.bytes(), prefix, suffix); if ((code & 1) == 0) {
payload = new BytesRefBuilder(); payload.grow(payloadLength);
term.grow(1 + target.length);
scratch.grow(scratch.length());