package stream;

import static java.nio.charset.StandardCharsets.UTF_8;

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

public class SafeInputStream {

    private InputStreamReader underlyingStream;

    public SafeInputStream(InputStream underlyingStream) {
        this.underlyingStream = new InputStreamReader(underlyingStream, UTF_8);
    }

    public int read() {
        try {
            return underlyingStream.read();
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }

    public void close() {
        try {
            underlyingStream.close();
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }

}