org.gudy.azureus2.core3.util
Class TorrentUtils

java.lang.Object
  extended by org.gudy.azureus2.core3.util.TorrentUtils

public class TorrentUtils
extends Object


Nested Class Summary
static interface TorrentUtils.ExtendedTorrent
           
static interface TorrentUtils.TorrentAnnounceURLChangeListener
           
static interface TorrentUtils.torrentAttributeListener
           
static class TorrentUtils.torrentDelegate
           
 
Field Summary
static long MAX_TORRENT_FILE_SIZE
           
static String TORRENT_AZ_PROP_INITIAL_LINKAGE
           
static String TORRENT_AZ_PROP_INITIAL_LINKAGE2
           
static String TORRENT_AZ_PROP_OBTAINED_FROM
           
static int TORRENT_FLAG_LOW_NOISE
           
static int TORRENT_FLAG_METADATA_TORRENT
           
 
Constructor Summary
TorrentUtils()
           
 
Method Summary
static void addCreatedTorrent(TOTorrent torrent)
           
static void addTorrentAttributeListener(TorrentUtils.torrentAttributeListener listener)
           
static void addTorrentURLChangeListener(TorrentUtils.TorrentAnnounceURLChangeListener listener)
           
static boolean announceGroupsContainsURL(TOTorrent torrent, String url)
           
static void announceGroupsInsertFirst(TOTorrent torrent, String first_url)
           
static void announceGroupsInsertFirst(TOTorrent torrent, URL first_url)
           
static void announceGroupsInsertFirst(TOTorrent torrent, URL[] first_urls)
           
static void announceGroupsInsertLast(TOTorrent torrent, URL[] first_urls)
           
static void announceGroupsSetFirst(TOTorrent torrent, String first_url)
           
static List<List<String>> announceGroupsToList(TOTorrent torrent)
           
static String announceGroupsToText(List<List<String>> group)
           
static String announceGroupsToText(TOTorrent torrent)
           
static List<List<String>> announceTextToGroups(String text)
           
static boolean canMergeAnnounceURLs(TOTorrent new_torrent, TOTorrent dest_torrent)
           
static TOTorrent cloneTorrent(TOTorrent torrent)
           
static void copyToFile(TOTorrent torrent, File file)
           
static File copyTorrentFileToSaveDir(File f, boolean persistent)
          Copy a file to the Torrent Save Directory, taking into account all the user config options related to that.
static void delete(File torrent_file, boolean force_no_recycle)
           
static void delete(TOTorrent torrent)
           
static TOTorrent download(URL url)
           
static TOTorrent download(URL url, long timeout)
           
static void endTorrentDelete()
           
static String exceptionToText(TOTorrentException e)
           
static List<List<String>> getClone(List<List<String>> lls)
           
static URL getDecentralisedEmptyURL()
           
static URL getDecentralisedURL(byte[] hash)
           
static URL getDecentralisedURL(TOTorrent torrent)
           
static boolean getDHTBackupEnabled(TOTorrent torrent)
           
static DownloadManager getDownloadManager(HashWrapper hash)
          Get the DownloadManager related to a torrent's hashBytes
static boolean getFlag(TOTorrent torrent, int flag)
           
static Set<String> getIgnoreSet()
           
static Map<Integer,File> getInitialLinkage(TOTorrent torrent)
           
static String getLocalisedName(TOTorrent torrent)
           
static long getMillisecondsSinceLastTorrentDelete()
           
static List<String> getNetworkCache(TOTorrent torrent)
           
static String getObtainedFrom(TOTorrent torrent)
           
static Map getPeerCache(TOTorrent torrent)
           
static Map getPluginMapProperty(TOTorrent torrent, String name)
           
static String getPluginStringProperty(TOTorrent torrent, String name)
           
static boolean getPrivate(TOTorrent torrent)
           
static Set<String> getSkipExtensionsSet()
           
static List<String> getTagCache(TOTorrent torrent)
           
static Object getTLS()
          get tls for cloning onto another thread
static String getTLSDescription()
           
static TOTorrent getTLSTorrent()
           
static HashWrapper getTLSTorrentHash()
           
static String getTorrentFileName(TOTorrent torrent)
           
static Set<String> getUniqueTrackerHosts(TOTorrent torrent)
           
static boolean isCreatedTorrent(TOTorrent torrent)
           
static boolean isDecentralised(String host)
           
static boolean isDecentralised(TOTorrent torrent)
           
static boolean isDecentralised(URL url)
           
static boolean isDHTBackupRequested(TOTorrent torrent)
           
static boolean isFeaturedContent(TOTorrent torrent)
           
static boolean isReallyPrivate(TOTorrent torrent)
           
static boolean isTorrentDeleting()
           
static boolean isTorrentFile(String filename)
          Runs a file through a series of test to verify if it is a torrent.
static void listToAnnounceGroups(List<List<String>> groups, TOTorrent torrent)
           
static TOTorrentAnnounceURLSet[] listToAnnounceSets(List<List<String>> groups, TOTorrent torrent)
          This method DOES NOT MODIFY THE TORRENT
static void main(String[] args)
           
static List<List<String>> mergeAnnounceURLs(List<List<String>> base_urls, List<List<String>> merge_urls)
           
static boolean mergeAnnounceURLs(TOTorrent new_torrent, TOTorrent dest_torrent)
           
static boolean move(File from_torrent, File to_torrent)
           
static String nicePrintTorrentHash(TOTorrent torrent)
          A nice string of a Torrent's hash
static String nicePrintTorrentHash(TOTorrent torrent, boolean tight)
          A nice string of a Torrent's hash
static TorrentUtils.ExtendedTorrent readDelegateFromFile(File file, boolean force_initial_discard)
          If you set "create_delegate" to true then you must understand that this results is piece hashes being discarded and then re-read from the torrent file if needed Therefore, if you delete the original torrent file you're going to get errors if you access the pieces after this (and they've been discarded)
static TOTorrent readFromBEncodedInputStream(InputStream is)
           
static TOTorrent readFromFile(File file, boolean create_delegate)
           
static TOTorrent readFromFile(File file, boolean create_delegate, boolean force_initial_discard)
           
static void recursiveEmptyDirDelete(File f)
          Deletes the given dir and all dirs underneath if empty.
static void recursiveEmptyDirDelete(File f, boolean log_warnings)
          Same as #recursiveEmptyDirDelete(File), except allows disabling of logging of any warnings
static void registerMapFluff(String[] fluff)
          Register keys that are used for heavyweight maps that should be discarded when the torrent is not in use Make sure these keys are only ever used for Map objects!
static List<List<String>> removeAnnounceURLs(List<List<String>> base_urls, List<List<String>> remove_urls, boolean use_prefix_match)
           
static List<List<String>> removeAnnounceURLs2(List<List<String>> base_urls, List<String> remove_urls, boolean use_prefix_match)
           
static void removeCreatedTorrent(TOTorrent torrent)
           
static void removeTorrentAttributeListener(TorrentUtils.torrentAttributeListener listener)
           
static void removeTorrentURLChangeListener(TorrentUtils.TorrentAnnounceURLChangeListener listener)
           
static boolean replaceAnnounceURL(TOTorrent torrent, URL old_url, URL new_url)
           
static void runTorrentDelete(Runnable target)
           
static void setDecentralised(TOTorrent torrent)
           
static void setDHTBackupEnabled(TOTorrent torrent, boolean enabled)
           
static void setDHTBackupRequested(TOTorrent torrent, boolean requested)
           
static void setFlag(TOTorrent torrent, int flag, boolean value)
           
static void setMemoryOnly(TOTorrent torrent, boolean mem_only)
           
static void setNetworkCache(TOTorrent torrent, List<String> networks)
           
static void setObtainedFrom(File file, String str)
           
static void setObtainedFrom(TOTorrent torrent, String str)
           
static void setPeerCache(TOTorrent torrent, Map pc)
           
static void setPeerCacheValid(TOTorrent torrent)
           
static void setPluginMapProperty(TOTorrent torrent, String name, Map value)
           
static void setPluginStringProperty(TOTorrent torrent, String name, String value)
           
static void setPrivate(TOTorrent torrent, boolean _private)
           
static void setResumeDataCompletelyValid(DownloadManagerState download_manager_state)
           
static void setTagCache(TOTorrent torrent, List<String> networks)
           
static void setTLS(Object obj)
           
static void setTLSDescription(String desc)
           
static void setTLSTorrentHash(HashWrapper hash)
           
static void setTorrentDeleted()
           
static boolean shouldDeleteTorrentFileAfterAdd(File f, boolean persistent)
           
static void startTorrentDelete()
           
static void writeToFile(TOTorrent torrent)
           
static void writeToFile(TOTorrent torrent, boolean force_backup)
           
static void writeToFile(TOTorrent torrent, File file)
           
static void writeToFile(TOTorrent torrent, File file, boolean force_backup)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_TORRENT_FILE_SIZE

