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

📄 totorrentimpl.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:   TOTorrentImpl.java

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

import com.aelitis.azureus.core.AzureusCore;
import com.aelitis.azureus.core.AzureusCoreFactory;
import java.io.*;
import java.net.URL;
import java.util.*;
import org.gudy.azureus2.core3.global.GlobalManager;
import org.gudy.azureus2.core3.logging.LogRelation;
import org.gudy.azureus2.core3.torrent.*;
import org.gudy.azureus2.core3.util.*;

// Referenced classes of package org.gudy.azureus2.core3.torrent.impl:
//			TOTorrentAnnounceURLGroupImpl, TOTorrentAnnounceURLSetImpl, TOTorrentFileImpl, TOTorrentXMLSerialiser

public class TOTorrentImpl extends LogRelation
	implements TOTorrent
{

	protected static final String TK_ANNOUNCE = "announce";
	protected static final String TK_ANNOUNCE_LIST = "announce-list";
	protected static final String TK_COMMENT = "comment";
	protected static final String TK_CREATION_DATE = "creation date";
	protected static final String TK_CREATED_BY = "created by";
	protected static final String TK_INFO = "info";
	protected static final String TK_NAME = "name";
	protected static final String TK_LENGTH = "length";
	protected static final String TK_PATH = "path";
	protected static final String TK_FILES = "files";
	protected static final String TK_PIECE_LENGTH = "piece length";
	protected static final String TK_PIECES = "pieces";
	protected static final String TK_PRIVATE = "private";
	protected static final String TK_NAME_UTF8 = "name.utf-8";
	protected static final String TK_PATH_UTF8 = "path.utf-8";
	protected static final String TK_COMMENT_UTF8 = "comment.utf-8";
	protected static final String TK_WEBSEED_BT = "httpseeds";
	protected static final String TK_WEBSEED_GR = "url-list";
	protected static final String TK_HASH_OVERRIDE = "hash-override";
	protected static final List TK_ADDITIONAL_OK_ATTRS = Arrays.asList(new String[] {
		"comment.utf-8", "azureus_properties", "httpseeds", "url-list"
	});
	private byte torrent_name[];
	private byte torrent_name_utf8[];
	private byte comment[];
	private URL announce_url;
	private TOTorrentAnnounceURLGroupImpl announce_group;
	private long piece_length;
	private byte pieces[][];
	private int number_of_pieces;
	private byte torrent_hash_override[];
	private byte torrent_hash[];
	private HashWrapper torrent_hash_wrapper;
	private boolean simple_torrent;
	private TOTorrentFileImpl files[];
	private long creation_date;
	private byte created_by[];
	private Map additional_properties;
	private Map additional_info_properties;
	private boolean created;
	private boolean serialising;
	protected AEMonitor this_mon;

	protected TOTorrentImpl()
	{
		announce_group = new TOTorrentAnnounceURLGroupImpl(this);
		additional_properties = new LightHashMap(4);
		additional_info_properties = new LightHashMap(4);
		this_mon = new AEMonitor("TOTorrent");
	}

	protected TOTorrentImpl(String _torrent_name, URL _announce_url, boolean _simple_torrent)
		throws TOTorrentException
	{
		announce_group = new TOTorrentAnnounceURLGroupImpl(this);
		additional_properties = new LightHashMap(4);
		additional_info_properties = new LightHashMap(4);
		this_mon = new AEMonitor("TOTorrent");
		created = true;
		try
		{
			torrent_name = _torrent_name.getBytes("UTF8");
			torrent_name_utf8 = torrent_name;
			setAnnounceURL(_announce_url);
			simple_torrent = _simple_torrent;
		}
		catch (UnsupportedEncodingException e)
		{
			throw new TOTorrentException((new StringBuilder()).append("Unsupported encoding for '").append(_torrent_name).append("'").toString(), 7);
		}
	}

	public void serialiseToBEncodedFile(File output_file)
		throws TOTorrentException
	{
		BufferedOutputStream bos;
		Exception exception;
		if (created)
			TorrentUtils.addCreatedTorrent(this);
		byte res[] = serialiseToByteArray();
		bos = null;
		try
		{
			File parent = output_file.getParentFile();
			if (parent == null)
				throw new TOTorrentException((new StringBuilder()).append("Path '").append(output_file).append("' is invalid").toString(), 5);
			if (!parent.isDirectory())
			{
				boolean dir_created = FileUtil.mkdirs(parent);
				if (!dir_created)
					if (parent.exists())
					{
						if (!parent.isDirectory())
							throw new TOTorrentException((new StringBuilder()).append("Path '").append(output_file).append("' is invalid").toString(), 5);
					} else
					{
						throw new TOTorrentException((new StringBuilder()).append("Failed to create directory '").append(parent).append("'").toString(), 5);
					}
			}
			File temp = new File(parent, (new StringBuilder()).append(output_file.getName()).append(".saving").toString());
			if (temp.exists())
			{
				if (!temp.delete())
					throw new TOTorrentException((new StringBuilder()).append("Insufficient permissions to delete '").append(temp).append("'").toString(), 5);
			} else
			{
				boolean ok = false;
				try
				{
					ok = temp.createNewFile();
				}
				catch (Throwable e) { }
				if (!ok)
					throw new TOTorrentException((new StringBuilder()).append("Insufficient permissions to write '").append(temp).append("'").toString(), 5);
			}
			FileOutputStream fos = new FileOutputStream(temp, false);
			bos = new BufferedOutputStream(fos, 8192);
			bos.write(res);
			bos.flush();
			fos.getFD().sync();
			bos.close();
			bos = null;
			if (temp.length() > 1L)
			{
				output_file.delete();
				temp.renameTo(output_file);
			}
		}
		catch (TOTorrentException e)
		{
			throw e;
		}
		catch (Throwable e)
		{
			throw new TOTorrentException((new StringBuilder()).append("Failed to serialise torrent: ").append(Debug.getNestedExceptionMessage(e)).toString(), 5);
		}
		finally
		{
			if (bos == null) goto _L0; else goto _L0
		}
		if (bos != null)
			try
			{
				bos.close();
			}
			catch (IOException e)
			{
				Debug.printStackTrace(e);
			}
		break MISSING_BLOCK_LABEL_455;
		try
		{
			bos.close();
		}
		catch (IOException e)
		{
			Debug.printStackTrace(e);
		}
		throw exception;
	}

	protected byte[] serialiseToByteArray()
		throws TOTorrentException
	{
		Map root;
		if (created)
			TorrentUtils.addCreatedTorrent(this);
		root = serialiseToMap();
		return BEncoder.encode(root);
		IOException e;
		e;
		throw new TOTorrentException((new StringBuilder()).append("Failed to serialise torrent: ").append(Debug.getNestedExceptionMessage(e)).toString(), 5);
	}

	public Map serialiseToMap()
		throws TOTorrentException
	{
		if (!created || serialising)
			break MISSING_BLOCK_LABEL_39;
		serialising = true;
		TorrentUtils.addCreatedTorrent(this);
		serialising = false;
		break MISSING_BLOCK_LABEL_39;
		Exception exception;
		exception;
		serialising = false;
		throw exception;
		Map root = new HashMap();
		writeStringToMetaData(root, "announce", announce_url.toString());
		TOTorrentAnnounceURLSet sets[] = announce_group.getAnnounceURLSets();
		if (sets.length > 0)
		{
			List announce_list = new ArrayList();
			for (int i = 0; i < sets.length; i++)
			{
				TOTorrentAnnounceURLSet set = sets[i];
				URL urls[] = set.getAnnounceURLs();
				if (urls.length == 0)
					continue;
				List sub_list = new ArrayList();
				announce_list.add(sub_list);
				for (int j = 0; j < urls.length; j++)
					sub_list.add(writeStringToMetaData(urls[j].toString()));

			}

			if (announce_list.size() > 0)
				root.put("announce-list", announce_list);
		}
		if (comment != null)
			root.put("comment", comment);
		if (creation_date != 0L)
			root.put("creation date", new Long(creation_date));
		if (created_by != null)
			root.put("created by", created_by);
		Map info = new HashMap();
		root.put("info", info);
		info.put("piece length", new Long(piece_length));
		if (pieces == null)
			throw new TOTorrentException("Pieces is null", 5);
		byte flat_pieces[] = new byte[pieces.length * 20];
		for (int i = 0; i < pieces.length; i++)
			System.arraycopy(pieces[i], 0, flat_pieces, i * 20, 20);

		info.put("pieces", flat_pieces);
		info.put("name", torrent_name);
		if (torrent_name_utf8 != null)
			info.put("name.utf-8", torrent_name_utf8);
		if (torrent_hash_override != null)
			info.put("hash-override", torrent_hash_override);
		if (simple_torrent)
		{
			TOTorrentFile file = files[0];
			info.put("length", new Long(file.getLength()));
		} else
		{
			List meta_files = new ArrayList();
			info.put("files", meta_files);
			for (int i = 0; i < files.length; i++)
			{
				TOTorrentFileImpl file = files[i];
				Map file_map = new HashMap();
				meta_files.add(file_map);
				file_map.put("length", new Long(file.getLength()));
				List path = new ArrayList();
				file_map.put("path", path);
				byte path_comps[][] = file.getPathComponents();
				for (int j = 0; j < path_comps.length; j++)
					path.add(path_comps[j]);

				if (file.isUTF8())
				{
					List utf8_path = new ArrayList();
					file_map.put("path.utf-8", utf8_path);
					for (int j = 0; j < path_comps.length; j++)
						utf8_path.add(path_comps[j]);

				}
				Map file_additional_properties = file.getAdditionalProperties();
				String key;
				for (Iterator prop_it = file_additional_properties.keySet().iterator(); prop_it.hasNext(); file_map.put(key, file_additional_properties.get(key)))
					key = (String)prop_it.next();

			}

		}
		String key;
		for (Iterator info_it = additional_info_properties.keySet().iterator(); info_it.hasNext(); info.put(key, additional_info_properties.get(key)))
			key = (String)info_it.next();

		Iterator it = additional_properties.keySet().iterator();
		do
		{
			if (!it.hasNext())
				break;
			String key = (String)it.next();
			Object value = additional_properties.get(key);
			if (value != null)
				root.put(key, value);
		} while (true);
		return root;
	}

	public void serialiseToXMLFile(File file)
		throws TOTorrentException
	{
		if (created)
			TorrentUtils.addCreatedTorrent(this);
		TOTorrentXMLSerialiser serialiser = new TOTorrentXMLSerialiser(this);
		serialiser.serialiseToFile(file);
	}

	public byte[] getName()
	{
		return torrent_name;
	}

	protected void setName(byte _name[])
	{
		torrent_name = _name;
	}

	public boolean isSimpleTorrent()
	{
		return simple_torrent;
	}

	public byte[] getComment()
	{
		return comment;
	}

	protected void setComment(byte _comment[])
	{
		comment = _comment;
	}

	public void setComment(String _comment)
	{
		try
		{
			byte utf8_comment[] = _comment.getBytes("UTF8");
			setComment(utf8_comment);
			setAdditionalByteArrayProperty("comment.utf-8", utf8_comment);
		}
		catch (UnsupportedEncodingException e)
		{
			Debug.printStackTrace(e);
			comment = null;
		}
	}

	public URL getAnnounceURL()
	{
		return announce_url;
	}

	public boolean setAnnounceURL(URL url)
	{
		URL newURL = anonymityTransform(url);
		String s0 = newURL != null ? newURL.toString() : "";
		String s1 = announce_url != null ? announce_url.toString() : "";
		if (s0.equals(s1))
		{
			return false;
		} else
		{
			announce_url = StringInterner.internURL(newURL);
			return true;
		}
	}

	public long getCreationDate()
	{
		return creation_date;
	}

	public void setCreationDate(long _creation_date)
	{
		creation_date = _creation_date;
	}

	protected void setCreatedBy(byte _created_by[])
	{
		created_by = _created_by;
	}

	protected void setCreatedBy(String _created_by)
	{
		try
		{
			setCreatedBy(_created_by.getBytes("UTF8"));
		}
		catch (UnsupportedEncodingException e)
		{
			Debug.printStackTrace(e);
			created_by = null;
		}
	}

	public byte[] getCreatedBy()
	{
		return created_by;
	}

	public boolean isCreated()
	{
		return created;
	}

	public byte[] getHash()
		throws TOTorrentException
	{
		if (torrent_hash == null)
		{
			Map root = serialiseToMap();
			Map info = (Map)root.get("info");

⌨️ 快捷键说明

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