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

📄 urltransfer.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:   URLTransfer.java

package org.gudy.azureus2.ui.swt;

import java.io.*;
import java.util.*;
import org.eclipse.swt.dnd.ByteArrayTransfer;
import org.eclipse.swt.dnd.TransferData;
import org.gudy.azureus2.core3.util.Debug;
import org.gudy.azureus2.core3.util.UrlUtils;

public class URLTransfer extends ByteArrayTransfer
{
	public class URLType
	{

		public String linkURL;
		public String linkText;
		final URLTransfer this$0;

		public String toString()
		{
			return (new StringBuilder()).append(linkURL).append("\n").append(linkText).toString();
		}

		public URLType()
		{
			this$0 = URLTransfer.this;
			super();
		}
	}


	private boolean bCheckingString;
	private static boolean DEBUG = false;
	private static URLTransfer _instance = new URLTransfer();
	private static final String supportedTypes[] = {
		"CF_UNICODETEXT", "CF_TEXT", "OEM_TEXT"
	};
	private static final int supportedTypeIds[] = {
		13, 1, 17
	};

	public URLTransfer()
	{
		bCheckingString = false;
	}

	public static URLTransfer getInstance()
	{
		return _instance;
	}

	public void javaToNative(Object object, TransferData transferData)
	{
		if (DEBUG)
			System.out.println("javaToNative called");
		if (object == null || !(object instanceof URLType[]))
			return;
		if (isSupportedType(transferData))
		{
			URLType myTypes[] = (URLType[])(URLType[])object;
			try
			{
				ByteArrayOutputStream out = new ByteArrayOutputStream();
				DataOutputStream writeOut = new DataOutputStream(out);
				int i = 0;
				for (int length = myTypes.length; i < length; i++)
				{
					writeOut.writeBytes(myTypes[i].linkURL);
					writeOut.writeBytes("\n");
					writeOut.writeBytes(myTypes[i].linkText);
				}

				byte buffer[] = out.toByteArray();
				writeOut.close();
				super.javaToNative(buffer, transferData);
			}
			catch (IOException e) { }
		}
	}

	public Object nativeToJava(TransferData transferData)
	{
		if (DEBUG)
			System.out.println("nativeToJava called");
		byte buffer[];
		if (!isSupportedType(transferData))
			break MISSING_BLOCK_LABEL_48;
		buffer = (byte[])(byte[])super.nativeToJava(transferData);
		return bytebufferToJava(buffer);
		Exception e;
		e;
		Debug.out(e);
		return null;
	}

	public URLType bytebufferToJava(byte buffer[])
	{
		if (buffer == null)
		{
			if (DEBUG)
				System.out.println("buffer null");
			return null;
		}
		URLType myData = null;
		try
		{
			String data;
			if (buffer.length > 1)
			{
				if (DEBUG)
				{
					for (int i = 0; i < buffer.length; i++)
						if (buffer[i] >= 32)
							System.out.print((char)buffer[i]);
						else
							System.out.print("#");

					System.out.println();
				}
				boolean bFirst0 = buffer[0] == 0;
				boolean bSecond0 = buffer[1] == 0;
				if (bFirst0 && bSecond0)
					data = new String(buffer);
				else
				if (bFirst0)
					data = new String(buffer, "UTF-16BE");
				else
				if (bSecond0)
					data = new String(buffer, "UTF-16LE");
				else
				if (buffer[0] == -17 && buffer[1] == -69 && buffer.length > 3 && buffer[2] == -65)
					data = new String(buffer, 3, buffer.length - 3, "UTF-8");
				else
				if (buffer[0] == -1 || buffer[0] == -2)
					data = new String(buffer, "UTF-16");
				else
					data = new String(buffer);
			} else
			{
				byte text[] = new byte[buffer.length];
				int j = 0;
				for (int i = 0; i < buffer.length; i++)
					if (buffer[i] != 0)
						text[j++] = buffer[i];

				data = new String(text, 0, j);
			}
			int iPos = data.indexOf("\nURL=");
			if (iPos > 0)
			{
				int iEndPos = data.indexOf("\r", iPos);
				if (iEndPos < 0)
					iEndPos = data.length();
				myData = new URLType();
				myData.linkURL = data.substring(iPos + 5, iEndPos);
				myData.linkText = "";
			} else
			{
				String split[] = data.split("[\r\n]+", 2);
				myData = new URLType();
				myData.linkURL = split.length <= 0 ? "" : split[0];
				myData.linkText = split.length <= 1 ? "" : split[1];
			}
		}
		catch (Exception ex)
		{
			ex.printStackTrace();
		}
		return myData;
	}

	protected String[] getTypeNames()
	{
		return supportedTypes;
	}

	protected int[] getTypeIds()
	{
		return supportedTypeIds;
	}

	public boolean isSupportedType(TransferData transferData)
	{
		URLType url;
		if (bCheckingString)
			return true;
		if (transferData == null)
			return false;
		url = null;
		if (DEBUG)
			System.out.println((new StringBuilder()).append("Checking if type #").append(transferData.type).append(" is URL").toString());
		bCheckingString = true;
		byte buffer[] = (byte[])(byte[])super.nativeToJava(transferData);
		url = bytebufferToJava(buffer);
		bCheckingString = false;
		break MISSING_BLOCK_LABEL_110;
		Exception e;
		e;
		Debug.out(e);
		bCheckingString = false;
		break MISSING_BLOCK_LABEL_110;
		Exception exception;
		exception;
		bCheckingString = false;
		throw exception;
		if (url == null)
		{
			if (DEBUG)
				System.out.println((new StringBuilder()).append("no, Null URL for type #").append(transferData.type).toString());
			return false;
		}
		if (UrlUtils.isURL(url.linkURL, false))
		{
			if (DEBUG)
				System.out.println((new StringBuilder()).append("Yes, ").append(url.linkURL).append(" of type #").append(transferData.type).toString());
			return true;
		}
		if (DEBUG)
			System.out.println((new StringBuilder()).append("no, ").append(url.linkURL).append(" not URL for type #").append(transferData.type).toString());
		return false;
	}

	public static TransferData pickBestType(TransferData dataTypes[], TransferData def)
	{
		int i = 0;
_L5:
		int supportedTypeID;
		int j;
		if (i >= supportedTypeIds.length)
			break; /* Loop/switch isn't completed */
		supportedTypeID = supportedTypeIds[i];
		j = 0;
_L3:
		if (j >= dataTypes.length) goto _L2; else goto _L1
_L1:
		TransferData data = dataTypes[j];
		if (supportedTypeID == data.type)
			return data;
		continue; /* Loop/switch isn't completed */
		Throwable t;
		t;
		Debug.out("Picking Best Type", t);
		j++;
		  goto _L3
_L2:
		i++;
		if (true) goto _L5; else goto _L4
_L4:
		return def;
	}

	public static void main(String args[])
	{
		Map map = new LinkedHashMap();
		map.put("UTF-8", new byte[] {
			-17, -69, -65, 72, 105
		});
		map.put("UTF-32 BE BOM", new byte[] {
			0, 0, -2, -1, 72, 0, 0, 0, 105, 0, 
			0, 0
		});
		map.put("UTF-16 LE BOM", new byte[] {
			-1, -2, 72, 0, 105, 0
		});
		map.put("UTF-16 BE BOM", new byte[] {
			-2, -1, 0, 72, 0, 105
		});
		map.put("UTF-16 LE", new byte[] {
			72, 0, 105, 0
		});
		map.put("UTF-16 BE", new byte[] {
			0, 72, 0, 105
		});
		String data;
		for (Iterator iterator = map.keySet().iterator(); iterator.hasNext(); System.out.println(data))
		{
			String element = (String)iterator.next();
			System.out.println((new StringBuilder()).append(element).append(":").toString());
			byte buffer[] = (byte[])(byte[])map.get(element);
			boolean bFirst0 = buffer[0] == 0;
			boolean bSecond0 = buffer[1] == 0;
			data = "";
			try
			{
				if (bFirst0 && bSecond0)
				{
					data = new String(buffer);
					continue;
				}
				if (bFirst0)
				{
					data = new String(buffer, "UTF-16BE");
					continue;
				}
				if (bSecond0)
				{
					data = new String(buffer, "UTF-16LE");
					continue;
				}
				if (buffer[0] == -17 && buffer[1] == -69 && buffer.length > 3 && buffer[2] == -65)
				{
					data = new String(buffer, 3, buffer.length - 3, "UTF-8");
					continue;
				}
				if (buffer[0] == -1 || buffer[0] == -2)
					data = new String(buffer, "UTF-16");
				else
					data = new String(buffer);
			}
			catch (UnsupportedEncodingException e)
			{
				e.printStackTrace();
			}
		}

	}

}

⌨️ 快捷键说明

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