@Override protected synchronized void doOpen() throws IOException { if (streaming == Streaming.Async) { throw new IllegalArgumentException("Asynchronous streaming isn't supported yet on this channel"); } out = new ChannelOutputStream(this, getRemoteWindow(), log, SshConstants.SSH_MSG_CHANNEL_DATA, true); invertedIn = out; }
@Override public synchronized void close() throws IOException { if (!isOpen()) { return; } if (log.isTraceEnabled()) { log.trace("close({}) closing", this); } try { flush(); if (isEofOnClose()) { AbstractChannel channel = getChannel(); channel.sendEof(); } } finally { try { if (!(packetWriter instanceof Channel)) { packetWriter.close(); } } finally { closedState.set(true); } } }
public ChannelOutputStream(AbstractChannel channel, Window remoteWindow, long maxWaitTimeout, Logger log, byte cmd, boolean eofOnClose) { this.channelInstance = Objects.requireNonNull(channel, "No channel"); this.packetWriter = channelInstance.resolveChannelStreamPacketWriter(channel, cmd); this.remoteWindow = Objects.requireNonNull(remoteWindow, "No remote window"); ValidateUtils.checkTrue(maxWaitTimeout > 0L, "Non-positive max. wait time: %d", maxWaitTimeout); this.maxWaitTimeout = maxWaitTimeout; this.log = Objects.requireNonNull(log, "No logger"); this.cmd = cmd; this.eofOnClose = eofOnClose; newBuffer(0); }
@Override public synchronized void write(byte[] buf, int s, int l) throws IOException { Channel channel = getChannel(); if (!isOpen()) { throw new SshChannelClosedException(channel.getId(), "write(" + this + ") len=" + l + " - channel already closed"); if (l2 <= 0) { if (bufferLength > 0) { flush(); } else { session.resetIdleTimeout(); if (isNoDelay()) { flush(); } else { session.resetIdleTimeout();
@Override public synchronized void flush() throws IOException { AbstractChannel channel = getChannel(); if (!isOpen()) { throw new SshChannelClosedException(channel.getId(), "flush(" + this + ") length=" + bufferLength + " - stream is already closed"); buf.wpos(buf.wpos() + (int) length); if (total == length) { newBuffer((int) length); } else { long leftover = total - length; newBuffer((int) Math.max(leftover, length)); buffer.putRawBytes(buf.array(), pos - (int) leftover, (int) leftover); bufferLength = (int) leftover;
@Override public String toString() { return getClass().getSimpleName() + "[" + getChannel() + "] " + SshConstants.getCommandMessageName(cmd & 0xFF); } }
@Override public synchronized void write(int w) throws IOException { b[0] = (byte) w; write(b, 0, 1); }
@Override public void setOutputStream(OutputStream out) { this.out = out; if (out instanceof ChannelOutputStream) { ((ChannelOutputStream) out).setNoDelay(true); } }
@Override public synchronized void write(byte[] buf, int s, int l) throws IOException { Channel channel = getChannel(); if (!isOpen()) { throw new SshChannelClosedException(channel.getId(), "write(" + this + ") len=" + l + " - channel already closed"); if (l2 <= 0) { if (bufferLength > 0) { flush(); } else { session.resetIdleTimeout(); if (isNoDelay()) { flush(); } else { session.resetIdleTimeout();
@Override public synchronized void flush() throws IOException { AbstractChannel channel = getChannel(); if (!isOpen()) { throw new SshChannelClosedException(channel.getId(), "flush(" + this + ") length=" + bufferLength + " - stream is already closed"); buf.wpos(buf.wpos() + (int) length); if (total == length) { newBuffer((int) length); } else { long leftover = total - length; newBuffer((int) Math.max(leftover, length)); buffer.putRawBytes(buf.array(), pos - (int) leftover, (int) leftover); bufferLength = (int) leftover;
@Override public String toString() { return getClass().getSimpleName() + "[" + getChannel() + "] " + SshConstants.getCommandMessageName(cmd & 0xFF); } }
@Override public synchronized void write(int w) throws IOException { b[0] = (byte) w; write(b, 0, 1); }
@Override public void setErrorStream(OutputStream err) { this.err = err; if (err instanceof ChannelOutputStream) { ((ChannelOutputStream) err).setNoDelay(true); } }
@Override public synchronized void close() throws IOException { if (!isOpen()) { return; } if (log.isTraceEnabled()) { log.trace("close({}) closing", this); } try { flush(); if (isEofOnClose()) { AbstractChannel channel = getChannel(); channel.sendEof(); } } finally { try { if (!(packetWriter instanceof Channel)) { packetWriter.close(); } } finally { closedState.set(true); } } }
@Override protected synchronized void doOpen() throws IOException { if (streaming == Streaming.Async) { throw new IllegalArgumentException("Asynchronous streaming isn't supported yet on this channel"); } out = new ChannelOutputStream(this, getRemoteWindow(), log, SshConstants.SSH_MSG_CHANNEL_DATA, true); invertedIn = out; }
protected void newBuffer(int size) { Channel channel = getChannel(); Session session = channel.getSession(); buffer = session.createBuffer(cmd, size <= 0 ? 12 : 12 + size); buffer.putInt(channel.getRecipient()); if (cmd == SshConstants.SSH_MSG_CHANNEL_EXTENDED_DATA) { buffer.putInt(SshConstants.SSH_EXTENDED_DATA_STDERR); } buffer.putInt(0); bufferLength = 0; }
public ChannelOutputStream(AbstractChannel channel, Window remoteWindow, long maxWaitTimeout, Logger log, byte cmd, boolean eofOnClose) { this.channelInstance = Objects.requireNonNull(channel, "No channel"); this.packetWriter = channelInstance.resolveChannelStreamPacketWriter(channel, cmd); this.remoteWindow = Objects.requireNonNull(remoteWindow, "No remote window"); ValidateUtils.checkTrue(maxWaitTimeout > 0L, "Non-positive max. wait time: %d", maxWaitTimeout); this.maxWaitTimeout = maxWaitTimeout; this.log = Objects.requireNonNull(log, "No logger"); this.cmd = cmd; this.eofOnClose = eofOnClose; newBuffer(0); }
@Override protected synchronized void doOpen() throws IOException { if (Streaming.Async.equals(streaming)) { throw new IllegalArgumentException("Asynchronous streaming isn't supported yet on this channel"); } out = new ChannelOutputStream(this, getRemoteWindow(), log, SshConstants.SSH_MSG_CHANNEL_DATA, true); invertedIn = out; }
protected void newBuffer(int size) { Channel channel = getChannel(); Session session = channel.getSession(); buffer = session.createBuffer(cmd, size <= 0 ? 12 : 12 + size); buffer.putInt(channel.getRecipient()); if (cmd == SshConstants.SSH_MSG_CHANNEL_EXTENDED_DATA) { buffer.putInt(SshConstants.SSH_EXTENDED_DATA_STDERR); } buffer.putInt(0); bufferLength = 0; }
@Override protected synchronized void doOpen() throws IOException { if (Streaming.Async.equals(streaming)) { throw new IllegalArgumentException("Asynchronous streaming isn't supported yet on this channel"); } out = new ChannelOutputStream(this, getRemoteWindow(), log, SshConstants.SSH_MSG_CHANNEL_DATA, true); invertedIn = out; }