在 Chronicle Queue 中跳过文档的最佳方法是什么?

What is the best way to skip a document in Chronicle Queue?

从编年史队列中读取文档时,当我不感兴趣时​​跳过当前文档的最佳方法是什么?

即给定以下代码,我应该用什么代替注释?

try (DocumentContext context = getTailer().readingDocument(false)) {
    if (context.isPresent()) {
        // How do I skip the document here?
    }
}

好吧,我假设您至少需要添加一些代码来证明您确实对这个特定文档不感兴趣。否则 - 当文档上下文关闭时,你什么都不放 - 跳过文档。

但是,如果您知道自己刚刚阅读了一份文档,该文档告诉您应该跳过下一篇文档,并且您觉得很冒险,那么您可以这样做:

@Test
public void testSkip() {
    final SingleChronicleQueue q = SingleChronicleQueueBuilder.binary("test").build();

    final ExcerptAppender appender = q.acquireAppender();
    appender.writeText("Hello");
    appender.writeText("Cruel");
    appender.writeText("World");

    final ExcerptTailer tailer = q.createTailer().toStart();

    boolean skip = false;
    while (true) {
        if (skip)
            tailer.moveToIndex(tailer.index() + 1);
        final String text = tailer.readText();
        if (text == null)
            break;
        System.err.println(text);
        skip = text.equals("Hello");
    }
}