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

📄 utilitiesimpl.java

📁 java 文件下载器。可自定义
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
// 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:   UtilitiesImpl.java

package org.gudy.azureus2.pluginsimpl.local.utils;

import com.aelitis.azureus.core.AzureusCore;
import com.aelitis.azureus.core.versioncheck.VersionCheckClient;
import java.io.*;
import java.net.InetAddress;
import java.net.URL;
import java.nio.ByteBuffer;
import java.util.*;
import org.gudy.azureus2.core3.ipchecker.extipchecker.*;
import org.gudy.azureus2.core3.logging.*;
import org.gudy.azureus2.core3.util.*;
import org.gudy.azureus2.platform.PlatformManager;
import org.gudy.azureus2.platform.PlatformManagerFactory;
import org.gudy.azureus2.plugins.PluginException;
import org.gudy.azureus2.plugins.PluginInterface;
import org.gudy.azureus2.plugins.utils.*;
import org.gudy.azureus2.plugins.utils.resourcedownloader.*;
import org.gudy.azureus2.plugins.utils.resourceuploader.ResourceUploaderFactory;
import org.gudy.azureus2.plugins.utils.search.SearchException;
import org.gudy.azureus2.plugins.utils.search.SearchProvider;
import org.gudy.azureus2.plugins.utils.security.SESecurityManager;
import org.gudy.azureus2.plugins.utils.xml.rss.RSSFeed;
import org.gudy.azureus2.plugins.utils.xml.simpleparser.SimpleXMLParserDocumentException;
import org.gudy.azureus2.plugins.utils.xml.simpleparser.SimpleXMLParserDocumentFactory;
import org.gudy.azureus2.pluginsimpl.local.PluginInitializer;
import org.gudy.azureus2.pluginsimpl.local.utils.resourcedownloader.ResourceDownloaderFactoryImpl;
import org.gudy.azureus2.pluginsimpl.local.utils.resourceuploader.ResourceUploaderFactoryImpl;
import org.gudy.azureus2.pluginsimpl.local.utils.security.SESecurityManagerImpl;
import org.gudy.azureus2.pluginsimpl.local.utils.xml.rss.RSSFeedImpl;
import org.gudy.azureus2.pluginsimpl.local.utils.xml.simpleparser.SimpleXMLParserDocumentFactoryImpl;

// Referenced classes of package org.gudy.azureus2.pluginsimpl.local.utils:
//			FormattersImpl, LocaleUtilitiesImpl, MonitorImpl, PooledByteBufferImpl, 
//			SemaphoreImpl, UTTimerImpl

