32 lines
747 B
Java
32 lines
747 B
Java
package stream;
|
|
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.InputStreamReader;
|
|
|
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
|
|
|
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);
|
|
}
|
|
}
|
|
} |