@Override public BytesRefIterator iterator() { if (references.length > 0) { return new BytesRefIterator() { int index = 0; private BytesRefIterator current = references[index++].iterator(); @Override public BytesRef next() throws IOException { BytesRef next = current.next(); if (next == null) { while (index < references.length) { current = references[index++].iterator(); next = current.next(); if (next != null) { break; } } } return next; } }; } else { return () -> null; } }
/** * Writes the bytes directly to the output stream. */ public void writeTo(OutputStream os) throws IOException { final BytesRefIterator iterator = iterator(); BytesRef ref; while ((ref = iterator.next()) != null) { os.write(ref.bytes, ref.offset, ref.length); } }
@Override public int hashCode() { if (hash == null) { final BytesRefIterator iterator = iterator(); BytesRef ref; int result = 1; try { while ((ref = iterator.next()) != null) { for (int i = 0; i < ref.length; i++) { result = 31 * result + ref.bytes[ref.offset + i]; } } } catch (IOException ex) { throw new AssertionError("wont happen", ex); } return hash = result; } else { return hash.intValue(); } }
private MarkSupportingStreamInputWrapper(BytesReference reference) throws IOException { this.reference = reference; this.input = new BytesReferenceStreamInput(reference.iterator(), reference.length()); }
@Override public BytesRef next() throws IOException { BytesRef next = current.next(); if (next == null) { while (index < references.length) { current = references[index++].iterator(); next = current.next(); if (next != null) { break; } } } return next; } };
@Override public void reset() throws IOException { input = new BytesReferenceStreamInput(reference.iterator(), reference.length()); input.skip(mark); }
indexOutput = getOpenIndexOutput(name); BytesRefIterator iterator = content.iterator(); BytesRef scratch; while((scratch = iterator.next()) != null) { // we iterate over all pages - this is a 0-copy for all core impls
/** * Writes the bytes directly to the output stream. */ public void writeTo(OutputStream os) throws IOException { final BytesRefIterator iterator = iterator(); BytesRef ref; while ((ref = iterator.next()) != null) { os.write(ref.bytes, ref.offset, ref.length); } }
/** * Writes the bytes directly to the output stream. */ public void writeTo(OutputStream os) throws IOException { final BytesRefIterator iterator = iterator(); BytesRef ref; while ((ref = iterator.next()) != null) { os.write(ref.bytes, ref.offset, ref.length); } }
/** * Writes the bytes directly to the output stream. */ public void writeTo(OutputStream os) throws IOException { final BytesRefIterator iterator = iterator(); BytesRef ref; while ((ref = iterator.next()) != null) { os.write(ref.bytes, ref.offset, ref.length); } }
public static int getNumPages(BytesReference ref) throws IOException { int num = 0; if (ref.length() > 0) { BytesRefIterator iterator = ref.iterator(); while(iterator.next() != null) { num++; } } return num; }
private MarkSupportingStreamInputWrapper(BytesReference reference) throws IOException { this.reference = reference; this.input = new BytesReferenceStreamInput(reference.iterator(), reference.length()); }
@Override public void reset() throws IOException { input = new BytesReferenceStreamInput(reference.iterator(), reference.length()); input.skip(mark); }
@Override public void reset() throws IOException { input = new BytesReferenceStreamInput(reference.iterator(), reference.length()); input.skip(mark); }
@Override public void reset() throws IOException { input = new BytesReferenceStreamInput(reference.iterator(), reference.length()); input.skip(mark); }
public void testEmptyToBytesRefIterator() throws IOException { BytesReference pbr = newBytesReference(0); assertNull(pbr.iterator().next()); }
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; }
public void testIterator() throws IOException { int length = randomIntBetween(10, PAGE_SIZE * randomIntBetween(2, 8)); BytesReference pbr = newBytesReference(length); BytesRefIterator iterator = pbr.iterator(); BytesRef ref; BytesRefBuilder builder = new BytesRefBuilder(); while((ref = iterator.next()) != null) { builder.append(ref); } assertArrayEquals(BytesReference.toBytes(pbr), BytesRef.deepCopyOf(builder.toBytesRef()).bytes); }
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); }