Top Description Fields Constructors Methods
org.apache.sshd.server.channel

public Class PipeDataReceiver

extends AbstractLoggingBean
implements ChannelDataReceiver
Class Inheritance
All Implemented Interfaces
org.apache.sshd.server.channel.ChannelDataReceiver, java.io.Closeable, java.lang.AutoCloseable
Imports
java.io.IOException, .InputStream, .OutputStream, org.apache.sshd.common.PropertyResolver, org.apache.sshd.common.channel.ChannelPipedInputStream, .ChannelPipedOutputStream, .LocalWindow, org.apache.sshd.common.util.io.output.LoggingFilterOutputStream, org.apache.sshd.common.util.logging.AbstractLoggingBean

ChannelDataReceiver that buffers the received data into byte buffer and provides an InputStream to consume them.
Author
Kohsuke Kawaguchi

Field Summary

Modifier and TypeField and Description
private InputStream
private OutputStream
Inherited from org.apache.sshd.common.util.logging.AbstractLoggingBean:
log

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

public int
data(ChannelSession
The caller to which this ChannelDataReceiver is assigned. Never null.
channel
,
byte[]
Holds the bytes received. This buffer belongs to the caller, and it might get reused by the caller as soon as this method returns.
buf
,
int
buf[start] is the first byte that received from the client.
start
,
int
the length of the bytes received. Can be zero.
len
)

Implements org.apache.sshd.server.channel.ChannelDataReceiver.data.

Called when the server receives additional bytes from the client.

public InputStream
Inherited from org.apache.sshd.common.util.logging.AbstractLoggingBean:
debugdebugdebugdebugdebugerrorerrorerrorerrorerrorgetSimplifiedLoggerinfoinfowarnwarnwarnwarnwarnwarnwarnwarn

Field Detail

inback to summary
private InputStream in
outback to summary
private OutputStream out

Constructor Detail

PipeDataReceiverback to summary
public PipeDataReceiver(PropertyResolver resolver, LocalWindow localWindow)

Method Detail

closeback to summary
public void close() throws IOException

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
databack to summary
public int data(ChannelSession channel, byte[] buf, int start, int len) throws IOException

Implements org.apache.sshd.server.channel.ChannelDataReceiver.data.

Doc from org.apache.sshd.server.channel.ChannelDataReceiver.data.

Called when the server receives additional bytes from the client. When close()-d then indicates EOF - The client will no longer send us any more data.

SSH channels use the windowing mechanism to perform flow control, much like TCP does. The server gives the client the initial window size, which represents the number of bytes the client can send to the server. As the server receives data, it can send a message to the client to allow it to send more data.

The return value from this method is used to control this behaviour. Intuitively speaking, the callee returns the number of bytes consumed by this method, by the time this method returns. Picture a one-way long bridge (for example Golden Gate Bridge) with toll plazas on both sides. The window size is the maximum number of cars allowed on the bridge. Here we are on the receiving end, so our job here is to count the number of cars as it leaves the bridge, and if enough of them left, we'll signal the sending end that they can let in more cars. The return value of this method counts the number of cars that are leaving in this batch.

In simple cases, where the callee has consumed the bytes before it returns, the return value must be the same value as the 'len' parameter given.

On the other hand, if the callee is queueing up the received bytes somewhere to be consumed later (for example by another thread), then this method should return 0, for the bytes aren't really consumed yet. And when at some later point the bytes are actually used, then you'll invoke channel.getLocalWindow().consumeAndCheck(len) to let the channel know that bytes are consumed.

This behaviour will result in a better flow control, as the server will not allow the SSH client to overflow its buffer. If instead you always return the value passed in the 'len' parameter, the place where you are queueing up bytes may overflow.

In either case, the callee must account for every bytes it receives in this method. Returning 0 and failing to call back channel.getLocalWindow().consumeAndCheck(len) later will dry up the window size, and eventually the client will stop sending you any data.

In the SSH protocol, this method invocation is triggered by a SSH_MSG_CHANNEL_DATA message.

Parameters
channel:ChannelSession

The caller to which this ChannelDataReceiver is assigned. Never null.

buf:byte[]

Holds the bytes received. This buffer belongs to the caller, and it might get reused by the caller as soon as this method returns.

start:int

buf[start] is the first byte that received from the client.

len:int

the length of the bytes received. Can be zero.

Returns:int

The number of bytes consumed, for the purpose of the flow control. For a simple use case, you return the value given by the 'len' parameter. See the method javadoc for more details.

Annotations
@Override
Exceptions
IOException:
if failed to consume the data
getInback to summary
public InputStream getIn()