Beispiel #1
0
  public static void main(String[] args) throws Exception {
    ServerSocketChannel ssc = ServerSocketChannel.open().bind(new InetSocketAddress(0));
    try {
      InetAddress lh = InetAddress.getLocalHost();
      int port = ((InetSocketAddress) (ssc.getLocalAddress())).getPort();
      SocketAddress remote = new InetSocketAddress(lh, port);

      // Test SocketChannel shutdownXXX
      SocketChannel sc;
      sc = SocketChannel.open(remote);
      try {
        acceptAndReset(ssc);
        sc.shutdownInput();
        sc.shutdownOutput();
      } finally {
        sc.close();
      }

      // Test Socket adapter shutdownXXX and isShutdownInput
      sc = SocketChannel.open(remote);
      try {
        acceptAndReset(ssc);
        boolean before = sc.socket().isInputShutdown();
        sc.socket().shutdownInput();
        boolean after = sc.socket().isInputShutdown();
        if (before || !after) throw new RuntimeException("Before and after test failed");
        sc.socket().shutdownOutput();
      } finally {
        sc.close();
      }
    } finally {
      ssc.close();
    }
  }
 @Override
 public SocketChannel shutdownInput() throws IOException {
   socketChannel = socketChannel.shutdownInput();
   return this;
 }