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

📄 totorrentdeserialiseimpl.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:   TOTorrentDeserialiseImpl.java

package org.gudy.azureus2.core3.torrent.impl;

import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import org.gudy.azureus2.core3.html.HTMLUtils;
import org.gudy.azureus2.core3.torrent.*;
import org.gudy.azureus2.core3.util.*;

// Referenced classes of package org.gudy.azureus2.core3.torrent.impl:
//			TOTorrentImpl, TOTorrentFileImpl

public class TOTorrentDeserialiseImpl extends TOTorrentImpl
{

	public TOTorrentDeserialiseImpl(File file)
		throws TOTorrentException
	{
		FileInputStream fis;
		Exception exception;
		if (!file.exists())
			throw new TOTorrentException((new StringBuilder()).append("Torrent file '").append(file.toString()).append("' does not exist").toString(), 1);
		if (!file.isFile())
			throw new TOTorrentException((new StringBuilder()).append("Torrent must be a file ('").append(file.toString()).append("')").toString(), 1);
		if (file.length() == 0L)
			throw new TOTorrentException((new StringBuilder()).append("Torrent is zero length ('").append(file.toString()).append("')").toString(), 2);
		fis = null;
		try
		{
			fis = new FileInputStream(file);
			construct(fis);
		}
		catch (Throwable e)
		{
			throw new TOTorrentException((new StringBuilder()).append("Error reading torrent file '").append(file.toString()).append(" - ").append(Debug.getNestedExceptionMessage(e)).toString(), 4);
		}
		finally
		{
			if (fis == null) goto _L0; else goto _L0
		}
		if (fis != null)
			try
			{
				fis.close();
			}
			catch (IOException e)
			{
				Debug.printStackTrace(e);
			}
		break MISSING_BLOCK_LABEL_237;
		try
		{
			fis.close();
		}
		catch (IOException e)
		{
			Debug.printStackTrace(e);
		}
		throw exception;
	}

	public TOTorrentDeserialiseImpl(InputStream is)
		throws TOTorrentException
	{
		construct(is);
	}

	public TOTorrentDeserialiseImpl(byte bytes[])
		throws TOTorrentException
	{
		construct(bytes);
	}

	public TOTorrentDeserialiseImpl(Map map)
		throws TOTorrentException
	{
		construct(map);
	}

	protected void construct(InputStream is)
		throws TOTorrentException
	{
		ByteArrayOutputStream metaInfo = new ByteArrayOutputStream();
		try
		{
			byte buf[] = new byte[32768];
			int iFirstByte = is.read();
			int nbRead;
			if (iFirstByte != 100 && iFirstByte != 101 && iFirstByte != 105 && (iFirstByte < 48 || iFirstByte > 57))
			{
				try
				{
					metaInfo.write(iFirstByte);
					for (; (nbRead = is.read(buf)) > 0 && metaInfo.size() < 32000; metaInfo.write(buf, 0, nbRead));
					String char_data = new String(metaInfo.toByteArray());
					if (char_data.toLowerCase().indexOf("html") != -1)
					{
						char_data = HTMLUtils.convertHTMLToText2(char_data);
						char_data = HTMLUtils.splitWithLineLength(char_data, 80);
						if (char_data.length() > 400)
							char_data = (new StringBuilder()).append(char_data.substring(0, 400)).append("...").toString();
						throw new TOTorrentException((new StringBuilder()).append("Contents maybe HTML:\n").append(char_data).toString(), 6);
					}
				}
				catch (Throwable e)
				{
					if (e instanceof TOTorrentException)
						throw (TOTorrentException)e;
				}
				throw new TOTorrentException("Contents invalid - bad header", 6);
			}
			metaInfo.write(iFirstByte);
			while ((e = is.read(buf)) > 0) 
				metaInfo.write(buf, 0, e);
		}
		catch (Throwable e)
		{
			throw new TOTorrentException((new StringBuilder()).append("Error reading torrent: ").append(Debug.getNestedExceptionMessage(e)).toString(), 4);
		}
		construct(metaInfo.toByteArray());
	}

	protected void construct(byte bytes[])
		throws TOTorrentException
	{
		try
		{
			Map meta_data = BDecoder.decode(bytes);
			construct(meta_data);
		}
		catch (IOException e)
		{
			throw new TOTorrentException((new StringBuilder()).append("Error reading torrent: ").append(Debug.getNestedExceptionMessage(e)).toString(), 6, e);
		}
	}

	protected void construct(Map meta_data)
		throws TOTorrentException
	{
		try
		{
			String announce_url = null;
			boolean got_announce = false;
			boolean got_announce_list = false;
			boolean bad_announce = false;
			Iterator root_it = meta_data.keySet().iterator();
			do
			{
				if (!root_it.hasNext())
					break;
				String key = (String)root_it.next();
				if (key.equalsIgnoreCase("announce"))
				{
					got_announce = true;
					announce_url = readStringFromMetaData(meta_data, "announce");
					if (announce_url == null)
					{
						bad_announce = true;
					} else
					{
						announce_url = announce_url.replaceAll(" ", "");
						try
						{
							setAnnounceURL(new URL(announce_url));
						}
						catch (MalformedURLException e)
						{
							if (announce_url.indexOf("://") == -1)
								announce_url = (new StringBuilder()).append("http:/").append(announce_url.startsWith("/") ? "" : "/").append(announce_url).toString();
							try
							{
								setAnnounceURL(new URL(announce_url));
							}
							catch (MalformedURLException f)
							{
								bad_announce = true;
							}
						}
					}
				} else
				if (key.equalsIgnoreCase("announce-list"))
				{
					got_announce_list = true;
					List announce_list = null;
					Object ann_list = meta_data.get("announce-list");
					if (ann_list instanceof List)
						announce_list = (List)ann_list;
					if (announce_list != null && announce_list.size() > 0)
					{
						announce_url = readStringFromMetaData(meta_data, "announce");
						if (announce_url != null)
							announce_url = announce_url.replaceAll(" ", "");
						boolean announce_url_found = false;
						for (int i = 0; i < announce_list.size(); i++)
						{
							Object temp = announce_list.get(i);
							if (temp instanceof List)
							{
								List set = (List)temp;
								Vector urls = new Vector();
								for (int j = 0; j < set.size(); j++)
								{
									String url_str = readStringFromMetaData((byte[])(byte[])set.get(j));
									url_str = url_str.replaceAll(" ", "");
									try
									{
										urls.add(new URL(StringInterner.intern(url_str)));
										if (url_str.equalsIgnoreCase(announce_url))
											announce_url_found = true;
										continue;
									}
									catch (MalformedURLException e) { }
									if (url_str.indexOf("://") == -1)
										url_str = (new StringBuilder()).append("http:/").append(url_str.startsWith("/") ? "" : "/").append(url_str).toString();
									try
									{
										urls.add(new URL(StringInterner.intern(url_str)));
										if (url_str.equalsIgnoreCase(announce_url))
											announce_url_found = true;
									}
									catch (MalformedURLException f)
									{
										Debug.printStackTrace(f);
									}
								}

								if (urls.size() > 0)
								{
									URL url_array[] = new URL[urls.size()];
									urls.copyInto(url_array);
									addTorrentAnnounceURLSet(url_array);
								}
							} else
							{
								Debug.out((new StringBuilder()).append("Torrent has invalid url-list entry (").append(temp).append(") - ignoring").toString());
							}

⌨️ 快捷键说明

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