<commit_before>package com.hypirion.io;

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

public class RevivableInputStream extends InputStream {
    protected InputStream in;

    protected volatile boolean killed;
    protected volatile boolean streamClosed;
    protected volatile int data;
    protected volatile boolean beenRead;
    protected Object dataLock;
    protected volatile boolean threadCrashed;
    protected volatile IOException threadException;

    protected final ThreadReader reader;
    protected final Thread readerThread;

    public RevivableInputStream(InputStream in) throws InterruptedException {
        this.in = in;
        killed = false;
        streamClosed = false;
        beenRead = true;
        dataLock = new Object();
        threadCrashed = false;
        threadException = null;
        data = -2;
        reader = new ThreadReader();
        readerThread = new Thread(reader);
        readerThread.setDaemon(true);
        readerThread.setName("RevivableReader " + in.hashCode());
        readerThread.start();
    }

    public synchronized int available() throws IOException {
        return 0;
    }

    public synchronized void close() throws IOException {
        synchronized (dataLock) {
            in.close();
            dataLock.notifyAll();
        }
    }

    public synchronized int read() throws IOException {
        synchronized (dataLock) {
            try {
                while (beenRead && !killed && !streamClosed && !threadCrashed) {
                    dataLock.wait();
                }
            }
            catch (InterruptedException ie) {
                throw new InterruptedIOException();
            }
            if (streamClosed)
                return -1;
            if (threadCrashed)
                throw threadException;
            if (killed)
                return -1;
            int val = data;
            beenRead = true;
            dataLock.notifyAll();
            return val;
        }
    }

    public synchronized int read(byte[] b) throws IOException {
        return read(b, 0, b.length);
    }

    public synchronized int read(byte[] b, int off, int len) throws IOException{
        if (len == 0)
            return 0;
        int v = read();
        if (v == -1)
            return -1;
        b[off] = (byte) v;
        return 1;
    }

    public synchronized void reset() throws IOException {
        throw new UnsupportedOperationException();
    }

    public synchronized long skip(long n) throws IOException {
        for (int i = 0; i < n; i++)
            read();
        return n;
    }

    public void kill() {
        synchronized (dataLock) {
            killed = true;
            dataLock.notifyAll();
        }
    }

    public synchronized void resurrect() {
        killed = false;
    }

    private class ThreadReader implements Runnable {<commit_msg>Remove methods already defined in InputStream.<commit_after>package com.hypirion.io;

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

public class RevivableInputStream extends InputStream {
    protected InputStream in;

    protected volatile boolean killed;
    protected volatile boolean streamClosed;
    protected volatile int data;
    protected volatile boolean beenRead;
    protected Object dataLock;
    protected volatile boolean threadCrashed;
    protected volatile IOException threadException;

    protected final ThreadReader reader;
    protected final Thread readerThread;

    public RevivableInputStream(InputStream in) throws InterruptedException {
        this.in = in;
        killed = false;
        streamClosed = false;
        beenRead = true;
        dataLock = new Object();
        threadCrashed = false;
        threadException = null;
        data = -2;
        reader = new ThreadReader();
        readerThread = new Thread(reader);
        readerThread.setDaemon(true);
        readerThread.setName("RevivableReader " + in.hashCode());
        readerThread.start();
    }

    public synchronized int available() throws IOException {
        return 0;
    }

    public synchronized void close() throws IOException {
        synchronized (dataLock) {
            in.close();
            dataLock.notifyAll();
        }
    }

    public synchronized int read() throws IOException {
        synchronized (dataLock) {
            try {
                while (beenRead && !killed && !streamClosed && !threadCrashed) {
                    dataLock.wait();
                }
            }
            catch (InterruptedException ie) {
                throw new InterruptedIOException();
            }
            if (streamClosed)
                return -1;
            if (threadCrashed)
                throw threadException;
            if (killed)
                return -1;
            int val = data;
            beenRead = true;
            dataLock.notifyAll();
            return val;
        }
    }

    public void kill() {
        synchronized (dataLock) {
            killed = true;
            dataLock.notifyAll();
        }
    }

    public synchronized void resurrect() {
        killed = false;
    }

    private class ThreadReader implements Runnable {
{'fraction_non_alphanumeric': 0.07781143506247633, 'fraction_numerical': 0.002839833396440742, 'mean_word_length': 1.9043430456294668, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, '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': '816200', 'n_tokens_mistral': 1307, 'n_tokens_neox': 1265, 'n_words': 393}