ClientSession session = client.connect("localhost", port).await().getSession();
session.authPassword("smx", "smx");
ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_SHELL);
ByteArrayOutputStream sent = new ByteArrayOutputStream();
PipedOutputStream pipedIn = new PipedOutputStream();
OutputStream teeOut = new TeeOutputStream(sent, pipedIn);
channel.setIn(new PipedInputStream(pipedIn));
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayOutputStream err = new ByteArrayOutputStream();
channel.setOut(out);
channel.setErr(err);
channel.open().await();
long t0 = System.currentTimeMillis();
int bytes = 0;
for (int i = 0; i < 10000; i++) {
byte[] data = "01234567890123456789012345678901234567890123456789\n".getBytes();
teeOut.write(data);
teeOut.flush();
bytes += data.length;
if ((bytes & 0xFFF00000) != ((bytes - data.length) & 0xFFF00000)) {
System.out.println("Bytes written: " + bytes);
}
}
teeOut.write("exit\n".getBytes());
teeOut.flush();
long t1 = System.currentTimeMillis();
System.out.println("Sent " + (bytes / 1024) + " Kb in " + (t1 - t0) + " ms");