本文整理汇总了Java中org.apache.commons.net.telnet.WindowSizeOptionHandler类的典型用法代码示例。如果您正苦于以下问题:Java WindowSizeOptionHandler类的具体用法?Java WindowSizeOptionHandler怎么用?Java WindowSizeOptionHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WindowSizeOptionHandler类属于org.apache.commons.net.telnet包,在下文中一共展示了WindowSizeOptionHandler类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAcceptNAWS
import org.apache.commons.net.telnet.WindowSizeOptionHandler; //导入依赖的package包/类
@Test
public void testAcceptNAWS() throws Exception {
final AtomicReference<Boolean> serverValue = new AtomicReference<>();
final AtomicReference<int[]> size = new AtomicReference<>();
WindowSizeOptionHandler optionHandler = new WindowSizeOptionHandler(20, 10, false, false, true, false);
testOptionValue(() -> new TelnetHandler() {
@Override
protected void onOpen(TelnetConnection conn) {
conn.writeDoOption(Option.NAWS);
}
@Override
protected void onNAWS(boolean naws) {
serverValue.set(naws);
}
@Override
protected void onSize(int width, int height) {
size.set(new int[]{width, height});
testComplete();
}
}, optionHandler);
assertEquals(true, serverValue.get());
assertEquals(true, optionHandler.getAcceptLocal());
assertEquals(2, size.get().length);
assertEquals(20, size.get()[0]);
assertEquals(10, size.get()[1]);
}
示例2: testSizeHandler
import org.apache.commons.net.telnet.WindowSizeOptionHandler; //导入依赖的package包/类
@Test
public void testSizeHandler() throws Exception {
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
server.start(() -> {
final AtomicInteger count = new AtomicInteger();
return new TelnetTtyConnection(false, false, StandardCharsets.UTF_8, conn -> {
conn.setSizeHandler(size -> {
switch (count.getAndIncrement()) {
case 0:
assertEquals(20, size.getWidth());
assertEquals(10, size.getHeight());
latch1.countDown();
break;
case 1:
assertEquals(80, size.getWidth());
assertEquals(24, size.getHeight());
latch2.countDown();
break;
case 2:
assertEquals(180, size.getWidth());
assertEquals(160, size.getHeight());
testComplete();
break;
default:
fail("Was not expecting that");
}
});
});
});
WindowSizeOptionHandler optionHandler = new WindowSizeOptionHandler(20, 10, false, false, true, false);
client.setOptionHandler(optionHandler);
client.connect("localhost", 4000);
latch1.await(30, TimeUnit.SECONDS);
client.writeDirectAndFlush(new byte[]{TelnetConnection.BYTE_IAC, TelnetConnection.BYTE_SB, 31, 0, 80, 0, 24, TelnetConnection.BYTE_IAC, TelnetConnection.BYTE_SE});
latch2.await(30, TimeUnit.SECONDS);
client.writeDirectAndFlush(new byte[]{TelnetConnection.BYTE_IAC, TelnetConnection.BYTE_SB, 31, 0, (byte) 180, 0, (byte) 160, TelnetConnection.BYTE_IAC, TelnetConnection.BYTE_SE});
await();
}
示例3: testRejectNAWS
import org.apache.commons.net.telnet.WindowSizeOptionHandler; //导入依赖的package包/类
@Test
public void testRejectNAWS() throws Exception {
final AtomicReference<Boolean> serverValue = new AtomicReference<>();
WindowSizeOptionHandler optionHandler = new WindowSizeOptionHandler(20, 10, false, false, false, false);
testOptionValue(new Supplier<TelnetHandler>() {
@Override
public TelnetHandler get() {
return new TelnetHandler() {
@Override
protected void onOpen(TelnetConnection conn) {
conn.writeDoOption(Option.NAWS);
}
@Override
protected void onNAWS(boolean naws) {
serverValue.set(naws);
testComplete();
}
@Override
protected void onSize(int width, int height) {
super.onSize(width, height);
}
};
}
}, optionHandler);
assertEquals(false, serverValue.get());
assertEquals(false, optionHandler.getAcceptLocal());
}
示例4: testWindowSize
import org.apache.commons.net.telnet.WindowSizeOptionHandler; //导入依赖的package包/类
@Test
public void testWindowSize(TestContext context) throws Exception {
Async async = context.async();
startTelnet(context, term -> {
context.assertEquals(-1, term.width());
context.assertEquals(-1, term.height());
term.resizehandler(v -> {
context.assertEquals(10, term.width());
context.assertEquals(20, term.height());
async.complete();
});
});
client.addOptionHandler(new WindowSizeOptionHandler(10, 20, false, false, true, false));
client.connect("localhost", server.actualPort());
}
示例5: testOutBinaryTrue
import org.apache.commons.net.telnet.WindowSizeOptionHandler; //导入依赖的package包/类
@Test
public void testOutBinaryTrue(TestContext context) throws Exception {
startTelnet(context, new TelnetTermOptions().setOutBinary(true), term -> {
term.write("\u20AC");
});
client.addOptionHandler(new WindowSizeOptionHandler(10, 20, false, false, true, false));
client.connect("localhost", server.actualPort());
InputStream in = client.getInputStream();
context.assertEquals(226, in.read());
context.assertEquals(130, in.read());
context.assertEquals(172, in.read());
}
示例6: testOutBinaryFalse
import org.apache.commons.net.telnet.WindowSizeOptionHandler; //导入依赖的package包/类
@Test
public void testOutBinaryFalse(TestContext context) throws Exception {
byte[] expected = StandardCharsets.US_ASCII.encode("€").array();
startTelnet(context, new TelnetTermOptions().setOutBinary(false), term -> {
term.write("\u20AC");
});
client.addOptionHandler(new WindowSizeOptionHandler(10, 20, false, false, true, false));
client.connect("localhost", server.actualPort());
InputStream in = client.getInputStream();
for (int i = 0;i < expected.length;i++) {
context.assertEquals((int)expected[i], in.read());
}
}
示例7: testSizeHandler
import org.apache.commons.net.telnet.WindowSizeOptionHandler; //导入依赖的package包/类
@Test
public void testSizeHandler() throws Exception {
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
server.start(() -> {
final AtomicInteger count = new AtomicInteger();
return new TelnetTtyConnection(false, false, StandardCharsets.UTF_8, conn -> {
conn.setSizeHandler(size -> {
switch (count.getAndIncrement()) {
case 0:
assertEquals(20, size.x());
assertEquals(10, size.y());
latch1.countDown();
break;
case 1:
assertEquals(80, size.x());
assertEquals(24, size.y());
latch2.countDown();
break;
case 2:
assertEquals(180, size.x());
assertEquals(160, size.y());
testComplete();
break;
default:
fail("Was not expecting that");
}
});
});
});
WindowSizeOptionHandler optionHandler = new WindowSizeOptionHandler(20, 10, false, false, true, false);
client.setOptionHandler(optionHandler);
client.connect("localhost", 4000);
latch1.await(30, TimeUnit.SECONDS);
client.writeDirectAndFlush(new byte[]{TelnetConnection.BYTE_IAC, TelnetConnection.BYTE_SB, 31, 0, 80, 0, 24, TelnetConnection.BYTE_IAC, TelnetConnection.BYTE_SE});
latch2.await(30, TimeUnit.SECONDS);
client.writeDirectAndFlush(new byte[]{TelnetConnection.BYTE_IAC, TelnetConnection.BYTE_SB, 31, 0, (byte) 180, 0, (byte) 160, TelnetConnection.BYTE_IAC, TelnetConnection.BYTE_SE});
await();
}
示例8: testSize
import org.apache.commons.net.telnet.WindowSizeOptionHandler; //导入依赖的package包/类
@Override
public void testSize() throws Exception {
wsHandler = new WindowSizeOptionHandler(80, 24, false, false, true, true);
client.setOptionHandler(wsHandler);
super.testSize();
}