📄 torrentmanagerimpl.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: TorrentManagerImpl.java
package org.gudy.azureus2.pluginsimpl.local.torrent;
import com.aelitis.azureus.core.util.CopyOnWriteList;
import java.io.*;
import java.net.URL;
import java.util.*;
import org.gudy.azureus2.core3.internat.LocaleTorrentUtil;
import org.gudy.azureus2.core3.internat.LocaleUtilEncodingException;
import org.gudy.azureus2.core3.torrent.*;
import org.gudy.azureus2.core3.util.*;
import org.gudy.azureus2.plugins.PluginInterface;
import org.gudy.azureus2.plugins.torrent.*;
// Referenced classes of package org.gudy.azureus2.pluginsimpl.local.torrent:
// TorrentAttributeCategoryImpl, TorrentAttributeDisplayNameImpl, TorrentAttributeNetworksImpl, TorrentAttributePeerSourcesImpl,
// TorrentAttributePluginImpl, TorrentAttributeRelativeSavePathImpl, TorrentAttributeSharePropertiesImpl, TorrentAttributeTrackerClientExtImpl,
// TorrentAttributeUserCommentImpl, TorrentDownloaderImpl, TorrentImpl
public class TorrentManagerImpl
implements TorrentManager, TOTorrentProgressListener
{
private static TorrentManagerImpl singleton;
private static AEMonitor class_mon = new AEMonitor("TorrentManager");
private static TorrentAttribute category_attribute;
private static TorrentAttribute share_properties_attribute;
private static TorrentAttribute networks_attribute;
private static TorrentAttribute peer_sources_attribute;
private static TorrentAttribute tr_ext_attribute;
private static TorrentAttribute disp_name_attribute;
private static TorrentAttribute comment_attribute;
private static TorrentAttribute relative_save_path_attribute;
private static Map attribute_map;
protected static List listeners = new ArrayList();
protected PluginInterface plugin_interface;
public static TorrentManagerImpl getSingleton()
{
TorrentManagerImpl torrentmanagerimpl;
class_mon.enter();
if (singleton == null)
singleton = new TorrentManagerImpl(null);
torrentmanagerimpl = singleton;
class_mon.exit();
return torrentmanagerimpl;
Exception exception;
exception;
class_mon.exit();
throw exception;
}
protected TorrentManagerImpl(PluginInterface _pi)
{
plugin_interface = _pi;
}
public TorrentManager specialise(PluginInterface _pi)
{
return new TorrentManagerImpl(_pi);
}
public TorrentDownloader getURLDownloader(URL url)
throws TorrentException
{
return new TorrentDownloaderImpl(this, url);
}
public TorrentDownloader getURLDownloader(URL url, String user_name, String password)
throws TorrentException
{
return new TorrentDownloaderImpl(this, url, user_name, password);
}
public Torrent createFromBEncodedFile(File file)
throws TorrentException
{
return createFromBEncodedFile(file, false);
}
public Torrent createFromBEncodedFile(File file, boolean for_seeding)
throws TorrentException
{
TOTorrent torrent;
if (for_seeding)
torrent = TorrentUtils.readFromFile(file, true, true);
else
torrent = TorrentUtils.readFromFile(file, false);
return new TorrentImpl(plugin_interface, torrent);
TOTorrentException e;
e;
throw new TorrentException("TorrentManager::createFromBEncodedFile Fails", e);
}
public Torrent createFromBEncodedInputStream(InputStream data)
throws TorrentException
{
return new TorrentImpl(plugin_interface, TorrentUtils.readFromBEncodedInputStream(data));
TOTorrentException e;
e;
throw new TorrentException("TorrentManager::createFromBEncodedFile Fails", e);
}
public Torrent createFromBEncodedData(byte data[])
throws TorrentException
{
ByteArrayInputStream is;
Exception exception;
is = null;
TorrentImpl torrentimpl;
try
{
is = new ByteArrayInputStream(data);
torrentimpl = new TorrentImpl(plugin_interface, TorrentUtils.readFromBEncodedInputStream(is));
}
catch (TOTorrentException e)
{
throw new TorrentException("TorrentManager::createFromBEncodedData Fails", e);
}
finally { }
try
{
is.close();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
return torrentimpl;
try
{
is.close();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
throw exception;
}
public Torrent createFromDataFile(File data, URL announce_url)
throws TorrentException
{
return createFromDataFile(data, announce_url, false);
}
public Torrent createFromDataFile(File data, URL announce_url, boolean include_other_hashes)
throws TorrentException
{
TOTorrentCreator c;
c = TOTorrentFactory.createFromFileOrDirWithComputedPieceLength(data, announce_url, include_other_hashes);
c.addListener(this);
return new TorrentImpl(plugin_interface, c.create());
TOTorrentException e;
e;
throw new TorrentException("TorrentManager::createFromDataFile Fails", e);
}
public TorrentCreator createFromDataFileEx(File data, URL announce_url, boolean include_other_hashes)
throws TorrentException
{
final TOTorrentCreator c = TOTorrentFactory.createFromFileOrDirWithComputedPieceLength(data, announce_url, include_other_hashes);
return new TorrentCreator() {
private CopyOnWriteList listeners;
final TOTorrentCreator val$c;
final TorrentManagerImpl this$0;
public void start()
{
c.addListener(new TOTorrentProgressListener() {
final 1 this$1;
public void reportProgress(int percent_complete)
{
for (Iterator it = listeners.iterator(); it.hasNext(); ((TorrentCreatorListener)it.next()).reportPercentageDone(percent_complete));
}
public void reportCurrentTask(String task_description)
{
for (Iterator it = listeners.iterator(); it.hasNext(); ((TorrentCreatorListener)it.next()).reportActivity(task_description));
}
{
this$1 = 1.this;
super();
}
});
(new AEThread("TorrentManager::create", true) {
final 1 this$1;
public void runSupport()
{
try
{
TOTorrent t = c.create();
Torrent torrent = new TorrentImpl(plugin_interface, t);
for (Iterator it = listeners.iterator(); it.hasNext(); ((TorrentCreatorListener)it.next()).complete(torrent));
}
catch (TOTorrentException e)
{
for (Iterator it = listeners.iterator(); it.hasNext(); ((TorrentCreatorListener)it.next()).failed(new TorrentException(e)));
}
}
{
this$1 = 1.this;
super(x0, x1);
}
}).start();
}
public void cancel()
{
c.cancel();
}
public void addListener(TorrentCreatorListener listener)
{
listeners.add(listener);
}
public void removeListener(TorrentCreatorListener listener)
{
listeners.remove(listener);
}
{
this$0 = TorrentManagerImpl.this;
c = totorrentcreator;
super();
listeners = new CopyOnWriteList();
}
};
TOTorrentException e;
e;
throw new TorrentException("TorrentManager::createFromDataFile Fails", e);
}
public TorrentAttribute[] getDefinedAttributes()
{
TorrentAttribute atorrentattribute[];
class_mon.enter();
Collection entries = attribute_map.values();
TorrentAttribute res[] = new TorrentAttribute[entries.size()];
entries.toArray(res);
atorrentattribute = res;
class_mon.exit();
return atorrentattribute;
Exception exception;
exception;
class_mon.exit();
throw exception;
}
public TorrentAttribute getAttribute(String name)
{
TorrentAttribute torrentattribute;
class_mon.enter();
TorrentAttribute res = (TorrentAttribute)attribute_map.get(name);
if (res == null && name.startsWith("Plugin."))
{
res = new TorrentAttributePluginImpl(name);
attribute_map.put(name, res);
}
if (res == null)
throw new IllegalArgumentException((new StringBuilder()).append("No such attribute: \"").append(name).append("\"").toString());
torrentattribute = res;
class_mon.exit();
return torrentattribute;
Exception exception;
exception;
class_mon.exit();
throw exception;
}
public TorrentAttribute getPluginAttribute(String name)
{
name = (new StringBuilder()).append("Plugin.").append(plugin_interface.getPluginID()).append(".").append(name).toString();
TorrentAttribute torrentattribute;
class_mon.enter();
TorrentAttribute res = (TorrentAttribute)attribute_map.get(name);
if (res == null)
break MISSING_BLOCK_LABEL_70;
torrentattribute = res;
class_mon.exit();
return torrentattribute;
TorrentAttribute res = new TorrentAttributePluginImpl(name);
attribute_map.put(name, res);
torrentattribute = res;
class_mon.exit();
return torrentattribute;
Exception exception;
exception;
class_mon.exit();
throw exception;
}
public Torrent createFromBEncodedData(byte data[], int preserve)
throws TorrentException
{
ByteArrayInputStream bais;
Exception exception;
bais = new ByteArrayInputStream(data);
TorrentImpl torrentimpl;
try
{
TOTorrent torrent = TOTorrentFactory.deserialiseFromBEncodedInputStream(bais);
torrentimpl = new TorrentImpl(plugin_interface, preserveFields(torrent, preserve));
}
catch (TOTorrentException e)
{
throw new TorrentException("Failed to read TorrentData", e);
}
finally { }
try
{
bais.close();
}
catch (IOException e) { }
return torrentimpl;
try
{
bais.close();
}
catch (IOException e) { }
throw exception;
}
public Torrent createFromBEncodedFile(File file, int preserve)
throws TorrentException
{
FileInputStream fis;
Exception exception;
fis = null;
TorrentImpl torrentimpl;
try
{
fis = new FileInputStream(file);
TOTorrent torrent = TOTorrentFactory.deserialiseFromBEncodedInputStream(fis);
torrentimpl = new TorrentImpl(plugin_interface, preserveFields(torrent, preserve));
}
catch (FileNotFoundException e)
{
throw new TorrentException("Failed to read from TorrentFile", e);
}
catch (TOTorrentException e)
{
throw new TorrentException("Failed to read TorrentData", e);
}
finally
{
if (fis == null) goto _L0; else goto _L0
}
if (fis != null)
try
{
fis.close();
}
catch (IOException e) { }
return torrentimpl;
try
{
fis.close();
}
catch (IOException e) { }
throw exception;
}
public Torrent createFromBEncodedInputStream(InputStream data, int preserve)
throws TorrentException
{
TOTorrent torrent = TOTorrentFactory.deserialiseFromBEncodedInputStream(data);
return new TorrentImpl(plugin_interface, preserveFields(torrent, preserve));
TOTorrentException e;
e;
throw new TorrentException("Failed to read TorrentData", e);
}
private TOTorrent preserveFields(TOTorrent torrent, int preserve)
{
if (preserve == -1)
return torrent;
if ((preserve & 1) > 0)
{
String encoding = torrent.getAdditionalStringProperty("encoding");
torrent.removeAdditionalProperties();
if (encoding != null)
torrent.setAdditionalStringProperty("encoding", encoding);
} else
if (preserve == 0)
torrent.removeAdditionalProperties();
return torrent;
}
public void reportProgress(int i)
{
}
public void reportCurrentTask(final String task_description)
{
for (Iterator it = listeners.iterator(); it.hasNext(); ((TorrentManagerListener)it.next()).event(new TorrentManagerEvent() {
final String val$task_description;
final TorrentManagerImpl this$0;
public Object getData()
{
return task_description;
}
{
this$0 = TorrentManagerImpl.this;
task_description = s;
super();
}
}));
}
protected void tryToSetTorrentEncoding(TOTorrent torrent, String encoding)
throws TorrentEncodingException
{
try
{
LocaleTorrentUtil.setTorrentEncoding(torrent, encoding);
}
catch (LocaleUtilEncodingException e)
{
String charsets[] = e.getValidCharsets();
if (charsets == null)
throw new TorrentEncodingException("Failed to set requested encoding", e);
else
throw new TorrentEncodingException(charsets, e.getValidTorrentNames());
}
}
protected void tryToSetDefaultTorrentEncoding(TOTorrent torrent)
throws TorrentException
{
try
{
LocaleTorrentUtil.setDefaultTorrentEncoding(torrent);
}
catch (LocaleUtilEncodingException e)
{
String charsets[] = e.getValidCharsets();
if (charsets == null)
throw new TorrentEncodingException("Failed to set default encoding", e);
else
throw new TorrentEncodingException(charsets, e.getValidTorrentNames());
}
}
public void addListener(TorrentManagerListener l)
{
class_mon.enter();
ArrayList new_listeners = new ArrayList(listeners);
new_listeners.add(l);
listeners = new_listeners;
class_mon.exit();
break MISSING_BLOCK_LABEL_45;
Exception exception;
exception;
class_mon.exit();
throw exception;
}
public void removeListener(TorrentManagerListener l)
{
class_mon.enter();
ArrayList new_listeners = new ArrayList(listeners);
new_listeners.remove(l);
listeners = new_listeners;
class_mon.exit();
break MISSING_BLOCK_LABEL_45;
Exception exception;
exception;
class_mon.exit();
throw exception;
}
static
{
category_attribute = new TorrentAttributeCategoryImpl();
share_properties_attribute = new TorrentAttributeSharePropertiesImpl();
networks_attribute = new TorrentAttributeNetworksImpl();
peer_sources_attribute = new TorrentAttributePeerSourcesImpl();
tr_ext_attribute = new TorrentAttributeTrackerClientExtImpl();
disp_name_attribute = new TorrentAttributeDisplayNameImpl();
comment_attribute = new TorrentAttributeUserCommentImpl();
relative_save_path_attribute = new TorrentAttributeRelativeSavePathImpl();
attribute_map = new HashMap();
attribute_map.put("Category", category_attribute);
attribute_map.put("ShareProperties", share_properties_attribute);
attribute_map.put("Networks", networks_attribute);
attribute_map.put("PeerSources", peer_sources_attribute);
attribute_map.put("TrackerClientExtensions", tr_ext_attribute);
attribute_map.put("DisplayName", disp_name_attribute);
attribute_map.put("UserComment", comment_attribute);
attribute_map.put("RelativePath", relative_save_path_attribute);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -