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

📄 resourcedownloadertimeoutimpl.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:   ResourceDownloaderTimeoutImpl.java

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

import java.io.InputStream;
import org.gudy.azureus2.core3.util.*;
import org.gudy.azureus2.plugins.utils.resourcedownloader.*;

// Referenced classes of package org.gudy.azureus2.pluginsimpl.local.utils.resourcedownloader:
//			ResourceDownloaderBaseImpl

public class ResourceDownloaderTimeoutImpl extends ResourceDownloaderBaseImpl
	implements ResourceDownloaderListener
{

	protected ResourceDownloaderBaseImpl delegate;
	protected int timeout_millis;
	protected boolean cancelled;
	protected ResourceDownloaderBaseImpl current_downloader;
	protected Object result;
	protected AESemaphore done_sem;
	protected long size;

	public ResourceDownloaderTimeoutImpl(ResourceDownloaderBaseImpl _parent, ResourceDownloader _delegate, int _timeout_millis)
	{
		super(_parent);
		done_sem = new AESemaphore("RDTimeout");
		size = -2L;
		delegate = (ResourceDownloaderBaseImpl)_delegate;
		delegate.setParent(this);
		timeout_millis = _timeout_millis;
	}

	public String getName()
	{
		return (new StringBuilder()).append(delegate.getName()).append(": timeout=").append(timeout_millis).toString();
	}

	public long getSize()
		throws ResourceDownloaderException
	{
		if (size != -2L)
			return size;
		ResourceDownloaderTimeoutImpl x = new ResourceDownloaderTimeoutImpl(getParent(), delegate.getClone(this), timeout_millis);
		addReportListener(x);
		size = x.getSizeSupport();
		setProperties(x);
		if (size == -2L)
			size = -1L;
		setSize(size);
		break MISSING_BLOCK_LABEL_116;
		Exception exception;
		exception;
		if (size == -2L)
			size = -1L;
		setSize(size);
		throw exception;
		return size;
	}

	protected void setSize(long l)
	{
		size = l;
		if (size >= 0L)
			delegate.setSize(size);
	}

	public void setProperty(String name, Object value)
		throws ResourceDownloaderException
	{
		setPropertySupport(name, value);
		delegate.setProperty(name, value);
	}

	public ResourceDownloaderBaseImpl getClone(ResourceDownloaderBaseImpl parent)
	{
		ResourceDownloaderTimeoutImpl c = new ResourceDownloaderTimeoutImpl(getParent(), delegate.getClone(parent), timeout_millis);
		c.setSize(size);
		c.setProperties(this);
		return c;
	}

	public InputStream download()
		throws ResourceDownloaderException
	{
		asyncDownload();
		done_sem.reserve();
		if (result instanceof InputStream)
			return (InputStream)result;
		else
			throw (ResourceDownloaderException)result;
	}

	public void asyncDownload()
	{
		this_mon.enter();
		if (!cancelled)
		{
			current_downloader = delegate.getClone(this);
			informActivity((new StringBuilder()).append(getLogIndent()).append("Downloading: ").append(getName()).toString());
			current_downloader.addListener(this);
			current_downloader.asyncDownload();
			Thread t = new AEThread("ResourceDownloaderTimeout") {

				final ResourceDownloaderTimeoutImpl this$0;

				public void runSupport()
				{
					try
					{
						Thread.sleep(timeout_millis);
						cancel(new ResourceDownloaderException("Download timeout"));
					}
					catch (Throwable e)
					{
						Debug.printStackTrace(e);
					}
				}

			
			{
				this$0 = ResourceDownloaderTimeoutImpl.this;
				super(x0);
			}
			};
			t.setDaemon(true);
			t.start();
		}
		this_mon.exit();
		break MISSING_BLOCK_LABEL_114;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	protected long getSizeSupport()
		throws ResourceDownloaderException
	{
		asyncGetSize();
		done_sem.reserve();
		if (result instanceof Long)
			return ((Long)result).longValue();
		else
			throw (ResourceDownloaderException)result;
	}

	public void asyncGetSize()
	{
		this_mon.enter();
		if (!cancelled)
		{
			current_downloader = delegate.getClone(this);
			Thread size_thread = new AEThread("ResourceDownloader:size getter") {

				final ResourceDownloaderTimeoutImpl this$0;

				public void runSupport()
				{
					try
					{
						long res = current_downloader.getSize();
						result = new Long(res);
						setProperties(current_downloader);
						done_sem.release();
					}
					catch (ResourceDownloaderException e)
					{
						failed(current_downloader, e);
					}
				}

			
			{
				this$0 = ResourceDownloaderTimeoutImpl.this;
				super(x0);
			}
			};
			size_thread.setDaemon(true);
			size_thread.start();
			Thread t = new AEThread("ResourceDownloaderTimeout") {

				final ResourceDownloaderTimeoutImpl this$0;

				public void runSupport()
				{
					try
					{
						Thread.sleep(timeout_millis);
						cancel(new ResourceDownloaderException("getSize timeout"));
					}
					catch (Throwable e)
					{
						Debug.printStackTrace(e);
					}
				}

			
			{
				this$0 = ResourceDownloaderTimeoutImpl.this;
				super(x0);
			}
			};
			t.setDaemon(true);
			t.start();
		}
		this_mon.exit();
		break MISSING_BLOCK_LABEL_86;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	public void cancel()
	{
		cancel(((ResourceDownloaderException) (new ResourceDownloaderCancelledException())));
	}

	protected void cancel(ResourceDownloaderException reason)
	{
		setCancelled();
		this_mon.enter();
		result = reason;
		cancelled = true;
		informFailed((ResourceDownloaderException)result);
		if (current_downloader != null)
			current_downloader.cancel();
		this_mon.exit();
		break MISSING_BLOCK_LABEL_66;
		Exception exception;
		exception;
		this_mon.exit();
		throw exception;
	}

	public boolean completed(ResourceDownloader downloader, InputStream data)
	{
		if (informComplete(data))
		{
			result = data;
			done_sem.release();
			return true;
		} else
		{
			return false;
		}
	}

	public void failed(ResourceDownloader downloader, ResourceDownloaderException e)
	{
		result = e;
		done_sem.release();
		informFailed(e);
	}
}

⌨️ 快捷键说明

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