<commit_before>package net.lshift.spki.convert;

import java.io.IOException;
import java.io.InputStream;
import java.util.Stack;

import net.lshift.spki.CanonicalSpkiInputStream;
import net.lshift.spki.InvalidInputException;
import net.lshift.spki.ParseException;
import net.lshift.spki.SpkiInputStream;

/**
 * Input stream that wraps an SpkiInputStream to add facilities
 * useful for conversion to classes.
 */
public class ConvertInputStream
    extends SpkiInputStream {
    private final SpkiInputStream delegate;
    private final Stack<TokenType> tokenStack = new Stack<TokenType>();
    private final Stack<byte[]> byteStack = new Stack<byte[]>();

    public ConvertInputStream(final SpkiInputStream delegate) {
        super();
        this.delegate = delegate;
    }

    public ConvertInputStream(final InputStream is) {
        this(new CanonicalSpkiInputStream(is));
    }

    @Override
    public TokenType doNext()
        throws IOException,
            ParseException {
        if (tokenStack.isEmpty()) {
            return delegate.next();
        } else {
            return tokenStack.pop();
        }
    }

    @Override
    public byte[] doAtomBytes()
        throws IOException,
            ParseException {
        if (byteStack.isEmpty()) {
            return delegate.atomBytes();
        } else {
            return byteStack.pop();
        }
    }

    @Override
    public void close()
        throws IOException {
        delegate.close();
    }

    public <T> T read(final Class<T> clazz)
        throws IOException, InvalidInputException {
        return Registry.getConverter(clazz).read(this);
    }

    public <T> T readRest(final Class<T> clazz)
            throws IOException, InvalidInputException {
        return ((ListConverter<T>)Registry.getConverter(clazz)).readRest(this);
    }

    public void pushback(final TokenType token) {
        switch (token) {
        case EOF:
            assertState(State.FINISHED);
            break;
        case ATOM:
            assertState(State.ATOM);
            break;
        default:
            assertState(State.TOKEN);
            break;
        }
        tokenStack.push(token);
        state = State.TOKEN;
    }

    public void pushback(final byte[] atom) {
        assertState(State.TOKEN);
        byteStack.push(atom);
        state = State.ATOM;
    }

    public void nextAssertType(final TokenType type)
        throws IOException, InvalidInputException {
        if (next() != type) {<commit_msg>Remove pushback from ConvertInputStream.<commit_after>package net.lshift.spki.convert;

import java.io.IOException;
import java.io.InputStream;

import net.lshift.spki.CanonicalSpkiInputStream;
import net.lshift.spki.InvalidInputException;
import net.lshift.spki.ParseException;
import net.lshift.spki.SpkiInputStream;

/**
 * Input stream that wraps an SpkiInputStream to add facilities
 * useful for conversion to classes.
 */
public class ConvertInputStream
    extends SpkiInputStream {
    private final SpkiInputStream delegate;

    public ConvertInputStream(final SpkiInputStream delegate) {
        super();
        this.delegate = delegate;
    }

    public ConvertInputStream(final InputStream is) {
        this(new CanonicalSpkiInputStream(is));
    }

    @Override
    public TokenType doNext()
        throws IOException,
            ParseException {
        return delegate.next();
    }

    @Override
    public byte[] doAtomBytes()
        throws IOException,
            ParseException {
        return delegate.atomBytes();
    }

    @Override
    public void close()
        throws IOException {
        delegate.close();
    }

    public <T> T read(final Class<T> clazz)
        throws IOException, InvalidInputException {
        return Registry.getConverter(clazz).read(this);
    }

    public <T> T readRest(final Class<T> clazz)
            throws IOException, InvalidInputException {
        return ((ListConverter<T>)Registry.getConverter(clazz)).readRest(this);
    }

    public void nextAssertType(final TokenType type)
        throws IOException, InvalidInputException {
        if (next() != type) {
{'fraction_non_alphanumeric': 0.0907993238348225, 'fraction_numerical': 0.0, 'mean_word_length': 2.5923677363399826, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6719095', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1081, 'n_words': 273}