@Override
    public Supplier<Token> lookahead() {
        return new Supplier<>() {
            int localNesting = nesting();
            final Supplier<Token> buffered = LazyTokenBuffer.super.lookahead();
            @Override public Token get() {
                if (localNesting == 0)
                    return null;

                Token token = buffered.get();
                if (token == null) {
                    token = nextToken();
                    tokens.add(token);
                }
                localNesting += nestingOffset(token.token);
                return token;
            }
        };
    }
A {@link TokenBuffer} which only buffers tokens when needed, i.e., when peeking.

@author jonmv
document/src/main/java/com/yahoo/document/json/LazyTokenBuffer.java