public AsyncDataReceiver(Channel channel) { in = new ChannelAsyncInputStream(channel); }
@Override public void close() throws IOException { in.close(false); } }
public void write(Readable src) throws IOException { synchronized (buffer) { buffer.putBuffer(src); } doRead(true); }
@Override public IoReadFuture read(Buffer buf) { IoReadFutureImpl future = new IoReadFutureImpl(readFutureId, buf); if (isClosing()) { synchronized (buffer) { if (pending != null) { throw new ReadPendingException("Previous pending read not handled"); } if (buffer.available() > 0) { Buffer fb = future.getBuffer(); int nbRead = fb.putBuffer(buffer, false); buffer.compact(); future.setValue(nbRead); } else { future.setValue(new IOException("Closed")); } } } else { synchronized (buffer) { if (pending != null) { throw new ReadPendingException("Previous pending read not handled"); } pending = future; } doRead(false); } return future; }
@Override public int data(ChannelSession channel, byte[] buf, int start, int len) throws IOException { in.write(new ByteArrayBuffer(buf, start, len)); return 0; }
@Override public String toString() { return getClass().getSimpleName() + "[" + getChannel() + "]"; }
@Override protected CloseFuture doCloseGracefully() { synchronized (buffer) { return builder().when(pending).build().close(false); } }
public ChannelAsyncInputStream(Channel channel) { this.channelInstance = Objects.requireNonNull(channel, "No channel"); this.readFutureId = toString(); }
@Override public IoReadFuture read(Buffer buf) { IoReadFutureImpl future = new IoReadFutureImpl(readFutureId, buf); if (isClosing()) { synchronized (buffer) { if (pending != null) { throw new ReadPendingException("Previous pending read not handled"); } if (buffer.available() > 0) { Buffer fb = future.getBuffer(); int nbRead = fb.putBuffer(buffer, false); buffer.compact(); future.setValue(nbRead); } else { future.setValue(new IOException("Closed")); } } } else { synchronized (buffer) { if (pending != null) { throw new ReadPendingException("Previous pending read not handled"); } pending = future; } doRead(false); } return future; }
@Override public int data(ChannelSession channel, byte[] buf, int start, int len) throws IOException { in.write(new ByteArrayBuffer(buf, start, len)); return 0; }
@Override public String toString() { return getClass().getSimpleName() + "[" + getChannel() + "]"; }
@Override protected CloseFuture doCloseGracefully() { synchronized (buffer) { return builder().when(pending).build().close(false); } }
public ChannelAsyncInputStream(Channel channel) { this.channelInstance = Objects.requireNonNull(channel, "No channel"); this.readFutureId = toString(); }
@Override protected void doWriteData(byte[] data, int off, long len) throws IOException { // If we're already closing, ignore incoming data if (isClosing()) { return; } ValidateUtils.checkTrue(len <= Integer.MAX_VALUE, "Data length exceeds int boundaries: %d", len); if (asyncOut != null) { asyncOut.write(new ByteArrayBuffer(data, off, (int) len)); } else if (out != null) { out.write(data, off, (int) len); out.flush(); if (invertedOut == null) { Window wLocal = getLocalWindow(); wLocal.consumeAndCheck(len); } } else { throw new IllegalStateException("No output stream for channel"); } }
public AsyncDataReceiver(Channel channel) { in = new ChannelAsyncInputStream(channel); }
Channel channel = getChannel(); try { Window wLocal = channel.getLocalWindow();
@Override public void close() throws IOException { in.close(false); } }
public void write(Readable src) throws IOException { synchronized (buffer) { buffer.putBuffer(src); } doRead(true); }
@Override protected void doWriteExtendedData(byte[] data, int off, long len) throws IOException { // If we're already closing, ignore incoming data if (isClosing()) { return; } ValidateUtils.checkTrue(len <= Integer.MAX_VALUE, "Extended data length exceeds int boundaries: %d", len); if (asyncErr != null) { asyncErr.write(new ByteArrayBuffer(data, off, (int) len)); } else if (err != null) { err.write(data, off, (int) len); err.flush(); if (invertedErr == null) { Window wLocal = getLocalWindow(); wLocal.consumeAndCheck(len); } } else { throw new IllegalStateException("No error stream for channel"); } }
@Override protected void doOpen() throws IOException { if (streaming == Streaming.Async) { asyncIn = new ChannelAsyncOutputStream(this, SshConstants.SSH_MSG_CHANNEL_DATA); asyncOut = new ChannelAsyncInputStream(this); } else { out = new ChannelOutputStream(this, getRemoteWindow(), log, SshConstants.SSH_MSG_CHANNEL_DATA, true); invertedIn = out; ChannelPipedInputStream pis = new ChannelPipedInputStream(this, getLocalWindow()); pipe = new ChannelPipedOutputStream(pis); in = pis; invertedOut = in; } }