⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hostnametoipresolver.java

📁 java 文件下载器。可自定义
💻 JAVA
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space 
// Source File Name:   HostNameToIPResolver.java

package org.gudy.azureus2.core3.util;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;

// Referenced classes of package org.gudy.azureus2.core3.util:
//			AEMonitor, AENetworkClassifier, AESemaphore, AEThread2, 
//			HostNameToIPResolverException, HostNameToIPResolverListener, Debug

public class HostNameToIPResolver
{
	protected static class request
	{

		protected String host;
		protected HostNameToIPResolverListener listener;

		protected String getHost()
		{
			return host;
		}

		protected HostNameToIPResolverListener getListener()
		{
			return listener;
		}

		protected request(String _host, HostNameToIPResolverListener _listener)
		{
			host = _host;
			listener = _listener;
		}
	}


	protected static AEThread2 resolver_thread;
	protected static List request_queue = new ArrayList();
	protected static AEMonitor request_queue_mon = new AEMonitor("HostNameToIPResolver");
	protected static AESemaphore request_semaphore = new AESemaphore("HostNameToIPResolver");
	static final int INADDRSZ = 4;

	public HostNameToIPResolver()
	{
	}

	public static boolean isNonDNSName(String host)
	{
		return AENetworkClassifier.categoriseAddress(host) != "Public";
	}

	public static InetAddress syncResolve(String host)
		throws UnknownHostException
	{
		if (isNonDNSName(host))
			throw new HostNameToIPResolverException((new StringBuilder()).append("non-DNS name '").append(host).append("'").toString(), true);
		byte bytes[] = textToNumericFormat(host);
		if (bytes != null)
			return InetAddress.getByAddress(bytes);
		char chars[] = host.toCharArray();
		boolean resolve = false;
		int i = 0;
		do
		{
			if (i >= chars.length)
				break;
			if (chars[i] != '.' && !Character.isDigit(chars[i]))
			{
				resolve = true;
				break;
			}
			i++;
		} while (true);
		if (resolve)
			return InetAddress.getByName(host);
		else
			throw new UnknownHostException((new StringBuilder()).append("Host '").append(host).append("' doesn't obey minimal validation rules").toString());
	}

	public static void addResolverRequest(String host, HostNameToIPResolverListener l)
	{
		byte bytes[] = textToNumericFormat(host);
		if (bytes != null)
			try
			{
				l.hostNameResolutionComplete(InetAddress.getByAddress(host, bytes));
				return;
			}
			catch (UnknownHostException e) { }
		request_queue_mon.enter();
		request_queue.add(new request(host, l));
		request_semaphore.release();
		if (resolver_thread == null)
		{
			resolver_thread = new AEThread2("HostNameToIPResolver", true) {

				public void run()
				{
_L2:
					HostNameToIPResolver.request_semaphore.reserve(30000L);
					HostNameToIPResolver.request_queue_mon.enter();
					if (!HostNameToIPResolver.request_queue.isEmpty())
						break MISSING_BLOCK_LABEL_40;
					HostNameToIPResolver.resolver_thread = null;
					HostNameToIPResolver.request_queue_mon.exit();
					break; /* Loop/switch isn't completed */
					request req = (request)HostNameToIPResolver.request_queue.remove(0);
					HostNameToIPResolver.request_queue_mon.exit();
					break MISSING_BLOCK_LABEL_71;
					Exception exception1;
					exception1;
					HostNameToIPResolver.request_queue_mon.exit();
					throw exception1;
					try
					{
						InetAddress addr = HostNameToIPResolver.syncResolve(req.getHost());
						req.getListener().hostNameResolutionComplete(addr);
					}
					catch (Throwable e)
					{
						req.getListener().hostNameResolutionComplete(null);
					}
					continue; /* Loop/switch isn't completed */
					Throwable e;
					e;
					Debug.printStackTrace(e);
					if (true) goto _L2; else goto _L1
_L1:
				}

			};
			resolver_thread.start();
		}
		request_queue_mon.exit();
		break MISSING_BLOCK_LABEL_97;
		Exception exception;
		exception;
		request_queue_mon.exit();
		throw exception;
	}

	public static byte[] hostAddressToBytes(String host)
	{
		byte res[] = textToNumericFormat(host);
		return res;
	}

	static byte[] textToNumericFormat(String src)
	{
		if (src.length() == 0)
			return null;
		if (src.indexOf(':') == -1)
			break MISSING_BLOCK_LABEL_30;
		return InetAddress.getByName(src).getAddress();
		Throwable e;
		e;
		return null;
		byte dst[] = new byte[4];
		char srcb[] = src.toCharArray();
		boolean saw_digit = false;
		int octets = 0;
		int i = 0;
		int cur = 0;
		do
		{
			if (i >= srcb.length)
				break;
			char ch = srcb[i++];
			if (Character.isDigit(ch))
			{
				int sum = (dst[cur] & 0xff) * 10 + (Character.digit(ch, 10) & 0xff);
				if (sum > 255)
					return null;
				dst[cur] = (byte)(sum & 0xff);
				if (!saw_digit)
				{
					if (++octets > 4)
						return null;
					saw_digit = true;
				}
			} else
			if (ch == '.' && saw_digit)
			{
				if (octets == 4)
					return null;
				cur++;
				dst[cur] = 0;
				saw_digit = false;
			} else
			{
				return null;
			}
		} while (true);
		if (octets < 4)
			return null;
		else
			return dst;
	}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -