/* Class416_Sub1 - Decompiled by JODE
 * Visit http://jode.sourceforge.net/
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.Socket;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.List;

public class Class416_Sub1 extends Class416
{
    static final String aString8441 = "java.net.useSystemProxies";
    ProxySelector aProxySelector8442 = ProxySelector.getDefault();
    
    Socket method14033(String string, int i, String string_0_, byte i_1_)
	throws IOException {
	Socket socket = new Socket(string, i);
	socket.setSoTimeout(10000);
	OutputStream outputstream = socket.getOutputStream();
	if (null == string_0_)
	    outputstream.write(new StringBuilder().append("CONNECT ").append
				   (((Class416_Sub1) this).aString6061).append
				   (":").append
				   (((Class416_Sub1) this).anInt6060
				    * 187131581)
				   .append
				   (" HTTP/1.0\n\n").toString
				   ().getBytes(Charset.forName("ISO-8859-1")));
	else
	    outputstream.write(new StringBuilder().append("CONNECT ").append
				   (((Class416_Sub1) this).aString6061).append
				   (":").append
				   (((Class416_Sub1) this).anInt6060
				    * 187131581)
				   .append
				   (" HTTP/1.0\n").append
				   (string_0_).append
				   ("\n\n").toString
				   ().getBytes(Charset.forName("ISO-8859-1")));
	outputstream.flush();
	BufferedReader bufferedreader
	    = new BufferedReader(new InputStreamReader(socket
							   .getInputStream()));
	String string_2_ = bufferedreader.readLine();
	if (null != string_2_) {
	    if (string_2_.startsWith("HTTP/1.0 200")
		|| string_2_.startsWith("HTTP/1.1 200"))
		return socket;
	    if (string_2_.startsWith("HTTP/1.0 407")
		|| string_2_.startsWith("HTTP/1.1 407")) {
		int i_3_ = 0;
		String string_4_ = "proxy-authenticate: ";
		for (string_2_ = bufferedreader.readLine();
		     null != string_2_ && i_3_ < 50; i_3_++) {
		    if (string_2_.toLowerCase().startsWith(string_4_)) {
			string_2_
			    = string_2_.substring(string_4_.length()).trim();
			int i_5_ = string_2_.indexOf(' ');
			if (-1 != i_5_)
			    string_2_ = string_2_.substring(0, i_5_);
			throw new IOException_Sub1(string_2_);
		    }
		    string_2_ = bufferedreader.readLine();
		}
		throw new IOException_Sub1("");
	    }
	}
	outputstream.close();
	bufferedreader.close();
	socket.close();
	return null;
    }
    
    public Socket method7408(byte i) throws IOException {
	boolean bool = (Boolean.parseBoolean
			(System.getProperty("java.net.useSystemProxies")));
	if (!bool)
	    System.setProperty("java.net.useSystemProxies", "true");
	boolean bool_6_ = 443 == 187131581 * ((Class416_Sub1) this).anInt6060;
	List list;
	List list_7_;
	try {
	    list = (((Class416_Sub1) this).aProxySelector8442.select
		    (new URI(new StringBuilder().append
				 (bool_6_ ? "https" : "http").append
				 ("://").append
				 (((Class416_Sub1) this).aString6061)
				 .toString())));
	    list_7_ = (((Class416_Sub1) this).aProxySelector8442.select
		       (new URI(new StringBuilder().append
				    (bool_6_ ? "http" : "https").append
				    ("://").append
				    (((Class416_Sub1) this).aString6061)
				    .toString())));
	} catch (URISyntaxException urisyntaxexception) {
	    return method7405(2029449492);
	}
	list.addAll(list_7_);
	Object[] objects = list.toArray();
	IOException_Sub1 ioexception_sub1 = null;
	Object[] objects_8_ = objects;
	for (int i_9_ = 0; i_9_ < objects_8_.length; i_9_++) {
	    Object object = objects_8_[i_9_];
	    Proxy proxy = (Proxy) object;
	    Socket socket;
	    try {
		Socket socket_10_ = method14034(proxy, (byte) -53);
		if (socket_10_ == null)
		    continue;
		socket = socket_10_;
	    } catch (IOException_Sub1 ioexception_sub1_11_) {
		ioexception_sub1 = ioexception_sub1_11_;
		continue;
	    } catch (IOException ioexception) {
		continue;
	    }
	    return socket;
	}
	if (ioexception_sub1 != null)
	    throw ioexception_sub1;
	return method7405(888779443);
    }
    
    Socket method14034(Proxy proxy, byte i) throws IOException {
	if (proxy.type() == Proxy.Type.DIRECT)
	    return method7405(-110977496);
	java.net.SocketAddress socketaddress = proxy.address();
	if (!(socketaddress instanceof InetSocketAddress))
	    return null;
	InetSocketAddress inetsocketaddress
	    = (InetSocketAddress) socketaddress;
	if (proxy.type() == Proxy.Type.HTTP) {
	    String string = null;
	    try {
		Class var_class
		    = (Class.forName
		       ("sun.net.www.protocol.http.AuthenticationInfo"));
		Method method
		    = var_class.getDeclaredMethod("getProxyAuth",
						  (new Class[]
						   { java.lang.String.class,
						     Integer.TYPE }));
		method.setAccessible(true);
		Object object
		    = method.invoke(null, (new Object[]
					   { inetsocketaddress.getHostName(),
					     new Integer(inetsocketaddress
							     .getPort()) }));
		if (object != null) {
		    Method method_12_
			= (var_class.getDeclaredMethod
			   ("supportsPreemptiveAuthorization", new Class[0]));
		    method_12_.setAccessible(true);
		    if (((Boolean) method_12_.invoke(object, new Object[0]))
			    .booleanValue()) {
			Method method_13_
			    = var_class.getDeclaredMethod("getHeaderName",
							  new Class[0]);
			method_13_.setAccessible(true);
			Method method_14_
			    = (var_class.getDeclaredMethod
			       ("getHeaderValue",
				new Class[] { java.net.URL.class,
					      java.lang.String.class }));
			method_14_.setAccessible(true);
			String string_15_
			    = ((String)
			       method_13_.invoke(object, new Object[0]));
			String string_16_
			    = ((String)
			       (method_14_.invoke
				(object, (new Object[]
					  { new URL(new StringBuilder().append
							("https://").append
							(((Class416_Sub1) this)
							 .aString6061)
							.append
							("/").toString()),
					    "https" }))));
			string = new StringBuilder().append(string_15_).append
				     (": ").append
				     (string_16_).toString();
		    }
		}
	    } catch (Exception exception) {
		/* empty */
	    }
	    return method14033(inetsocketaddress.getHostName(),
			       inetsocketaddress.getPort(), string,
			       (byte) -87);
	}
	if (proxy.type() == Proxy.Type.SOCKS) {
	    Socket socket = new Socket(proxy);
	    socket.connect(new InetSocketAddress((((Class416_Sub1) this)
						  .aString6061),
						 (187131581
						  * (((Class416_Sub1) this)
						     .anInt6060))));
	    return socket;
	}
	return null;
    }
    
    Socket method14035(Proxy proxy) throws IOException {
	if (proxy.type() == Proxy.Type.DIRECT)
	    return method7405(451800503);
	java.net.SocketAddress socketaddress = proxy.address();
	if (!(socketaddress instanceof InetSocketAddress))
	    return null;
	InetSocketAddress inetsocketaddress
	    = (InetSocketAddress) socketaddress;
	if (proxy.type() == Proxy.Type.HTTP) {
	    String string = null;
	    try {
		Class var_class
		    = (Class.forName
		       ("sun.net.www.protocol.http.AuthenticationInfo"));
		Method method
		    = var_class.getDeclaredMethod("getProxyAuth",
						  (new Class[]
						   { java.lang.String.class,
						     Integer.TYPE }));
		method.setAccessible(true);
		Object object
		    = method.invoke(null, (new Object[]
					   { inetsocketaddress.getHostName(),
					     new Integer(inetsocketaddress
							     .getPort()) }));
		if (object != null) {
		    Method method_17_
			= (var_class.getDeclaredMethod
			   ("supportsPreemptiveAuthorization", new Class[0]));
		    method_17_.setAccessible(true);
		    if (((Boolean) method_17_.invoke(object, new Object[0]))
			    .booleanValue()) {
			Method method_18_
			    = var_class.getDeclaredMethod("getHeaderName",
							  new Class[0]);
			method_18_.setAccessible(true);
			Method method_19_
			    = (var_class.getDeclaredMethod
			       ("getHeaderValue",
				new Class[] { java.net.URL.class,
					      java.lang.String.class }));
			method_19_.setAccessible(true);
			String string_20_
			    = ((String)
			       method_18_.invoke(object, new Object[0]));
			String string_21_
			    = ((String)
			       (method_19_.invoke
				(object, (new Object[]
					  { new URL(new StringBuilder().append
							("https://").append
							(((Class416_Sub1) this)
							 .aString6061)
							.append
							("/").toString()),
					    "https" }))));
			string = new StringBuilder().append(string_20_).append
				     (": ").append
				     (string_21_).toString();
		    }
		}
	    } catch (Exception exception) {
		/* empty */
	    }
	    return method14033(inetsocketaddress.getHostName(),
			       inetsocketaddress.getPort(), string, (byte) 51);
	}
	if (proxy.type() == Proxy.Type.SOCKS) {
	    Socket socket = new Socket(proxy);
	    socket.connect(new InetSocketAddress((((Class416_Sub1) this)
						  .aString6061),
						 (187131581
						  * (((Class416_Sub1) this)
						     .anInt6060))));
	    return socket;
	}
	return null;
    }
    
    Socket method14036(Proxy proxy) throws IOException {
	if (proxy.type() == Proxy.Type.DIRECT)
	    return method7405(1502420194);
	java.net.SocketAddress socketaddress = proxy.address();
	if (!(socketaddress instanceof InetSocketAddress))
	    return null;
	InetSocketAddress inetsocketaddress
	    = (InetSocketAddress) socketaddress;
	if (proxy.type() == Proxy.Type.HTTP) {
	    String string = null;
	    try {
		Class var_class
		    = (Class.forName
		       ("sun.net.www.protocol.http.AuthenticationInfo"));
		Method method
		    = var_class.getDeclaredMethod("getProxyAuth",
						  (new Class[]
						   { java.lang.String.class,
						     Integer.TYPE }));
		method.setAccessible(true);
		Object object
		    = method.invoke(null, (new Object[]
					   { inetsocketaddress.getHostName(),
					     new Integer(inetsocketaddress
							     .getPort()) }));
		if (object != null) {
		    Method method_22_
			= (var_class.getDeclaredMethod
			   ("supportsPreemptiveAuthorization", new Class[0]));
		    method_22_.setAccessible(true);
		    if (((Boolean) method_22_.invoke(object, new Object[0]))
			    .booleanValue()) {
			Method method_23_
			    = var_class.getDeclaredMethod("getHeaderName",
							  new Class[0]);
			method_23_.setAccessible(true);
			Method method_24_
			    = (var_class.getDeclaredMethod
			       ("getHeaderValue",
				new Class[] { java.net.URL.class,
					      java.lang.String.class }));
			method_24_.setAccessible(true);
			String string_25_
			    = ((String)
			       method_23_.invoke(object, new Object[0]));
			String string_26_
			    = ((String)
			       (method_24_.invoke
				(object, (new Object[]
					  { new URL(new StringBuilder().append
							("https://").append
							(((Class416_Sub1) this)
							 .aString6061)
							.append
							("/").toString()),
					    "https" }))));
			string = new StringBuilder().append(string_25_).append
				     (": ").append
				     (string_26_).toString();
		    }
		}
	    } catch (Exception exception) {
		/* empty */
	    }
	    return method14033(inetsocketaddress.getHostName(),
			       inetsocketaddress.getPort(), string,
			       (byte) -114);
	}
	if (proxy.type() == Proxy.Type.SOCKS) {
	    Socket socket = new Socket(proxy);
	    socket.connect(new InetSocketAddress((((Class416_Sub1) this)
						  .aString6061),
						 (187131581
						  * (((Class416_Sub1) this)
						     .anInt6060))));
	    return socket;
	}
	return null;
    }
    
    Socket method14037(Proxy proxy) throws IOException {
	if (proxy.type() == Proxy.Type.DIRECT)
	    return method7405(1594585036);
	java.net.SocketAddress socketaddress = proxy.address();
	if (!(socketaddress instanceof InetSocketAddress))
	    return null;
	InetSocketAddress inetsocketaddress
	    = (InetSocketAddress) socketaddress;
	if (proxy.type() == Proxy.Type.HTTP) {
	    String string = null;
	    try {
		Class var_class
		    = (Class.forName
		       ("sun.net.www.protocol.http.AuthenticationInfo"));
		Method method
		    = var_class.getDeclaredMethod("getProxyAuth",
						  (new Class[]
						   { java.lang.String.class,
						     Integer.TYPE }));
		method.setAccessible(true);
		Object object
		    = method.invoke(null, (new Object[]
					   { inetsocketaddress.getHostName(),
					     new Integer(inetsocketaddress
							     .getPort()) }));
		if (object != null) {
		    Method method_27_
			= (var_class.getDeclaredMethod
			   ("supportsPreemptiveAuthorization", new Class[0]));
		    method_27_.setAccessible(true);
		    if (((Boolean) method_27_.invoke(object, new Object[0]))
			    .booleanValue()) {
			Method method_28_
			    = var_class.getDeclaredMethod("getHeaderName",
							  new Class[0]);
			method_28_.setAccessible(true);
			Method method_29_
			    = (var_class.getDeclaredMethod
			       ("getHeaderValue",
				new Class[] { java.net.URL.class,
					      java.lang.String.class }));
			method_29_.setAccessible(true);
			String string_30_
			    = ((String)
			       method_28_.invoke(object, new Object[0]));
			String string_31_
			    = ((String)
			       (method_29_.invoke
				(object, (new Object[]
					  { new URL(new StringBuilder().append
							("https://").append
							(((Class416_Sub1) this)
							 .aString6061)
							.append
							("/").toString()),
					    "https" }))));
			string = new StringBuilder().append(string_30_).append
				     (": ").append
				     (string_31_).toString();
		    }
		}
	    } catch (Exception exception) {
		/* empty */
	    }
	    return method14033(inetsocketaddress.getHostName(),
			       inetsocketaddress.getPort(), string, (byte) 36);
	}
	if (proxy.type() == Proxy.Type.SOCKS) {
	    Socket socket = new Socket(proxy);
	    socket.connect(new InetSocketAddress((((Class416_Sub1) this)
						  .aString6061),
						 (187131581
						  * (((Class416_Sub1) this)
						     .anInt6060))));
	    return socket;
	}
	return null;
    }
    
    Socket method14038(String string, int i, String string_32_)
	throws IOException {
	Socket socket = new Socket(string, i);
	socket.setSoTimeout(10000);
	OutputStream outputstream = socket.getOutputStream();
	if (null == string_32_)
	    outputstream.write(new StringBuilder().append("CONNECT ").append
				   (((Class416_Sub1) this).aString6061).append
				   (":").append
				   (((Class416_Sub1) this).anInt6060
				    * 187131581)
				   .append
				   (" HTTP/1.0\n\n").toString
				   ().getBytes(Charset.forName("ISO-8859-1")));
	else
	    outputstream.write(new StringBuilder().append("CONNECT ").append
				   (((Class416_Sub1) this).aString6061).append
				   (":").append
				   (((Class416_Sub1) this).anInt6060
				    * 187131581)
				   .append
				   (" HTTP/1.0\n").append
				   (string_32_).append
				   ("\n\n").toString
				   ().getBytes(Charset.forName("ISO-8859-1")));
	outputstream.flush();
	BufferedReader bufferedreader
	    = new BufferedReader(new InputStreamReader(socket
							   .getInputStream()));
	String string_33_ = bufferedreader.readLine();
	if (null != string_33_) {
	    if (string_33_.startsWith("HTTP/1.0 200")
		|| string_33_.startsWith("HTTP/1.1 200"))
		return socket;
	    if (string_33_.startsWith("HTTP/1.0 407")
		|| string_33_.startsWith("HTTP/1.1 407")) {
		int i_34_ = 0;
		String string_35_ = "proxy-authenticate: ";
		for (string_33_ = bufferedreader.readLine();
		     null != string_33_ && i_34_ < 50; i_34_++) {
		    if (string_33_.toLowerCase().startsWith(string_35_)) {
			string_33_
			    = string_33_.substring(string_35_.length()).trim();
			int i_36_ = string_33_.indexOf(' ');
			if (-1 != i_36_)
			    string_33_ = string_33_.substring(0, i_36_);
			throw new IOException_Sub1(string_33_);
		    }
		    string_33_ = bufferedreader.readLine();
		}
		throw new IOException_Sub1("");
	    }
	}
	outputstream.close();
	bufferedreader.close();
	socket.close();
	return null;
    }
    
    Class416_Sub1() {
	/* empty */
    }
    
    Socket method14039(String string, int i, String string_37_)
	throws IOException {
	Socket socket = new Socket(string, i);
	socket.setSoTimeout(10000);
	OutputStream outputstream = socket.getOutputStream();
	if (null == string_37_)
	    outputstream.write(new StringBuilder().append("CONNECT ").append
				   (((Class416_Sub1) this).aString6061).append
				   (":").append
				   (((Class416_Sub1) this).anInt6060
				    * 187131581)
				   .append
				   (" HTTP/1.0\n\n").toString
				   ().getBytes(Charset.forName("ISO-8859-1")));
	else
	    outputstream.write(new StringBuilder().append("CONNECT ").append
				   (((Class416_Sub1) this).aString6061).append
				   (":").append
				   (((Class416_Sub1) this).anInt6060
				    * 187131581)
				   .append
				   (" HTTP/1.0\n").append
				   (string_37_).append
				   ("\n\n").toString
				   ().getBytes(Charset.forName("ISO-8859-1")));
	outputstream.flush();
	BufferedReader bufferedreader
	    = new BufferedReader(new InputStreamReader(socket
							   .getInputStream()));
	String string_38_ = bufferedreader.readLine();
	if (null != string_38_) {
	    if (string_38_.startsWith("HTTP/1.0 200")
		|| string_38_.startsWith("HTTP/1.1 200"))
		return socket;
	    if (string_38_.startsWith("HTTP/1.0 407")
		|| string_38_.startsWith("HTTP/1.1 407")) {
		int i_39_ = 0;
		String string_40_ = "proxy-authenticate: ";
		for (string_38_ = bufferedreader.readLine();
		     null != string_38_ && i_39_ < 50; i_39_++) {
		    if (string_38_.toLowerCase().startsWith(string_40_)) {
			string_38_
			    = string_38_.substring(string_40_.length()).trim();
			int i_41_ = string_38_.indexOf(' ');
			if (-1 != i_41_)
			    string_38_ = string_38_.substring(0, i_41_);
			throw new IOException_Sub1(string_38_);
		    }
		    string_38_ = bufferedreader.readLine();
		}
		throw new IOException_Sub1("");
	    }
	}
	outputstream.close();
	bufferedreader.close();
	socket.close();
	return null;
    }
    
    public Socket method7404() throws IOException {
	boolean bool = (Boolean.parseBoolean
			(System.getProperty("java.net.useSystemProxies")));
	if (!bool)
	    System.setProperty("java.net.useSystemProxies", "true");
	boolean bool_42_ = 443 == 187131581 * ((Class416_Sub1) this).anInt6060;
	List list;
	List list_43_;
	try {
	    list = (((Class416_Sub1) this).aProxySelector8442.select
		    (new URI(new StringBuilder().append
				 (bool_42_ ? "https" : "http").append
				 ("://").append
				 (((Class416_Sub1) this).aString6061)
				 .toString())));
	    list_43_ = (((Class416_Sub1) this).aProxySelector8442.select
			(new URI(new StringBuilder().append
				     (bool_42_ ? "http" : "https").append
				     ("://").append
				     (((Class416_Sub1) this).aString6061)
				     .toString())));
	} catch (URISyntaxException urisyntaxexception) {
	    return method7405(1932079366);
	}
	list.addAll(list_43_);
	Object[] objects = list.toArray();
	IOException_Sub1 ioexception_sub1 = null;
	Object[] objects_44_ = objects;
	for (int i = 0; i < objects_44_.length; i++) {
	    Object object = objects_44_[i];
	    Proxy proxy = (Proxy) object;
	    Socket socket;
	    try {
		Socket socket_45_ = method14034(proxy, (byte) 17);
		if (socket_45_ == null)
		    continue;
		socket = socket_45_;
	    } catch (IOException_Sub1 ioexception_sub1_46_) {
		ioexception_sub1 = ioexception_sub1_46_;
		continue;
	    } catch (IOException ioexception) {
		continue;
	    }
	    return socket;
	}
	if (ioexception_sub1 != null)
	    throw ioexception_sub1;
	return method7405(1408666972);
    }
}
