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

📄 torrentimpl.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:   TorrentImpl.java

package org.gudy.azureus2.pluginsimpl.local.torrent;

import com.aelitis.azureus.core.AzureusCore;
import com.aelitis.azureus.core.AzureusCoreFactory;
import com.aelitis.azureus.plugins.magnet.MagnetPlugin;
import java.io.File;
import java.net.URL;
import java.util.Map;
import org.gudy.azureus2.core3.download.DownloadManagerState;
import org.gudy.azureus2.core3.download.DownloadManagerStateFactory;
import org.gudy.azureus2.core3.internat.*;
import org.gudy.azureus2.core3.logging.LogRelation;
import org.gudy.azureus2.core3.torrent.*;
import org.gudy.azureus2.core3.util.*;
import org.gudy.azureus2.plugins.PluginInterface;
import org.gudy.azureus2.plugins.PluginManager;
import org.gudy.azureus2.plugins.download.DownloadException;
import org.gudy.azureus2.plugins.torrent.*;
import org.gudy.azureus2.pluginsimpl.local.download.DownloadImpl;
import org.gudy.azureus2.pluginsimpl.local.download.DownloadManagerImpl;
import org.gudy.azureus2.pluginsimpl.local.utils.UtilitiesImpl;

// Referenced classes of package org.gudy.azureus2.pluginsimpl.local.torrent:
//			TorrentAnnounceURLListImpl, TorrentFileImpl

public class TorrentImpl extends LogRelation
	implements Torrent
{

	private static MagnetPlugin magnet_plugin;
	private PluginInterface pi;
	private TOTorrent torrent;
	private LocaleUtilDecoder decoder;
	private boolean complete;

	public TorrentImpl(TOTorrent _torrent)
	{
		this(null, _torrent);
	}

	public TorrentImpl(PluginInterface _pi, TOTorrent _torrent)
	{
		pi = _pi;
		torrent = _torrent;
	}

	public String getName()
	{
		String name = decode(torrent.getName());
		name = FileUtil.convertOSSpecificChars(name, false);
		return name;
	}

	public URL getAnnounceURL()
	{
		return torrent.getAnnounceURL();
	}

	public void setAnnounceURL(URL url)
	{
		torrent.setAnnounceURL(url);
		updated();
	}

	public TorrentAnnounceURLList getAnnounceURLList()
	{
		return new TorrentAnnounceURLListImpl(this);
	}

	public TOTorrent getTorrent()
	{
		return torrent;
	}

	public boolean isDecentralised()
	{
		return TorrentUtils.isDecentralised(torrent);
	}

	public boolean isDecentralisedBackupEnabled()
	{
		return TorrentUtils.getDHTBackupEnabled(torrent);
	}

	public void setDecentralisedBackupRequested(boolean requested)
	{
		TorrentUtils.setDHTBackupRequested(torrent, requested);
	}

	public boolean isDecentralisedBackupRequested()
	{
		return TorrentUtils.isDHTBackupRequested(torrent);
	}

	public boolean isPrivate()
	{
		return TorrentUtils.getPrivate(torrent);
	}

	public void setPrivate(boolean priv)
	{
		TorrentUtils.setPrivate(torrent, priv);
	}

	public boolean wasCreatedByUs()
	{
		return TorrentUtils.isCreatedTorrent(torrent);
	}

	public URL getMagnetURI()
		throws TorrentException
	{
		if (magnet_plugin == null)
		{
			PluginInterface magnet_pi = AzureusCoreFactory.getSingleton().getPluginManager().getPluginInterfaceByClass(com/aelitis/azureus/plugins/magnet/MagnetPlugin);
			if (magnet_pi != null)
				magnet_plugin = (MagnetPlugin)magnet_pi.getPlugin();
		}
		if (magnet_plugin == null)
			throw new TorrentException("MegnetPlugin unavailable");
		URL res = magnet_plugin.getMagnetURL(torrent.getHash());
		return res;
		TOTorrentException e;
		e;
		throw new TorrentException(e);
	}

	public byte[] getHash()
	{
		return torrent.getHash();
		TOTorrentException e;
		e;
		Debug.printStackTrace(e);
		return null;
	}

	public long getSize()
	{
		return torrent.getSize();
	}

	public String getComment()
	{
		return decode(torrent.getComment());
	}

	public void setComment(String comment)
	{
		torrent.setComment(comment);
	}

	public long getCreationDate()
	{
		return torrent.getCreationDate();
	}

	public String getCreatedBy()
	{
		return decode(torrent.getCreatedBy());
	}

	public long getPieceSize()
	{
		return torrent.getPieceLength();
	}

	public long getPieceCount()
	{
		return (long)torrent.getNumberOfPieces();
	}

	public byte[][] getPieces()
	{
		return torrent.getPieces();
		TOTorrentException e;
		e;
		Debug.printStackTrace(e);
		return new byte[0][0];
	}

	public TorrentFile[] getFiles()
	{
		TOTorrentFile files[] = torrent.getFiles();
		TorrentFile res[] = new TorrentFile[files.length];
		for (int i = 0; i < res.length; i++)
		{
			TOTorrentFile tf = files[i];
			byte comps[][] = tf.getPathComponents();
			String name = "";
			for (int j = 0; j < comps.length; j++)
			{
				String comp = decode(comps[j]);
				comp = FileUtil.convertOSSpecificChars(comp, j != comps.length - 1);
				name = (new StringBuilder()).append(name).append(j != 0 ? File.separator : "").append(comp).toString();
			}

			res[i] = new TorrentFileImpl(name, tf.getLength());
		}

		return res;
	}

	protected void getDecoder()
	{
		try
		{
			decoder = LocaleTorrentUtil.getTorrentEncoding(torrent);
		}
		catch (Throwable e) { }
	}

	public String getEncoding()
	{
		getDecoder();
		if (decoder != null)
			return decoder.getName();
		else
			return "UTF8";
	}

	public void setEncoding(String encoding)
		throws TorrentEncodingException
	{
		try
		{
			LocaleTorrentUtil.setTorrentEncoding(torrent, encoding);
		}
		catch (LocaleUtilEncodingException e)
		{
			throw new TorrentEncodingException("Failed to set the encoding", e);
		}
	}

	public void setDefaultEncoding()
		throws TorrentEncodingException
	{
		setEncoding("UTF8");
	}

	protected String decode(byte data[])
	{
		getDecoder();
		if (data == null)
			break MISSING_BLOCK_LABEL_36;
		if (decoder == null)
			break MISSING_BLOCK_LABEL_27;
		return decoder.decodeString(data);
		Throwable e;
		e;
		return new String(data);
		return "";
	}

	public Object getAdditionalProperty(String name)
	{
		return torrent.getAdditionalProperty(name);
	}

	public Torrent removeAdditionalProperties()
	{
		TOTorrent t;
		t = TOTorrentFactory.deserialiseFromMap(torrent.serialiseToMap());
		t.removeAdditionalProperties();
		return new TorrentImpl(t);
		TOTorrentException e;
		e;
		Debug.printStackTrace(e);
		return this;
	}

	public void setPluginStringProperty(String name, String value)
	{
		PluginInterface p = pi;
		if (p == null)
			p = UtilitiesImpl.getPluginThreadContext();
		if (p == null)
			name = (new StringBuilder()).append("<internal>.").append(name).toString();
		else
			name = (new StringBuilder()).append(p.getPluginID()).append(".").append(name).toString();
		TorrentUtils.setPluginStringProperty(torrent, name, value);
	}

	public String getPluginStringProperty(String name)
	{
		PluginInterface p = pi;
		if (p == null)
			p = UtilitiesImpl.getPluginThreadContext();
		if (p == null)
			name = (new StringBuilder()).append("<internal>.").append(name).toString();
		else
			name = (new StringBuilder()).append(p.getPluginID()).append(".").append(name).toString();
		return TorrentUtils.getPluginStringProperty(torrent, name);
	}

	public void setMapProperty(String name, Map value)
	{
		TorrentUtils.setPluginMapProperty(torrent, name, value);
	}

	public Map getMapProperty(String name)
	{
		return TorrentUtils.getPluginMapProperty(torrent, name);
	}

	public Map writeToMap()
		throws TorrentException
	{
		return torrent.serialiseToMap();
		TOTorrentException e;
		e;
		throw new TorrentException("Torrent::writeToMap: fails", e);
	}

	public byte[] writeToBEncodedData()
		throws TorrentException
	{
		Map map = torrent.serialiseToMap();
		return BEncoder.encode(map);
		Throwable e;
		e;
		throw new TorrentException("Torrent::writeToBEncodedData: fails", e);
	}

	public void writeToFile(File file)
		throws TorrentException
	{
		try
		{
			torrent.serialiseToBEncodedFile(file);
		}
		catch (TOTorrentException e)
		{
			throw new TorrentException("Torrent::writeToFile: fails", e);
		}
	}

	protected void updated()
	{
		try
		{
			DownloadImpl dm = (DownloadImpl)DownloadManagerImpl.getDownloadStatic(torrent);
			if (dm != null)
				dm.torrentChanged();
		}
		catch (DownloadException e) { }
	}

	public void save()
		throws TorrentException
	{
		try
		{
			TorrentUtils.writeToFile(torrent);
		}
		catch (TOTorrentException e)
		{
			throw new TorrentException("Torrent::save Fails", e);
		}
	}

	public void setComplete(File data_dir)
		throws TorrentException
	{
		try
		{
			LocaleTorrentUtil.setDefaultTorrentEncoding(torrent);
			DownloadManagerState download_manager_state = DownloadManagerStateFactory.getDownloadState(torrent);
			TorrentUtils.setResumeDataCompletelyValid(download_manager_state);
			download_manager_state.save();
			complete = true;
		}
		catch (Throwable e)
		{
			throw new TorrentException("encoding selection fails", e);
		}
	}

	public boolean isComplete()
	{
		return complete;
	}

	public String getRelationText()
	{
		return propogatedRelationText(torrent);
	}

	public Object[] getQueryableInterfaces()
	{
		return (new Object[] {
			torrent
		});
	}

	public boolean isSimpleTorrent()
	{
		return torrent.isSimpleTorrent();
	}
}

⌨️ 快捷键说明

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