code: private static Channel createChannel() throws IOException {
  
          // dup the file descriptor - we do this so that for two reasons :-
          // 1. Avoids any timing issues with FileDescriptor.in being closed
          //    or redirected while we create the channel.
          // 2. Allows streams based on file descriptor 0 to co-exist with
          //    the channel (closing one doesn't impact the other)
  
          int fdVal = dup(0);
  
          // Examine the file descriptor - if it's not a socket then we don't
          // create a channel so we release the file descriptor.
  
          int st;
          st = soType0(fdVal);
          if (st != SOCK_STREAM && st != SOCK_DGRAM) {
              close0(fdVal);
              return null;
          }
  
  
          // Next we create a FileDescriptor for the dup'ed file descriptor
          // Have to use reflection and also make assumption on how FD
          // is implemented.
  
          Class paramTypes[] = { int.class };
          Constructor ctr = Reflect.lookupConstructor("java.io.FileDescriptor",
                                                      paramTypes);
          Object args[] = { new Integer(fdVal) };
          FileDescriptor fd = (FileDescriptor)Reflect.invoke(ctr, args);
  
  
          // Now create the channel. If the socket is a streams socket then
          // we see if tthere is a peer (ie: connected). If so, then we
          // create a SocketChannel, otherwise a ServerSocketChannel.
          // If the socket is a datagram socket then create a DatagramChannel
  
          SelectorProvider provider = SelectorProvider.provider();
          assert provider instanceof sun.nio.ch.SelectorProviderImpl;
  
          Channel c;
          if (st == SOCK_STREAM) {
              InetAddress ia = peerAddress0(fdVal);
              if (ia == null) {
                 c = new InheritedServerSocketChannelImpl(provider, fd);
              } else {
                 int port = peerPort0(fdVal);
                 assert port > 0;
                 InetSocketAddress isa = new InetSocketAddress(ia, port);
                 c = new InheritedSocketChannelImpl(provider, fd, isa);
              }
          } else {
              c = new InheritedDatagramChannelImpl(provider, fd);
          }
          return c;
      }
docs: /*
  If standard inherited channel is connected to a socket then return a Channel
  of the appropriate type based standard input.