public void read ( InputStream in , boolean clientMode ) throws SocksException , IOException { data = null ; ip = null ; DataInputStream di = new DataInputStream ( in ) ; version = di . readUnsignedByte ( ) ; command = di . readUnsignedByte ( ) ; if ( clientMode && command != 0 ) throw new SocksException ( command ) ; @ SuppressWarnings ( "unused" ) int reserved = di . readUnsignedByte ( ) ; addrType = di . readUnsignedByte ( ) ; byte addr [ ] ; switch ( addrType ) { case SOCKS_ATYP_IPV4 : addr = new byte [ 4 ] ; di . readFully ( addr ) ; host = bytes2IPV4 ( addr , 0 ) ; break ; case SOCKS_ATYP_IPV6 : addr = new byte [ SOCKS_IPV6_LENGTH ] ; //I believe it is 16 bytes,huge! di . readFully ( addr ) ; host = bytes2IPV6 ( addr , 0 ) ; break ; case SOCKS_ATYP_DOMAINNAME : //System.out.println("Reading ATYP_DOMAINNAME"); addr = new byte [ di . readUnsignedByte ( ) ] ; //Next byte shows the length di . readFully ( addr ) ; host = new String ( addr ) ; break ; default : throw ( new SocksException ( Proxy . SOCKS_JUST_ERROR ) ) ; } port = di . readUnsignedShort ( ) ; if ( addrType != SOCKS_ATYP_DOMAINNAME && doResolveIP ) { try { ip = InetAddress . getByName ( host ) ; } catch ( UnknownHostException uh_ex ) { } } }
Initialises Message from the stream . Reads server response or client request from given stream .