package pkgname.jsh;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.util.LinkedList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* The main entry of this POC.
*
* The whole idea is:
* <p/>
* Make our own input-stream and output-stream. And manage them by this class.
* MyOutputStream will read the response from SSH shell channel, if found an
* 'expected' response, it will notify the MyInputStream through the
* MySshIoManager, then the SSH shell channel can read from MyInputStream. And
* MyInputStream will handle the "password" input part.
*
* @author: clarioneswang
* @version: 1.0, Dec 31, 2012
*/
public class MySshIOManager {
private MyInputStream mInputStream;
private MyOutputStream mOutputStream;
private List<MyCommand> mCommands = new LinkedList<MyCommand>();
private int mCmdIdx;
private boolean canSend;
public InputStream getInputStream() {
return mInputStream;
}
public OutputStream getOutputStream() {
return mOutputStream;
}
// Load the command from file.
public void loadCommands(InputStream pIns) {
mInputStream = new MyInputStream();
mOutputStream = new MyOutputStream();
mInputStream.setManager(this);
mOutputStream.setManager(this);
mCmdIdx = 0;
canSend = false;
BufferedReader br = new BufferedReader(new InputStreamReader(pIns));
String line;
try {
while ((line = br.readLine()) != null) {
line = line.trim();
if (line.isEmpty()) {
continue;
}
if (line.startsWith("#")) {
continue;
}
addCommandLine(line);
}
} catch (IOException e) {
e.printStackTrace();
}
mCmdIdx = 0;
}
static Pattern cmdptn = Pattern.compile("\\[([^\\s\\]]*)\\]([^\\s\\[]*)\\[([^\\]]*)\\]");
private void addCommandLine(String pLine) {
Matcher m = cmdptn.matcher(pLine);
if (m.find()) {
System.out.println("load command: " + pLine);
addCommand(m.group(2), m.group(1), m.group(3));
}
}
private void addCommand(String pCmd, String pEnds, String pContent) {
mCommands.add(new MyCommand(pCmd, pEnds, pContent, mCmdIdx));
mCmdIdx++;
}
public MyCommand getNextCommand() {
if (mCmdIdx >= mCommands.size()) {
return null;
}
synchronized (mCommands) {
try {
mCommands.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
return mCommands.get(mCmdIdx++);
}
}
public MyCommand getCommand() {
if (mCmdIdx >= mCommands.size()) {
return null;
}
synchronized (mCommands) {
return mCommands.get(mCmdIdx);
}
}
public void enableSend() {
synchronized (mCommands) {
mCommands.notify();
}
}
}
JSCH处理输入pssword的源代码
4星 · 超过85%的资源 需积分: 49 174 浏览量
2012-12-31
15:46:30
上传
评论 3
收藏 215KB ZIP 举报
clariones
- 粉丝: 38
- 资源: 22
最新资源
- 直接插入排序,冒泡排序,直接选择排序.zip
- 在排序2的基础上,再次对快排进行优化,其次增加快排非递归,归并排序,归并排序非递归版.zip
- 实现了7种排序算法.三种复杂度排序.三种nlogn复杂度排序(堆排序,归并排序,快速排序)一种线性复杂度的排序.zip
- 冒泡排序 直接选择排序 直接插入排序 随机快速排序 归并排序 堆排序.zip
- 课设-内部排序算法比较 包括冒泡排序、直接插入排序、简单选择排序、快速排序、希尔排序、归并排序和堆排序.zip
- Python排序算法.zip
- C语言实现直接插入排序、希尔排序、选择排序、冒泡排序、堆排序、快速排序、归并排序、计数排序,并带图详解.zip
- 常用工具集参考用于图像等数据处理
- 音乐展示网页、基于Stenography的图像数字水印添加与提取,以及基于颜色矩和Tamura算法的图像相似度评估算法py源码
- 基于EmguCV(OpenCV .net封装),图像数字水印加解密算法的实现,其中包含最低有效位算法,离散傅里叶变换算法+文档书
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
前往页