2013-11-14 07:17:51 +00:00
|
|
|
package com.ryanmichela.sshd;
|
|
|
|
|
2018-05-06 16:42:39 +00:00
|
|
|
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 {
|
2018-05-06 16:42:39 +00:00
|
|
|
|
2019-10-06 07:08:34 +00:00
|
|
|
private OutputStream base;
|
|
|
|
private boolean isClosed = false;
|
|
|
|
|
|
|
|
public FlushyOutputStream(OutputStream base) {
|
|
|
|
this.base = base;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void write(int b) throws IOException {
|
|
|
|
if (isClosed) return;
|
|
|
|
base.write(b);
|
|
|
|
base.flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void write(byte[] b) throws IOException {
|
|
|
|
if (isClosed) return;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void close() {
|
|
|
|
isClosed = true;
|
|
|
|
}
|
2013-11-14 07:17:51 +00:00
|
|
|
}
|