📄 torrentutils.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: TorrentUtils.java
package org.gudy.azureus2.core3.util;
import com.aelitis.azureus.core.AzureusCore;
import com.aelitis.azureus.core.AzureusCoreFactory;
import com.aelitis.azureus.core.util.CopyOnWriteList;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.config.ParameterListener;
import org.gudy.azureus2.core3.disk.DiskManagerFactory;
import org.gudy.azureus2.core3.download.DownloadManager;
import org.gudy.azureus2.core3.download.DownloadManagerState;
import org.gudy.azureus2.core3.global.GlobalManager;
import org.gudy.azureus2.core3.internat.*;
import org.gudy.azureus2.core3.logging.LogRelation;
import org.gudy.azureus2.core3.torrent.*;
// Referenced classes of package org.gudy.azureus2.core3.util:
// AEMonitor, Base32, ByteFormatter, Debug,
// FileIsADirectoryException, FileUtil, HashWrapper, SimpleTimer,
// SystemTime, UrlUtils, TimerEventPerformer, TimerEvent
public class TorrentUtils
{
public static interface ExtendedTorrent
extends TOTorrent
{
public abstract byte[][] peekPieces()
throws TOTorrentException;
public abstract void setDiscardFluff(boolean flag);
}
public static interface torrentAttributeListener
{
public abstract void attributeSet(TOTorrent totorrent, String s, Object obj);
}
private static class torrentDelegate extends LogRelation
implements ExtendedTorrent
{
private TOTorrent delegate;
private File file;
private boolean fluff_dirty;
private long last_pieces_read_time;
public void setDiscardFluff(boolean discard)
{
if (!discard || TorrentUtils.torrentFluffKeyset.isEmpty())
break MISSING_BLOCK_LABEL_134;
getMonitor().enter();
try
{
if (fluff_dirty)
{
boolean restored[] = restoreState(true, true);
delegate.serialiseToBEncodedFile(file);
fluff_dirty = false;
if (restored[0])
discardPieces(SystemTime.getCurrentTime(), true);
}
for (Iterator it = TorrentUtils.torrentFluffKeyset.iterator(); it.hasNext(); delegate.setAdditionalMapProperty((String)it.next(), TorrentUtils.fluffThombstone));
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
getMonitor().exit();
break MISSING_BLOCK_LABEL_134;
Exception exception;
exception;
getMonitor().exit();
throw exception;
}
public byte[] getName()
{
return delegate.getName();
}
public boolean isSimpleTorrent()
{
return delegate.isSimpleTorrent();
}
public byte[] getComment()
{
return delegate.getComment();
}
public void setComment(String comment)
{
delegate.setComment(comment);
}
public long getCreationDate()
{
return delegate.getCreationDate();
}
public void setCreationDate(long date)
{
delegate.setCreationDate(date);
}
public byte[] getCreatedBy()
{
return delegate.getCreatedBy();
}
public boolean isCreated()
{
return delegate.isCreated();
}
public URL getAnnounceURL()
{
return delegate.getAnnounceURL();
}
public boolean setAnnounceURL(URL url)
{
return delegate.setAnnounceURL(url);
}
public TOTorrentAnnounceURLGroup getAnnounceURLGroup()
{
return delegate.getAnnounceURLGroup();
}
protected void discardPieces(long now, boolean force)
{
if (now < last_pieces_read_time && !force)
{
last_pieces_read_time = now;
break MISSING_BLOCK_LABEL_102;
}
if (now - last_pieces_read_time <= 0x2bf20L && !force || delegate.getPieces() == null)
break MISSING_BLOCK_LABEL_102;
getMonitor().enter();
delegate.setPieces((byte[][])null);
getMonitor().exit();
break MISSING_BLOCK_LABEL_102;
Throwable e;
e;
getMonitor().exit();
throw e;
e;
Debug.printStackTrace(e);
}
public byte[][] getPieces()
throws TOTorrentException
{
byte res[][];
res = delegate.getPieces();
last_pieces_read_time = SystemTime.getCurrentTime();
if (res != null)
break MISSING_BLOCK_LABEL_65;
getMonitor().enter();
restoreState(true, false);
res = delegate.getPieces();
getMonitor().exit();
break MISSING_BLOCK_LABEL_65;
Exception exception;
exception;
getMonitor().exit();
throw exception;
return res;
}
protected boolean[] restoreState(boolean do_pieces, boolean do_fluff)
throws TOTorrentException
{
boolean had_pieces = delegate.getPieces() != null;
boolean had_fluff = true;
for (Iterator it = TorrentUtils.torrentFluffKeyset.iterator(); it.hasNext();)
had_fluff &= delegate.getAdditionalMapProperty((String)it.next()) != TorrentUtils.fluffThombstone;
if (had_pieces)
do_pieces = false;
if (had_fluff)
do_fluff = false;
if (do_pieces || do_fluff)
{
TOTorrent temp = TorrentUtils.readFromFile(file, false);
if (do_pieces)
{
byte res[][] = temp.getPieces();
delegate.setPieces(res);
}
if (do_fluff)
{
Iterator it = TorrentUtils.torrentFluffKeyset.iterator();
do
{
if (!it.hasNext())
break;
String fluffKey = (String)it.next();
if (delegate.getAdditionalMapProperty(fluffKey) == TorrentUtils.fluffThombstone)
delegate.setAdditionalMapProperty(fluffKey, temp.getAdditionalMapProperty(fluffKey));
} while (true);
}
}
return (new boolean[] {
do_pieces, do_fluff
});
}
public byte[][] peekPieces()
throws TOTorrentException
{
return delegate.getPieces();
}
public void setPieces(byte pieces[][])
throws TOTorrentException
{
throw new TOTorrentException("Unsupported Operation", 5);
}
public long getPieceLength()
{
return delegate.getPieceLength();
}
public int getNumberOfPieces()
{
return delegate.getNumberOfPieces();
}
public long getSize()
{
return delegate.getSize();
}
public TOTorrentFile[] getFiles()
{
return delegate.getFiles();
}
public byte[] getHash()
throws TOTorrentException
{
return delegate.getHash();
}
public HashWrapper getHashWrapper()
throws TOTorrentException
{
return delegate.getHashWrapper();
}
public void setHashOverride(byte hash[])
throws TOTorrentException
{
throw new TOTorrentException("Not supported", 8);
}
public boolean getPrivate()
{
return delegate.getPrivate();
}
public void setPrivate(boolean _private)
throws TOTorrentException
{
throw new TOTorrentException("Can't amend private attribute", 5);
}
public boolean hasSameHashAs(TOTorrent other)
{
return delegate.hasSameHashAs(other);
}
public void setAdditionalStringProperty(String name, String value)
{
delegate.setAdditionalStringProperty(name, value);
}
public String getAdditionalStringProperty(String name)
{
return delegate.getAdditionalStringProperty(name);
}
public void setAdditionalByteArrayProperty(String name, byte value[])
{
delegate.setAdditionalByteArrayProperty(name, value);
}
public byte[] getAdditionalByteArrayProperty(String name)
{
return delegate.getAdditionalByteArrayProperty(name);
}
public void setAdditionalLongProperty(String name, Long value)
{
delegate.setAdditionalLongProperty(name, value);
}
public Long getAdditionalLongProperty(String name)
{
return delegate.getAdditionalLongProperty(name);
}
public void setAdditionalListProperty(String name, List value)
{
delegate.setAdditionalListProperty(name, value);
}
public List getAdditionalListProperty(String name)
{
return delegate.getAdditionalListProperty(name);
}
public void setAdditionalMapProperty(String name, Map value)
{
if (!TorrentUtils.torrentFluffKeyset.contains(name))
break MISSING_BLOCK_LABEL_56;
getMonitor().enter();
delegate.setAdditionalMapProperty(name, value);
fluff_dirty = true;
getMonitor().exit();
break MISSING_BLOCK_LABEL_67;
Exception exception;
exception;
getMonitor().exit();
throw exception;
delegate.setAdditionalMapProperty(name, value);
}
public Map getAdditionalMapProperty(String name)
{
if (!TorrentUtils.torrentFluffKeyset.contains(name))
break MISSING_BLOCK_LABEL_117;
getMonitor().enter();
Map result = delegate.getAdditionalMapProperty(name);
if (result != TorrentUtils.fluffThombstone)
break MISSING_BLOCK_LABEL_95;
Map map;
restoreState(false, true);
Map res = delegate.getAdditionalMapProperty(name);
map = res;
getMonitor().exit();
return map;
Throwable e;
e;
Debug.out((new StringBuilder()).append("Property '").append(name).append(" lost due to torrent read error").toString(), e);
getMonitor().exit();
break MISSING_BLOCK_LABEL_117;
Exception exception;
exception;
getMonitor().exit();
throw exception;
return delegate.getAdditionalMapProperty(name);
}
public Object getAdditionalProperty(String name)
{
if (!TorrentUtils.torrentFluffKeyset.contains(name))
break MISSING_BLOCK_LABEL_117;
getMonitor().enter();
Object result = delegate.getAdditionalProperty(name);
if (result != TorrentUtils.fluffThombstone)
break MISSING_BLOCK_LABEL_95;
Object obj;
restoreState(false, true);
Object res = delegate.getAdditionalProperty(name);
obj = res;
getMonitor().exit();
return obj;
Throwable e;
e;
Debug.out((new StringBuilder()).append("Property '").append(name).append(" lost due to torrent read error").toString(), e);
getMonitor().exit();
break MISSING_BLOCK_LABEL_117;
Exception exception;
exception;
getMonitor().exit();
throw exception;
return delegate.getAdditionalProperty(name);
}
public void setAdditionalProperty(String name, Object value)
{
if (!TorrentUtils.torrentFluffKeyset.contains(name))
break MISSING_BLOCK_LABEL_56;
getMonitor().enter();
delegate.setAdditionalProperty(name, value);
fluff_dirty = true;
getMonitor().exit();
break MISSING_BLOCK_LABEL_67;
Exception exception;
exception;
getMonitor().exit();
throw exception;
delegate.setAdditionalProperty(name, value);
}
public void removeAdditionalProperty(String name)
{
if (delegate.getAdditionalProperty(name) == null)
return;
if (!TorrentUtils.torrentFluffKeyset.contains(name))
break MISSING_BLOCK_LABEL_69;
getMonitor().enter();
delegate.removeAdditionalProperty(name);
fluff_dirty = true;
getMonitor().exit();
break MISSING_BLOCK_LABEL_79;
Exception exception;
exception;
getMonitor().exit();
throw exception;
delegate.removeAdditionalProperty(name);
}
public void removeAdditionalProperties()
{
getMonitor().enter();
delegate.removeAdditionalProperties();
fluff_dirty = true;
getMonitor().exit();
break MISSING_BLOCK_LABEL_41;
Exception exception;
exception;
getMonitor().exit();
throw exception;
}
public void serialiseToBEncodedFile(File target_file)
throws TOTorrentException
{
getMonitor().enter();
boolean restored[] = restoreState(true, true);
delegate.serialiseToBEncodedFile(target_file);
if (target_file.equals(file))
fluff_dirty = false;
if (restored[0])
discardPieces(SystemTime.getCurrentTime(), true);
if (restored[1])
{
for (Iterator it = TorrentUtils.torrentFluffKeyset.iterator(); it.hasNext(); delegate.setAdditionalMapProperty((String)it.next(), TorrentUtils.fluffThombstone));
}
getMonitor().exit();
break MISSING_BLOCK_LABEL_122;
Exception exception;
exception;
getMonitor().exit();
throw exception;
}
public Map serialiseToMap()
throws TOTorrentException
{
Map map;
getMonitor().enter();
boolean restored[] = restoreState(true, true);
Map result = delegate.serialiseToMap();
if (restored[0])
discardPieces(SystemTime.getCurrentTime(), true);
if (restored[1])
{
for (Iterator it = TorrentUtils.torrentFluffKeyset.iterator(); it.hasNext(); delegate.setAdditionalMapProperty((String)it.next(), TorrentUtils.fluffThombstone));
}
map = result;
getMonitor().exit();
return map;
Exception exception;
exception;
getMonitor().exit();
throw exception;
}
public void serialiseToXMLFile(File target_file)
throws TOTorrentException
{
getMonitor().enter();
boolean restored[] = restoreState(true, true);
delegate.serialiseToXMLFile(target_file);
if (restored[0])
discardPieces(SystemTime.getCurrentTime(), true);
if (restored[1])
{
for (Iterator it = TorrentUtils.torrentFluffKeyset.iterator(); it.hasNext(); delegate.setAdditionalMapProperty((String)it.next(), TorrentUtils.fluffThombstone));
}
getMonitor().exit();
break MISSING_BLOCK_LABEL_106;
Exception exception;
exception;
getMonitor().exit();
throw exception;
}
public AEMonitor getMonitor()
{
return delegate.getMonitor();
}
public void print()
{
delegate.print();
}
public String getRelationText()
{
if (delegate instanceof LogRelation)
return ((LogRelation)delegate).getRelationText();
else
return delegate.toString();
}
public Object[] getQueryableInterfaces()
{
if (delegate instanceof LogRelation)
return ((LogRelation)delegate).getQueryableInterfaces();
else
return super.getQueryableInterfaces();
}
protected torrentDelegate(TOTorrent _delegate, File _file)
{
last_pieces_read_time = SystemTime.getCurrentTime();
delegate = _delegate;
file = _file;
synchronized (TorrentUtils.torrent_delegates)
{
TorrentUtils.torrent_delegates.put(this, null);
}
}
}
public static final int TORRENT_FLAG_LOW_NOISE = 1;
private static final String TORRENT_AZ_PROP_DHT_BACKUP_ENABLE = "dht_backup_enable";
private static final String TORRENT_AZ_PROP_DHT_BACKUP_REQUESTED = "dht_backup_requested";
private static final String TORRENT_AZ_PROP_TORRENT_FLAGS = "torrent_flags";
private static final String TORRENT_AZ_PROP_PLUGINS = "plugins";
public static final String TORRENT_AZ_PROP_OBTAINED_FROM = "obtained_from";
private static final String MEM_ONLY_TORRENT_PATH = "?/\\!:mem_only:!\\/?";
private static final List created_torrents;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -