當前位置: 首頁>>代碼示例>>Java>>正文


Java WindowSizeOptionHandler類代碼示例

本文整理匯總了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]);
}
 
開發者ID:aeshell,項目名稱:aesh-readline,代碼行數:27,代碼來源:TelnetHandlerTest.java

示例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();
}
 
開發者ID:aeshell,項目名稱:aesh-readline,代碼行數:40,代碼來源:TelnetTermTest.java

示例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());
}
 
開發者ID:aeshell,項目名稱:aesh-readline,代碼行數:28,代碼來源:TelnetHandlerTest.java

示例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());
}
 
開發者ID:vert-x3,項目名稱:vertx-shell,代碼行數:16,代碼來源:TelnetTermServerTest.java

示例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());
}
 
開發者ID:vert-x3,項目名稱:vertx-shell,代碼行數:13,代碼來源:TelnetTermServerTest.java

示例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());
  }
}
 
開發者ID:vert-x3,項目名稱:vertx-shell,代碼行數:14,代碼來源:TelnetTermServerTest.java

示例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();
}
 
開發者ID:termd,項目名稱:termd,代碼行數:40,代碼來源:TelnetTermTest.java

示例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();
}
 
開發者ID:aeshell,項目名稱:aesh-readline,代碼行數:7,代碼來源:TelnetTtyTestBase.java


注:本文中的org.apache.commons.net.telnet.WindowSizeOptionHandler類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。