code: private IoBuffer encodeProxyRequestPacket(final SocksProxyRequest request)
              throws UnsupportedEncodingException {
          int len = 6;
          InetSocketAddress adr = request.getEndpointAddress();
          byte addressType = 0;
          byte[] host = null;
          
          if (adr != null && !adr.isUnresolved()) {
              if (adr.getAddress() instanceof Inet6Address) {
                  len += 16;
                  addressType = SocksProxyConstants.IPV6_ADDRESS_TYPE;
              } else if (adr.getAddress() instanceof Inet4Address) {
                  len += 4;
                  addressType = SocksProxyConstants.IPV4_ADDRESS_TYPE;
              }
          } else {
              host = request.getHost() != null ? 
                      request.getHost().getBytes("ASCII") : null;
  
              if (host != null) {
                  len += 1 + host.length;
                  addressType = SocksProxyConstants.DOMAIN_NAME_ADDRESS_TYPE;
              } else {
                  throw new IllegalArgumentException("SocksProxyRequest object " +
                          "has no suitable endpoint information");
              }
          }
          
          IoBuffer buf = IoBuffer.allocate(len);
  
          buf.put(request.getProtocolVersion());
          buf.put(request.getCommandCode());
          buf.put((byte) 0x00); // Reserved
          buf.put(addressType);
  
          if (host == null) {
              buf.put(request.getIpAddress());
          } else {
              buf.put((byte) host.length);
              buf.put(host);            
          }
  
          buf.put(request.getPort());
  
          return buf;
      }
docs: Encodes the proxy authorization request packet.
  
  @param request the socks proxy request data
  @return the encoded buffer
  @throws UnsupportedEncodingException if request's hostname charset
  can't be converted to ASCII.