}
protected synchronized void doWriteIfPossible(boolean resume) {
final IoWriteFutureImpl future = pendingWrite.get();
if (future != null) {
final Buffer buffer = future.buffer;
final int total = buffer.available();
if (total > 0) {
final int length = Math.min(Math.min(channel.getRemoteWindow().getSize(), total), channel.getRemoteWindow().getPacketSize());
if (length > 0) {
if (resume) {
log.debug("Resuming write due to more space available in the remote window");
}
Buffer buf = channel.getSession().createBuffer(cmd, length + 12);
buf.putInt(channel.getRecipient());
if (cmd == SshConstants.SSH_MSG_CHANNEL_EXTENDED_DATA) {
buf.putInt(1);
}
buf.putInt(length);
buf.putRawBytes(buffer.array(), buffer.rpos(), length);
buffer.rpos(buffer.rpos() + length);
channel.getRemoteWindow().consume(length);
try {
channel.getSession().writePacket(buf).addListener(new SshFutureListener<org.apache.sshd.common.io.IoWriteFuture>() {
public void operationComplete(org.apache.sshd.common.io.IoWriteFuture f) {