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

📄 externalipcheckerserviceimpl.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:   ExternalIPCheckerServiceImpl.java

package org.gudy.azureus2.core3.ipchecker.extipchecker.impl;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Vector;
import org.gudy.azureus2.core3.internat.MessageText;
import org.gudy.azureus2.core3.ipchecker.extipchecker.ExternalIPCheckerService;
import org.gudy.azureus2.core3.ipchecker.extipchecker.ExternalIPCheckerServiceListener;
import org.gudy.azureus2.core3.util.*;

public abstract class ExternalIPCheckerServiceImpl
	implements ExternalIPCheckerService, Cloneable
{

	private static final int MAX_PAGE_SIZE = 4096;
	private static final String MSG_KEY_ROOT = "IPChecker.external";
	private String name;
	private String description;
	private String url;
	private boolean completed;
	private Vector listeners;
	private AEMonitor this_mon;
	private AESemaphore timeout_sem;

	protected ExternalIPCheckerServiceImpl(String name_key)
	{
		listeners = new Vector();
		this_mon = new AEMonitor("ExtIPCheckServ");
		timeout_sem = new AESemaphore("ExtIPCheckServ");
		name = MessageText.getString((new StringBuilder()).append(name_key).append(".name").toString());
		description = MessageText.getString((new StringBuilder()).append(name_key).append(".description").toString());
		url = MessageText.getString((new StringBuilder()).append(name_key).append(".url").toString());
	}

	public void initiateCheck(long timeout)
	{
		_clone().initiateCheckSupport(timeout);
	}

	protected ExternalIPCheckerServiceImpl _clone()
	{
		return (ExternalIPCheckerServiceImpl)clone();
		CloneNotSupportedException e;
		e;
		Debug.printStackTrace(e);
		return null;
	}

	protected void initiateCheckSupport(long timeout)
	{
		Thread t = new AEThread("IPChecker") {

			final ExternalIPCheckerServiceImpl this$0;

			public void runSupport()
			{
				initiateCheckSupport();
				setComplete();
				break MISSING_BLOCK_LABEL_27;
				Exception exception;
				exception;
				setComplete();
				throw exception;
			}

			
			{
				this$0 = ExternalIPCheckerServiceImpl.this;
				super(x0);
			}
		};
		t.setDaemon(true);
		t.start();
		if (timeout > 0L)
		{
			Thread t2 = new AEThread(timeout) {

				final long val$timeout;
				final ExternalIPCheckerServiceImpl this$0;

				public void runSupport()
				{
					try
					{
						if (!timeout_sem.reserve(timeout) && !completed)
						{
							informFailure("timeout");
							setComplete();
						}
					}
					catch (Throwable e)
					{
						Debug.printStackTrace(e);
					}
				}

			
			{
				this$0 = ExternalIPCheckerServiceImpl.this;
				timeout = l;
				super(x0);
			}
			};
			t2.setDaemon(true);
			t2.start();
		}
	}

	protected abstract void initiateCheckSupport();

	protected void setComplete()
	{
		completed = true;
	}

	protected String loadPage(String url_string)
	{
		URL url;
		HttpURLConnection connection;
		InputStream is;
		url = new URL(url_string);
		connection = null;
		is = null;
		int response;
		String s1;
		connection = (HttpURLConnection)url.openConnection();
		response = connection.getResponseCode();
		if (response != 202 && response != 200)
			break MISSING_BLOCK_LABEL_159;
		is = connection.getInputStream();
		String page = "";
		do
		{
			if (page.length() >= 4096)
				break;
			byte buffer[] = new byte[2048];
			int len = is.read(buffer);
			if (len < 0)
				break;
			page = (new StringBuilder()).append(page).append(new String(buffer, 0, len)).toString();
		} while (true);
		s1 = page;
		try
		{
			if (is != null)
				is.close();
			if (connection != null)
				connection.disconnect();
		}
		catch (Throwable e)
		{
			Debug.printStackTrace(e);
		}
		return s1;
		String s;
		informFailure("httpinvalidresponse", (new StringBuilder()).append("").append(response).toString());
		s = null;
		try
		{
			if (is != null)
				is.close();
			if (connection != null)
				connection.disconnect();
		}
		catch (Throwable e)
		{
			Debug.printStackTrace(e);
		}
		return s;
		Exception exception;
		exception;
		try
		{
			if (is != null)
				is.close();
			if (connection != null)
				connection.disconnect();
		}
		catch (Throwable e)
		{
			Debug.printStackTrace(e);
		}
		throw exception;
		Throwable e;
		e;
		informFailure("httploadfail", e.toString());
		return null;
	}

	protected String extractIPAddress(String str)
	{
		int p1;
		for (int pos = 0; pos < str.length(); pos = p1 + 1)
		{
			p1 = str.indexOf('.', pos);
			if (p1 == -1)
			{
				informFailure("ipnotfound");
				return null;
			}
			if (p1 <= 0 || !Character.isDigit(str.charAt(p1 - 1)))
				continue;
			int p2;
			for (p2 = p1 - 1; p2 >= 0 && Character.isDigit(str.charAt(p2)); p2--);
			int p3 = ++p2 + 1;
			int dots = 0;
			for (; p3 < str.length(); p3++)
			{
				char c = str.charAt(p3);
				if (c == '.')
				{
					dots++;
					continue;
				}
				if (!Character.isDigit(c))
					break;
			}

			if (dots == 3)
				return str.substring(p2, p3);
		}

		informFailure("ipnotfound");
		return null;
	}

	public String getName()
	{
		return name;
	}

	public String getDescription()
	{
		return description;
	}

	public String getURL()
	{
		return url;
	}

	protected void informSuccess(String ip)
	{
		this_mon.enter();
		if (!completed)
		{
			timeout_sem.releaseForever();
			for (int i = 0; i < listeners.size(); i++)
				((ExternalIPCheckerServiceListener)listeners.elementAt(i)).checkComplete(this, ip);

		}
		this_mon.exit();
		break MISSING_BLOCK_LABEL_78;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	protected void informFailure(String msg_key)
	{
		this_mon.enter();
		informFailure(msg_key, null);
		this_mon.exit();
		break MISSING_BLOCK_LABEL_33;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	protected void informFailure(String msg_key, String extra)
	{
		this_mon.enter();
		if (!completed)
		{
			timeout_sem.releaseForever();
			String message = MessageText.getString((new StringBuilder()).append("IPChecker.external.").append(msg_key).toString());
			if (extra != null)
				message = (new StringBuilder()).append(message).append(": ").append(extra).toString();
			for (int i = 0; i < listeners.size(); i++)
				((ExternalIPCheckerServiceListener)listeners.elementAt(i)).checkFailed(this, message);

		}
		this_mon.exit();
		break MISSING_BLOCK_LABEL_134;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	protected void reportProgress(String msg_key)
	{
		this_mon.enter();
		reportProgress(msg_key, null);
		this_mon.exit();
		break MISSING_BLOCK_LABEL_33;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	protected void reportProgress(String msg_key, String extra)
	{
		this_mon.enter();
		if (!completed)
		{
			String message = MessageText.getString("IPChecker.external".concat(".").concat(msg_key));
			if (extra != null)
				message = message.concat(": ").concat(extra);
			for (int i = 0; i < listeners.size(); i++)
				((ExternalIPCheckerServiceListener)listeners.elementAt(i)).reportProgress(this, message);

		}
		this_mon.exit();
		break MISSING_BLOCK_LABEL_106;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	public void addListener(ExternalIPCheckerServiceListener l)
	{
		this_mon.enter();
		listeners.addElement(l);
		this_mon.exit();
		break MISSING_BLOCK_LABEL_35;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	public void removeListener(ExternalIPCheckerServiceListener l)
	{
		this_mon.enter();
		listeners.removeElement(l);
		this_mon.exit();
		break MISSING_BLOCK_LABEL_36;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}


}

⌨️ 快捷键说明

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