Minecraft-SSHD/src/main/java/com/ryanmichela/sshd/FlushyOutputStream.java

50 lines
1.0 KiB
Java
Raw Normal View History

2013-11-14 07:17:51 +00:00
package com.ryanmichela.sshd;
import org.apache.sshd.common.SshException;
2013-11-14 07:17:51 +00:00
import java.io.IOException;
import java.io.OutputStream;
/**
* Copyright 2013 Ryan Michela
*/
public class FlushyOutputStream extends OutputStream {
2013-11-14 07:17:51 +00:00
private OutputStream base;
private boolean isClosed = false;
2013-11-14 07:17:51 +00:00
public FlushyOutputStream(OutputStream base) {
this.base = base;
}
@Override
public void write(int b) throws IOException {
if (isClosed) return;
2013-11-14 07:17:51 +00:00
base.write(b);
base.flush();
}
@Override
public void write(byte[] b) throws IOException {
if (isClosed) return;
2013-11-14 07:17:51 +00:00
base.write(b);
base.flush();
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
if (isClosed) return;
try {
base.write(b, off, len);
base.flush();
} catch (SshException e) {
if (!e.getMessage().contains("channel already closed")) throw e;
}
2013-11-14 07:17:51 +00:00
}
@Override
public void close() {
isClosed = true;
}
2013-11-14 07:17:51 +00:00
}