use of org.apache.lucene.util.BytesRefIterator in project crate by crate.
the class AbstractBytesReferenceTestCase method getSinglePageOrNull.
public static BytesRef getSinglePageOrNull(BytesReference ref) throws IOException {
if (ref.length() > 0) {
BytesRefIterator iterator = ref.iterator();
BytesRef next = iterator.next();
BytesRef retVal = next.clone();
if (iterator.next() == null) {
return retVal;
}
} else {
return new BytesRef();
}
return null;
}
use of org.apache.lucene.util.BytesRefIterator in project crate by crate.
the class AbstractBytesReferenceTestCase method testSliceIterator.
public void testSliceIterator() throws IOException {
int length = randomIntBetween(10, PAGE_SIZE * randomIntBetween(2, 8));
BytesReference pbr = newBytesReference(length);
int sliceOffset = randomIntBetween(0, pbr.length());
int sliceLength = randomIntBetween(0, pbr.length() - sliceOffset);
BytesReference slice = pbr.slice(sliceOffset, sliceLength);
BytesRefIterator iterator = slice.iterator();
BytesRef ref = null;
BytesRefBuilder builder = new BytesRefBuilder();
while ((ref = iterator.next()) != null) {
builder.append(ref);
}
assertArrayEquals(BytesReference.toBytes(slice), BytesRef.deepCopyOf(builder.toBytesRef()).bytes);
}
Aggregations