public static final long MAX_TORRENT_FILE_SIZE
See Also:
Constant Field Values

TORRENT_FLAG_LOW_NOISE

public static final int TORRENT_FLAG_LOW_NOISE
See Also:
Constant Field Values

TORRENT_FLAG_METADATA_TORRENT

public static final int TORRENT_FLAG_METADATA_TORRENT
See Also:
Constant Field Values

TORRENT_AZ_PROP_OBTAINED_FROM

public static final String TORRENT_AZ_PROP_OBTAINED_FROM
See Also:
Constant Field Values

TORRENT_AZ_PROP_INITIAL_LINKAGE

public static final String TORRENT_AZ_PROP_INITIAL_LINKAGE
See Also:
Constant Field Values

TORRENT_AZ_PROP_INITIAL_LINKAGE2

public static final String TORRENT_AZ_PROP_INITIAL_LINKAGE2
See Also:
Constant Field Values
Constructor Detail

TorrentUtils

public TorrentUtils()
Method Detail

readFromFile

public static TOTorrent readFromFile(File file,
                                     boolean create_delegate)
                              throws TOTorrentException
Throws:
TOTorrentException

readDelegateFromFile

public static TorrentUtils.ExtendedTorrent readDelegateFromFile(File file,
                                                                boolean force_initial_discard)
                                                         throws TOTorrentException
If you set "create_delegate" to true then you must understand that this results is piece hashes being discarded and then re-read from the torrent file if needed Therefore, if you delete the original torrent file you're going to get errors if you access the pieces after this (and they've been discarded)

Parameters:
file -
create_delegate -
force_initial_discard - - use to get rid of pieces immediately
Returns:
Throws:
TOTorrentException

readFromFile

public static TOTorrent readFromFile(File file,
                                     boolean create_delegate,
                                     boolean force_initial_discard)
                              throws TOTorrentException
Throws:
TOTorrentException

readFromBEncodedInputStream

public static TOTorrent readFromBEncodedInputStream(InputStream is)
                                             throws TOTorrentException
Throws:
TOTorrentException

cloneTorrent

public static TOTorrent cloneTorrent(TOTorrent torrent)
                              throws TOTorrentException
Throws:
TOTorrentException

setMemoryOnly

public static void setMemoryOnly(TOTorrent torrent,
                                 boolean mem_only)

writeToFile

public static void writeToFile(TOTorrent torrent)
                        throws TOTorrentException
Throws:
TOTorrentException

writeToFile

public static void writeToFile(TOTorrent torrent,
                               boolean force_backup)
                        throws TOTorrentException
Throws:
TOTorrentException

writeToFile

public static void writeToFile(TOTorrent torrent,
                               File file)
                        throws TOTorrentException
Throws:
TOTorrentException

writeToFile

public static void writeToFile(TOTorrent torrent,
                               File file,
                               boolean force_backup)
                        throws TOTorrentException
Throws:
TOTorrentException

getTorrentFileName

public static String getTorrentFileName(TOTorrent torrent)
                                 throws TOTorrentException
Throws:
TOTorrentException

copyToFile

public static void copyToFile(TOTorrent torrent,
                              File file)
                       throws TOTorrentException
Throws:
TOTorrentException

delete

public static void delete(TOTorrent torrent)
                   throws TOTorrentException
Throws:
TOTorrentException

delete

public static void delete(File torrent_file,
                          boolean force_no_recycle)

move

public static boolean move(File from_torrent,
                           File to_torrent)

exceptionToText

public static String exceptionToText(TOTorrentException e)

getUniqueTrackerHosts

public static Set<String> getUniqueTrackerHosts(TOTorrent torrent)

announceGroupsToText

public static String announceGroupsToText(TOTorrent torrent)

announceGroupsToText

public static String announceGroupsToText(List<List<String>> group)

announceTextToGroups

public static List<List<String>> announceTextToGroups(String text)

announceGroupsToList

public static List<List<String>> announceGroupsToList(TOTorrent torrent)

listToAnnounceSets

public static TOTorrentAnnounceURLSet[] listToAnnounceSets(List<List<String>> groups,
                                                           TOTorrent torrent)
This method DOES NOT MODIFY THE TORRENT

Parameters:
groups -
torrent -
Returns:

listToAnnounceGroups

public static void listToAnnounceGroups(List<List<String>> groups,
                                        TOTorrent torrent)

announceGroupsInsertFirst

public static void announceGroupsInsertFirst(TOTorrent torrent,
                                             String first_url)

announceGroupsInsertFirst

public static void announceGroupsInsertFirst(TOTorrent torrent,
                                             URL first_url)

