classlib: add static nullOutputStream() to OutputStream (#878)

This commit is contained in:
Bernd Busse 2024-01-24 18:44:59 +01:00 committed by GitHub
parent b6bea8bcfb
commit 2318caad7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -19,6 +19,36 @@ import java.io.IOException;
import org.teavm.classlib.java.lang.TObject;
public abstract class TOutputStream extends TObject implements TCloseable, TFlushable {
public static TOutputStream nullOutputStream() {
return new TOutputStream() {
private boolean isClosed;
@Override
public void write(int b) throws IOException {
if (isClosed) {
throw new IOException("Stream closed");
}
}
@Override
public void write(byte[] b) throws IOException {
write(b, 0, b.length);
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
if (isClosed) {
throw new IOException("Stream closed");
}
}
@Override
public void close() throws IOException {
isClosed = true;
}
};
}
public abstract void write(int b) throws IOException;
public void write(byte[] b) throws IOException {