当前位置: 首页 > 工具软件 > JSch > 使用案例 >

jsch 【stream的理解】

翟嘉祥
2023-12-01

环境

操作系统: win7

getInputStream

public InputStream getInputStream()

官网的解释:

Gets an InputStream for this channel.
All data arriving in SSH_MSG_CHANNEL_DATA messages from the remote side can be read from this stream. 
This method is a polling alternative to setOutputStream(java.io.OutputStream). 
It should be called before connect().

意思:

得到该通道的输入流。
从远程端到达的所有数据消息(格式为:SSH_MSG_CHANNEL_DATA)都能从该流中读取。该方法和`setOutputStream`方法二者选一。
它应该在`connect()`方法之前调用。

getOutputStream

public OutputStream getOutputStream()
Gets an OutputStream for this channel.
All data written to this stream will be sent in SSH_MSG_CHANNEL_DATA messages to the remote side. 
This method is an alternative to setInputStream(java.io.InputStream). 
It should be called before connect().

意思:

得到该通道的输出流。
写入该流中的所有数据,都将发送到远程端,发送的数据格式为`SSH_MSG_CHANNEL_DATA`。
这个方法和`setInputStream`是二者选一的。它应该在`connect()`方法之前调用。

setInputStream

public void setInputStream(InputStream in)

官网:

Sets the InputStream for this channel. 
The channel will then read from this stream and forward the data to the remote side. 
The stream will be closed on disconnect(com.jcraft.jsch.Session). 
This method should be called before connect().

意思:

给该通道设置输入流。
该通道将从该流中读取并转发数据到远程端。
该流将在调用`disconnect`方法后关闭。
该方法应该在`connect`方法之前调用。

setInputStream

public void setInputStream(InputStream in,
                           boolean dontclose)

官网:

Sets the InputStream for this channel. 
The channel will then read from this stream and forward the data in SSH_MSG_CHANNEL_DATA to the remote side. 
This method should be called before connect().

dontclose - if true, we do not close the stream after usage.

意思:

给这个通道设置输入流。
该通道将从这个流中读取数据并转发到远程,数据格式为`SSH_MSG_CHANNEL_DATA`。
这个方法应该在`connect()`方法之前调用。

dontclose 如果为true,再使用完之后,我们不会关闭该流。

setOutputStream

public void setOutputStream(OutputStream out)

官网:

Sets the OutputStream for this channel.
All data arriving in SSH_MSG_CHANNEL_DATA messages from the remote side will be written to this OutputStream. 
This method should be called before connect(). 
The stream will be closed on disconnect(com.jcraft.jsch.Session).

意思:

给这个管道设置输出流。从远程端到达的所有数据消息(格式:SSH_MSG_CHANNEL_DATA)都将被写入到该流中。
这个方法应该在`connect()`方法之前调用。
这个流将在调用`disconnect`后关闭。

setOutputStream

public void setOutputStream(OutputStream out, boolean dontclose)

官网:

Sets the OutputStream for this channel. 
All data arriving in SSH_MSG_CHANNEL_DATA messages from the remote side will be written to this OutputStream. 
This method should be called before connect().

dontclose - if true, we do not close the stream on disconnect(com.jcraft.jsch.Session).

意思:

给这个通道设置输出流。
从远程端到达的所有数据消息(格式:SSH_MSG_CHANNEL_DATA)都将写入到该流中。
这个方法应该在`connect()`之前调用。

dontclose - 如果为真,在执行`disconnect`之后,我们不会关闭该流

参考地址:
http://epaul.github.io/jsch-documentation/javadoc/com/jcraft/jsch/Channel.html#setInputStream-java.io.InputStream-

 类似资料: