import com.jcraft.jsch.Channel;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import java.io.*;
public class PrintUDisk extends JSch implements TestInterface, Runnable {
int size = 1000;
PrintUDisk(){
size=33;
}
public int getFreeSize() {
return size;
}
public Session getSession() throws JSchException {
Session s = super.getSession(USER,HOST,PORT);
s.setConfig("StrictHostKeyChecking","no");
s.setPassword(PASS);
return s;
}
public String uptime() throws JSchException, IOException {
Session s = this.getSession();
s.connect(3000);
Channel c = s.openChannel("shell");
PipedInputStream pipIn = new PipedInputStream();
PipedOutputStream pipOut = new PipedOutputStream(pipIn);
FileOutputStream fileOut = new FileOutputStream( file, true);
c.setInputStream(pipIn);
c.setOutputStream(fileOut);
// c.setInputStream(System.in);
// c.setInputStream(new FilterInputStream(System.in) {
// public int read(byte[] b, int off, int len) throws IOException {
// return in.read(b, off, (len > 1024 ? 1024 : len));
// }
// });
c.connect();
pipOut.write("sudo su\n".getBytes());
pipOut.write("uptime\n".getBytes());
pipOut.write("exit\n".getBytes());
c.disconnect();
s.disconnect();
return "done";
}
@Override
public void name() {
}
@Override
public void type() {
}
@Override
public void run() {
while (size>0) {
System.out.println(Thread.currentThread().getName() + ": " + size);
try {
Process exec = Runtime.getRuntime().exec("ping www.163.com");
InputStream ret = exec.getInputStream();
System.out.println(new String(ret.readAllBytes(),"GB2312"));
size--;
} catch (IOException e) { e.printStackTrace();}
}
}
import com.jcraft.jsch.JSch;
import java.util.ArrayList;
public class TestObject {
JSch jsch;
public static void main(String[] args) {
String s[] = {"a","z"};
System.out.println(s[1]);
PrintUDisk pu = new PrintUDisk();
Thread th = new Thread(pu,"th");
Thread th1 = new Thread(pu,"th1");
th.start();
th1.start();
}
}