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

📄 resourceuploaderurlimpl.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:   ResourceUploaderURLImpl.java

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

import java.io.*;
import java.net.*;
import java.util.*;
import javax.net.ssl.*;
import org.gudy.azureus2.core3.security.SEPasswordListener;
import org.gudy.azureus2.core3.security.SESecurityManager;
import org.gudy.azureus2.core3.util.AddressUtils;
import org.gudy.azureus2.core3.util.Debug;
import org.gudy.azureus2.plugins.utils.resourcedownloader.ResourceDownloaderException;
import org.gudy.azureus2.plugins.utils.resourceuploader.ResourceUploader;
import org.gudy.azureus2.plugins.utils.resourceuploader.ResourceUploaderException;

public class ResourceUploaderURLImpl
	implements ResourceUploader, SEPasswordListener
{

	private URL target;
	private InputStream data;
	private String user_name;
	private String password;
	private Map properties;

	protected ResourceUploaderURLImpl(URL _target, InputStream _data, String _user_name, String _password)
	{
		properties = new HashMap();
		target = _target;
		data = _data;
		user_name = _user_name;
		password = _password;
	}

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

	public Object getProperty(String name)
		throws ResourceDownloaderException
	{
		return properties.get(name);
	}

	public InputStream upload()
		throws ResourceUploaderException
	{
		URL url;
		SSLException e;
		url = new URL(target.toString().replaceAll(" ", "%20"));
		String protocol = url.getProtocol().toLowerCase();
		if (url.getPort() == -1)
		{
			int target_port;
			if (protocol.equals("http"))
				target_port = 80;
			else
				target_port = 443;
			try
			{
				String str = target.toString().replaceAll(" ", "%20");
				int pos = str.indexOf("://");
				pos = str.indexOf("/", pos + 4);
				if (pos == -1)
					url = new URL((new StringBuilder()).append(str).append(":").append(target_port).append("/").toString());
				else
					url = new URL((new StringBuilder()).append(str.substring(0, pos)).append(":").append(target_port).append(str.substring(pos)).toString());
			}
			// Misplaced declaration of an exception variable
			catch (SSLException e)
			{
				Debug.printStackTrace(e);
			}
		}
		url = AddressUtils.adjustURL(url);
		int i;
		if (user_name != null)
			SESecurityManager.setPasswordHandler(url, this);
		i = 0;
_L1:
		if (i >= 2)
			break MISSING_BLOCK_LABEL_511;
		InputStream inputstream;
		HttpURLConnection con;
		if (url.getProtocol().equalsIgnoreCase("https"))
		{
			HttpsURLConnection ssl_con = (HttpsURLConnection)url.openConnection();
			ssl_con.setHostnameVerifier(new HostnameVerifier() {

				final ResourceUploaderURLImpl this$0;

				public boolean verify(String host, SSLSession session)
				{
					return true;
				}

			
			{
				this$0 = ResourceUploaderURLImpl.this;
				super();
			}
			});
			con = ssl_con;
		} else
		{
			con = (HttpURLConnection)url.openConnection();
		}
		con.setRequestMethod("POST");
		con.setRequestProperty("User-Agent", "Azureus 4.2.0.0");
		setRequestProperties(con, false);
		con.setDoOutput(true);
		con.setDoInput(true);
		OutputStream os = con.getOutputStream();
		byte buffer[] = new byte[0x10000];
		do
		{
			int len = data.read(buffer);
			if (len <= 0)
				break;
			os.write(buffer, 0, len);
		} while (true);
		con.connect();
		int response = con.getResponseCode();
		if (response != 202 && response != 200)
			throw new ResourceUploaderException((new StringBuilder()).append("Error on connect for '").append(url.toString()).append("': ").append(Integer.toString(response)).append(" ").append(con.getResponseMessage()).toString());
		InputStream is = con.getInputStream();
		getRequestProperties(con);
		inputstream = is;
		if (user_name != null)
			SESecurityManager.setPasswordHandler(url, null);
		try
		{
			data.close();
		}
		catch (Throwable e)
		{
			e.printStackTrace();
		}
		return inputstream;
		con;
		if (i != 0 || SESecurityManager.installServerCertificates(url) == null)
			throw con;
		i++;
		  goto _L1
		throw new ResourceUploaderException("Should never get here");
		Exception exception;
		exception;
		if (user_name != null)
			SESecurityManager.setPasswordHandler(url, null);
		throw exception;
		MalformedURLException e;
		e;
		throw new ResourceUploaderException((new StringBuilder()).append("Exception while parsing URL '").append(target).append("':").append(e.getMessage()).toString(), e);
		e;
		throw new ResourceUploaderException((new StringBuilder()).append("Exception while initializing download of '").append(target).append("': Unknown Host '").append(e.getMessage()).append("'").toString(), e);
		e;
		throw new ResourceUploaderException((new StringBuilder()).append("I/O Exception while downloading '").append(target).append("':").append(e.toString()).toString(), e);
		e;
		ResourceUploaderException rde;
		if (e instanceof ResourceUploaderException)
			rde = (ResourceUploaderException)e;
		else
			rde = new ResourceUploaderException("Unexpected error", e);
		throw rde;
		Exception exception1;
		exception1;
		try
		{
			data.close();
		}
		catch (Throwable e)
		{
			e.printStackTrace();
		}
		throw exception1;
	}

	protected void setRequestProperties(HttpURLConnection con, boolean use_compression)
	{
		Iterator it = properties.entrySet().iterator();
		do
		{
			if (!it.hasNext())
				break;
			java.util.Map.Entry entry = (java.util.Map.Entry)it.next();
			String key = (String)entry.getKey();
			Object value = entry.getValue();
			if (key.startsWith("URL_") && (value instanceof String))
			{
				key = key.substring(4);
				if (!key.equalsIgnoreCase("Accept-Encoding") || use_compression)
					con.setRequestProperty(key, (String)value);
			}
		} while (true);
	}

	protected void getRequestProperties(HttpURLConnection con)
	{
		try
		{
			setProperty("ContentType", con.getContentType());
			Map headers = con.getHeaderFields();
			Iterator it = headers.entrySet().iterator();
			do
			{
				if (!it.hasNext())
					break;
				java.util.Map.Entry entry = (java.util.Map.Entry)it.next();
				String key = (String)entry.getKey();
				Object val = entry.getValue();
				if (key != null)
					setProperty((new StringBuilder()).append("URL_").append(key).toString(), val);
			} while (true);
		}
		catch (Throwable e)
		{
			Debug.printStackTrace(e);
		}
	}

	public PasswordAuthentication getAuthentication(String realm, URL tracker)
	{
		if (user_name == null || password == null)
		{
			String user_info = tracker.getUserInfo();
			if (user_info == null)
				return null;
			String user_bit = user_info;
			String pw_bit = "";
			int pos = user_info.indexOf(':');
			if (pos != -1)
			{
				user_bit = user_info.substring(0, pos);
				pw_bit = user_info.substring(pos + 1);
			}
			return new PasswordAuthentication(user_bit, pw_bit.toCharArray());
		} else
		{
			return new PasswordAuthentication(user_name, password.toCharArray());
		}
	}

	public void setAuthenticationOutcome(String s, URL url, boolean flag)
	{
	}

	public void clearPasswords()
	{
	}
}

⌨️ 快捷键说明

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