public class UtilitiesImpl
	implements Utilities
{
	static class DelayedTaskImpl
		implements DelayedTask
	{

		private String name;
		private Runnable target;
		private long create_time;
		private long run_time;

		public void setTask(Runnable _target)
		{
			target = _target;
		}

		public void queue()
		{
			if (target == null)
			{
				throw new RuntimeException("Target must be set before queueing");
			} else
			{
				UtilitiesImpl.queueTask(this);
				return;
			}
		}

		protected void run()
		{
			try
			{
				run_time = SystemTime.getCurrentTime();
				target.run();
				long now = SystemTime.getCurrentTime();
				if (Logger.isEnabled())
					Logger.log(new LogEvent(LogIDs.PLUGIN, 0, (new StringBuilder()).append("Delayed task '").append(getName()).append("': queue_time=").append(run_time - create_time).append(", exec_time=").append(now - run_time).toString()));
			}
			catch (Throwable e)
			{
				Debug.out((new StringBuilder()).append("Initialisation task ").append(getName()).append(" failed to complete").toString(), e);
			}
		}

		protected String getName()
		{
			return (new StringBuilder()).append(name).append(" (").append(target.getClass()).append(")").toString();
		}

		private DelayedTaskImpl(String _name)
		{
			create_time = SystemTime.getCurrentTime();
			name = _name;
		}

	}

	public static interface runnableWithException
	{

		public abstract void run()
			throws Exception;
	}

	public static interface runnableWithReturn
	{

		public abstract Object run();
	}

	public static interface runnableWithReturnAndException
	{

		public abstract Object run()
			throws Exception;
	}

	public static interface searchManager
	{

		public abstract void addProvider(PluginInterface plugininterface, SearchProvider searchprovider);
	}


	private static InetAddress last_public_ip_address;
	private static long last_public_ip_address_time;
	private AzureusCore core;
	private PluginInterface pi;
	private static ThreadLocal tls = new ThreadLocal() {

		public PluginInterface initialValue()
		{
			return null;
		}

		public volatile Object initialValue()
		{
			return initialValue();
		}

	};
	private static List search_managers = new ArrayList();
	private static List search_providers = new ArrayList();
	private static List delayed_tasks = new ArrayList();
	private static AESemaphore delayed_tasks_sem = new AESemaphore("Utilities:delayedTask");
	private static AEThread2 delayed_task_thread;

	public UtilitiesImpl(AzureusCore _core, PluginInterface _pi)
	{
		core = _core;
		pi = _pi;
	}

	public String getAzureusUserDir()
	{
		String res = SystemProperties.getUserPath();
		if (res.endsWith(File.separator))
			res = res.substring(0, res.length() - 1);
		return res;
	}

	public String getAzureusProgramDir()
	{
		String res = SystemProperties.getApplicationPath();
		if (res.endsWith(File.separator))
			res = res.substring(0, res.length() - 1);
		return res;
	}

	public boolean isWindows()
	{
		return Constants.isWindows;
	}

	public boolean isLinux()
	{
		return Constants.isLinux;
	}

	public boolean isUnix()
	{
		return Constants.isUnix;
	}

	public boolean isFreeBSD()
	{
		return Constants.isFreeBSD;
	}

	public boolean isSolaris()
	{
		return Constants.isSolaris;
	}

	public boolean isOSX()
	{
		return Constants.isOSX;
	}

	public boolean isCVSVersion()
	{
		return Constants.isCVSVersion();
	}

	public InputStream getImageAsStream(String image_name)
	{
		return org/gudy/azureus2/pluginsimpl/local/utils/UtilitiesImpl.getClassLoader().getResourceAsStream((new StringBuilder()).append("org/gudy/azureus2/ui/icons/").append(image_name).toString());
	}

	public Semaphore getSemaphore()
	{
		return new SemaphoreImpl(pi);
	}

	public Monitor getMonitor()
	{
		return new MonitorImpl(pi);
	}

	public ByteBuffer allocateDirectByteBuffer(int size)
	{
		return DirectByteBufferPool.getBuffer((byte)1, size).getBuffer((byte)1);
	}

	public void freeDirectByteBuffer(ByteBuffer bytebuffer)
	{
	}

	public PooledByteBuffer allocatePooledByteBuffer(int length)
	{
		return new PooledByteBufferImpl(length);
	}

	public PooledByteBuffer allocatePooledByteBuffer(byte data[])
	{
		return new PooledByteBufferImpl(data);
	}

	public PooledByteBuffer allocatePooledByteBuffer(Map map)
		throws IOException
	{
		return new PooledByteBufferImpl(BEncoder.encode(map));
	}

	public Formatters getFormatters()
	{
		return new FormattersImpl();
	}

	public LocaleUtilities getLocaleUtilities()
	{
		return new LocaleUtilitiesImpl(pi);
	}

	public UTTimer createTimer(String name)
	{
		return new UTTimerImpl(pi, name, false);
	}

	public UTTimer createTimer(String name, boolean lightweight)
	{
		return new UTTimerImpl(pi, name, lightweight);
	}

	public UTTimer createTimer(String name, int priority)
	{
		return new UTTimerImpl(pi, name, priority);
	}

	public void createThread(String name, Runnable target)
	{
		AEThread2 t = new AEThread2(true, target) {

			final Runnable val$target;
			final UtilitiesImpl this$0;

			public void run()
			{
				UtilitiesImpl.callWithPluginThreadContext(pi, target);
			}

			
			{
				this$0 = UtilitiesImpl.this;
				target = runnable;
				super(x0, x1);
			}
		};
		t.start();
	}

	public void createProcess(String command_line)
		throws PluginException
	{
		try
		{
			PlatformManager pm = PlatformManagerFactory.getPlatformManager();
			pm.createProcess(command_line, false);
		}
		catch (Throwable e)
		{
			Debug.printStackTrace(e);
			try
			{
				Runtime.getRuntime().exec(command_line);
			}
			catch (Throwable f)
			{
				throw new PluginException("Failed to create process", f);
			}
		}
	}

	public ResourceDownloaderFactory getResourceDownloaderFactory()
	{
		return ResourceDownloaderFactoryImpl.getSingleton();
	}

	public ResourceUploaderFactory getResourceUploaderFactory()
	{
		return ResourceUploaderFactoryImpl.getSingleton();
	}

	public SESecurityManager getSecurityManager()
	{
		return new SESecurityManagerImpl(core);
	}

	public SimpleXMLParserDocumentFactory getSimpleXMLParserDocumentFactory()
	{
		return new SimpleXMLParserDocumentFactoryImpl();
	}

	public RSSFeed getRSSFeed(InputStream is)
		throws SimpleXMLParserDocumentException
	{
		RSSFeedImpl rssfeedimpl = new RSSFeedImpl(this, is);
		try
		{
			is.close();
		}
		catch (Throwable e) { }
		return rssfeedimpl;
		Exception exception;
		exception;
		try
		{
			is.close();
		}
		catch (Throwable e) { }
		throw exception;
	}

	public RSSFeed getRSSFeed(URL feed_location)
		throws ResourceDownloaderException, SimpleXMLParserDocumentException
	{
		return getRSSFeed(getResourceDownloaderFactory().create(feed_location));
	}

	public RSSFeed getRSSFeed(ResourceDownloader feed_location)
		throws ResourceDownloaderException, SimpleXMLParserDocumentException
	{
		return new RSSFeedImpl(this, feed_location);
	}

	public InetAddress getPublicAddress(boolean v6)
	{
		String vc_ip;
		if (!v6)
			break MISSING_BLOCK_LABEL_36;
		vc_ip = VersionCheckClient.getSingleton().getExternalIpAddress(false, true);
		if (vc_ip == null || vc_ip.length() <= 0)
			break MISSING_BLOCK_LABEL_34;
		return InetAddress.getByName(vc_ip);
		Throwable e;
		e;
		Debug.printStackTrace(e);
		return null;
		return getPublicAddress();
	}

	public InetAddress getPublicAddress()
	{
		long now;
		InetAddress res;
		now = SystemTime.getCurrentTime();
		if (now < last_public_ip_address_time)
			last_public_ip_address_time = now;
		else
		if (last_public_ip_address != null && now - last_public_ip_address_time < 0xdbba0L)
			return last_public_ip_address;
		res = null;
		String vc_ip = VersionCheckClient.getSingleton().getExternalIpAddress(false, false);
		if (vc_ip == null || vc_ip.length() <= 0) goto _L2; else goto _L1
_L1:
		res = InetAddress.getByName(vc_ip);
		  goto _L3
_L2:
		ExternalIPCheckerService services[];
		final String ip[];
		int i;
		ExternalIPChecker checker = ExternalIPCheckerFactory.create();
		services = checker.getServices();
		ip = (new String[] {
			null
		});
		i = 0;
_L6:
		ExternalIPCheckerService service;
		if (i >= services.length || ip[0] != null)
			break; /* Loop/switch isn't completed */
		service = services[i];
		if (!service.supportsCheck()) goto _L5; else goto _L4
_L4:
		final AESemaphore sem;
		ExternalIPCheckerServiceListener listener;
		sem = new AESemaphore("Utilities:getExtIP");
		listener = new ExternalIPCheckerServiceListener() {

			final String val$ip[];
			final AESemaphore val$sem;
			final UtilitiesImpl this$0;

			public void checkComplete(ExternalIPCheckerService _service, String _ip)
			{
				ip[0] = _ip;
				sem.release();
			}

			public void checkFailed(ExternalIPCheckerService _service, String _reason)
			{
				sem.release();
			}

			public void reportProgress(ExternalIPCheckerService externalipcheckerservice, String s)
			{
			}

			
			{
				this$0 = UtilitiesImpl.this;
				ip = as;
				sem = aesemaphore;
				super();
			}
		};
		services[i].addListener(listener);
		services[i].initiateCheck(60000L);
		sem.reserve(60000L);
		services[i].removeListener(listener);
		  goto _L5

⌨️ 快捷键说明

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