announceGroupsInsertFirst

public static void announceGroupsInsertFirst(TOTorrent torrent,
                                             URL[] first_urls)

announceGroupsInsertLast

public static void announceGroupsInsertLast(TOTorrent torrent,
                                            URL[] first_urls)

announceGroupsSetFirst

public static void announceGroupsSetFirst(TOTorrent torrent,
                                          String first_url)

announceGroupsContainsURL

public static boolean announceGroupsContainsURL(TOTorrent torrent,
                                                String url)

canMergeAnnounceURLs

public static boolean canMergeAnnounceURLs(TOTorrent new_torrent,
                                           TOTorrent dest_torrent)

mergeAnnounceURLs

public static boolean mergeAnnounceURLs(TOTorrent new_torrent,
                                        TOTorrent dest_torrent)

mergeAnnounceURLs

public static List<List<String>> mergeAnnounceURLs(List<List<String>> base_urls,
                                                   List<List<String>> merge_urls)

removeAnnounceURLs

public static List<List<String>> removeAnnounceURLs(List<List<String>> base_urls,
                                                    List<List<String>> remove_urls,
                                                    boolean use_prefix_match)

removeAnnounceURLs2

public static List<List<String>> removeAnnounceURLs2(List<List<String>> base_urls,
                                                     List<String> remove_urls,
                                                     boolean use_prefix_match)

getClone

public static List<List<String>> getClone(List<List<String>> lls)

replaceAnnounceURL

public static boolean replaceAnnounceURL(TOTorrent torrent,
                                         URL old_url,
                                         URL new_url)

setResumeDataCompletelyValid

public static void setResumeDataCompletelyValid(DownloadManagerState download_manager_state)

getLocalisedName

public static String getLocalisedName(TOTorrent torrent)

setTLSTorrentHash

public static void setTLSTorrentHash(HashWrapper hash)

getTLSTorrentHash

public static HashWrapper getTLSTorrentHash()

getTLSTorrent

public static TOTorrent getTLSTorrent()

setTLSDescription

public static void setTLSDescription(String desc)

getTLSDescription

public static String getTLSDescription()

getTLS

public static Object getTLS()
get tls for cloning onto another thread

Returns:

setTLS

public static void setTLS(Object obj)

getDecentralisedEmptyURL

public static URL getDecentralisedEmptyURL()

getDecentralisedURL

public static URL getDecentralisedURL(byte[] hash)

getDecentralisedURL

public static URL getDecentralisedURL(TOTorrent torrent)

setDecentralised

public static void setDecentralised(TOTorrent torrent)

isDecentralised

public static boolean isDecentralised(TOTorrent torrent)

isDecentralised

public static boolean isDecentralised(URL url)

isDecentralised

public static boolean isDecentralised(String host)

isFeaturedContent

public static boolean isFeaturedContent(TOTorrent torrent)

setObtainedFrom

public static void setObtainedFrom(File file,
                                   String str)

setObtainedFrom

public static void setObtainedFrom(TOTorrent torrent,
                                   String str)

getObtainedFrom

public static String getObtainedFrom(TOTorrent torrent)

setNetworkCache

public static void setNetworkCache(TOTorrent torrent,
                                   List<String> networks)

getNetworkCache

public static List<String> getNetworkCache(TOTorrent torrent)

setTagCache

public static void setTagCache(TOTorrent torrent,
                               List<String> networks)

getTagCache

public static List<String> getTagCache(TOTorrent torrent)

setPeerCache

public static void setPeerCache(TOTorrent torrent,
                                Map pc)

setPeerCacheValid

public static void setPeerCacheValid(TOTorrent torrent)

getPeerCache

public static Map getPeerCache(TOTorrent torrent)

setFlag

public static void setFlag(TOTorrent torrent,
                           int flag,
                           boolean value)

getFlag

public static boolean getFlag(TOTorrent torrent,
                              int flag)

getInitialLinkage

public static Map<Integer,File> getInitialLinkage(TOTorrent torrent)

setPluginStringProperty

public static void setPluginStringProperty(TOTorrent torrent,
                                           String name,
                                           String value)

getPluginStringProperty

public static String getPluginStringProperty(TOTorrent torrent,
                                             String name)

setPluginMapProperty

public static void setPluginMapProperty(TOTorrent torrent,
                                        String name,
                                        Map value)

getPluginMapProperty

public static Map getPluginMapProperty(TOTorrent torrent,
                                       String name)

setDHTBackupEnabled

public static void setDHTBackupEnabled(TOTorrent torrent,
                                       boolean enabled)

