@Override public boolean seek(final long position) { if (state == IteratorState.WRAP_NOT_CALLED) { throw new IllegalStateException("Iterator not initialized"); } // invalidate events first as the buffer content may change invalidateBufferAndOffsets(); final long blockAddress = lookUpBlockAddressForPosition(position); if (blockAddress < 0) { // no block found => empty log state = IteratorState.EMPTY_LOG_STREAM; return false; } else { readBlockIntoBuffer(blockAddress); readNextEvent(); return searchPositionInBuffer(position); } }
@Override public boolean seek(final long position) { if (state == IteratorState.WRAP_NOT_CALLED) { throw new IllegalStateException("Iterator not initialized"); } // invalidate events first as the buffer content may change invalidateBufferAndOffsets(); final long blockAddress = lookUpBlockAddressForPosition(position); if (blockAddress < 0) { // no block found => empty log state = IteratorState.EMPTY_LOG_STREAM; return false; } else { readBlockIntoBuffer(blockAddress); readNextEvent(); return searchPositionInBuffer(position); } }
private void compactBuffer() { // check if an event is wrapped and preserve it if (isReturnedEventInitialized() || isNextEventInitialized()) { final int offsetToCopy = minimalOffsetToPreserve(); // set position to last returned offset byteBuffer.position(offsetToCopy); // compact buffer to move old events to front byteBuffer.compact(); // update buffer offset bufferOffset -= offsetToCopy; // update event offsets if (isNextEventInitialized()) { wrapNextEvent(nextEvent.getFragmentOffset() - offsetToCopy); } if (isReturnedEventInitialized()) { wrapReturnedEvent(returnedEvent.getFragmentOffset() - offsetToCopy); } } else { // otherwise just clear the buffer invalidateBufferAndOffsets(); byteBuffer.clear(); } }
private void compactBuffer() { // check if an event is wrapped and preserve it if (isReturnedEventInitialized() || isNextEventInitialized()) { final int offsetToCopy = minimalOffsetToPreserve(); // set position to last returned offset byteBuffer.position(offsetToCopy); // compact buffer to move old events to front byteBuffer.compact(); // update buffer offset bufferOffset -= offsetToCopy; // update event offsets if (isNextEventInitialized()) { wrapNextEvent(nextEvent.getFragmentOffset() - offsetToCopy); } if (isReturnedEventInitialized()) { wrapReturnedEvent(returnedEvent.getFragmentOffset() - offsetToCopy); } } else { // otherwise just clear the buffer invalidateBufferAndOffsets(); byteBuffer.clear(); } }
} else { invalidateBufferAndOffsets();