mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
classlib: add static nullOutputStream() to OutputStream (#878)
This commit is contained in:
parent
b6bea8bcfb
commit
2318caad7b
|
@ -19,6 +19,36 @@ import java.io.IOException;
|
||||||
import org.teavm.classlib.java.lang.TObject;
|
import org.teavm.classlib.java.lang.TObject;
|
||||||
|
|
||||||
public abstract class TOutputStream extends TObject implements TCloseable, TFlushable {
|
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 abstract void write(int b) throws IOException;
|
||||||
|
|
||||||
public void write(byte[] b) throws IOException {
|
public void write(byte[] b) throws IOException {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user