getDHTBackupEnabled

public static boolean getDHTBackupEnabled(TOTorrent torrent)

isDHTBackupRequested

public static boolean isDHTBackupRequested(TOTorrent torrent)

setDHTBackupRequested

public static void setDHTBackupRequested(TOTorrent torrent,
                                         boolean requested)

isReallyPrivate

public static boolean isReallyPrivate(TOTorrent torrent)

getPrivate

public static boolean getPrivate(TOTorrent torrent)

setPrivate

public static void setPrivate(TOTorrent torrent,
                              boolean _private)

getSkipExtensionsSet

public static Set<String> getSkipExtensionsSet()

getIgnoreSet

public static Set<String> getIgnoreSet()

registerMapFluff

public static void registerMapFluff(String[] fluff)
Register keys that are used for heavyweight maps that should be discarded when the torrent is not in use Make sure these keys are only ever used for Map objects!


copyTorrentFileToSaveDir

public static File copyTorrentFileToSaveDir(File f,
                                            boolean persistent)
                                     throws IOException
Copy a file to the Torrent Save Directory, taking into account all the user config options related to that.

Also makes the directory if it doesn't exist.

Parameters:
f - File to copy
persistent - Whether the torrent is persistent
Returns:
File after it's been copied (may be the same as f)
Throws:
IOException

shouldDeleteTorrentFileAfterAdd

public static boolean shouldDeleteTorrentFileAfterAdd(File f,
                                                      boolean persistent)

getDownloadManager

public static DownloadManager getDownloadManager(HashWrapper hash)
Get the DownloadManager related to a torrent's hashBytes

Parameters:
hashBytes -
Returns:

recursiveEmptyDirDelete

public static void recursiveEmptyDirDelete(File f)
Deletes the given dir and all dirs underneath if empty. Don't delete default save path or completed files directory, however, allow deletion of their empty subdirectories Files defined to be ignored for the sake of torrent creation are automatically deleted For example, by default this includes thumbs.db


recursiveEmptyDirDelete

public static void recursiveEmptyDirDelete(File f,
                                           boolean log_warnings)
Same as #recursiveEmptyDirDelete(File), except allows disabling of logging of any warnings

Parameters:
f - Dir to delete
log_warnings - Whether to log warning

nicePrintTorrentHash

public static String nicePrintTorrentHash(TOTorrent torrent)
A nice string of a Torrent's hash

Parameters:
torrent - Torrent to fromat hash of
Returns:
Hash string in a nice format

nicePrintTorrentHash

public static String nicePrintTorrentHash(TOTorrent torrent,
                                          boolean tight)
A nice string of a Torrent's hash

Parameters:
torrent - Torrent to fromat hash of
tight - No spaces between groups of numbers
Returns:
Hash string in a nice format

isTorrentFile

public static boolean isTorrentFile(String filename)
                             throws FileNotFoundException,
                                    IOException
Runs a file through a series of test to verify if it is a torrent.

Parameters:
filename - File to test
Returns:
true - file is a valid torrent file
Throws:
FileNotFoundException
IOException

addCreatedTorrent

public static void addCreatedTorrent(TOTorrent torrent)

removeCreatedTorrent

public static void removeCreatedTorrent(TOTorrent torrent)

isCreatedTorrent

public static boolean isCreatedTorrent(TOTorrent torrent)

download

public static TOTorrent download(URL url)
                          throws IOException
Throws:
IOException

download

public static TOTorrent download(URL url,
                                 long timeout)
                          throws IOException
Throws:
IOException

addTorrentAttributeListener

public static void addTorrentAttributeListener(TorrentUtils.torrentAttributeListener listener)

removeTorrentAttributeListener

public static void removeTorrentAttributeListener(TorrentUtils.torrentAttributeListener listener)

addTorrentURLChangeListener

public static void addTorrentURLChangeListener(TorrentUtils.TorrentAnnounceURLChangeListener listener)

removeTorrentURLChangeListener

public static void removeTorrentURLChangeListener(TorrentUtils.TorrentAnnounceURLChangeListener listener)

startTorrentDelete

public static void startTorrentDelete()

endTorrentDelete

public static void endTorrentDelete()

runTorrentDelete

public static void runTorrentDelete(Runnable target)

isTorrentDeleting

public static boolean isTorrentDeleting()

setTorrentDeleted

public static void setTorrentDeleted()

getMillisecondsSinceLastTorrentDelete

public static long getMillisecondsSinceLastTorrentDelete()

main

public static void main(String[] args)