Class TorrentUtils

java.lang.Object
com.biglybt.core.util.TorrentUtils

public class TorrentUtils extends Object
  • Field Details

  • Constructor Details

    • TorrentUtils

      public TorrentUtils()
  • Method Details

    • getAnnounceGroupUID

      public static long getAnnounceGroupUID()
    • 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, boolean force_backup) throws TOTorrentException
      Throws:
      TOTorrentException
    • getTorrentFileName

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

      public static String getTorrentFileName(TOTorrent torrent, boolean is_mandatory) throws TOTorrentException
      Throws:
      TOTorrentException
    • clearTorrentFileName

      public static void clearTorrentFileName(TOTorrent torrent)
    • 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)
    • getUniqueTrackerHosts

      public static Set<String> getUniqueTrackerHosts(TOTorrent torrent, boolean include_port)
    • 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)
    • expandTrackerLists

      private static List<List<String>> expandTrackerLists(List<List<String>> groups)
    • getMergedTrackers

      public static List<List<String>> getMergedTrackers(DownloadManager[] dms)
    • getMergedTrackers

      public static List<List<String>> getMergedTrackers(List<TOTorrent> torrents)
    • getMergedTrackersFromGroups

      public static List<List<String>> getMergedTrackersFromGroups(List<List<List<String>>> all_trackers)
    • 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)
    • areIdentical

      public static boolean areIdentical(List<List<String>> ll1, List<List<String>> ll2)
    • replaceAnnounceURL

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

      public static void setResumeDataTotallyIncomplete(DownloadManagerState download_manager_state)
    • 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)
    • getAzureusProperties

      private static Map getAzureusProperties(TOTorrent torrent)
    • getAzureusPrivateProperties

      private static Map getAzureusPrivateProperties(TOTorrent torrent)
    • getContentMapString

      private static String getContentMapString(TOTorrent torrent, String key)
    • 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)
    • setDisplayName

      public static void setDisplayName(TOTorrent torrent, String str)
    • getDisplayName

      public static String getDisplayName(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> tags)
    • getTagCache

      public static List<String> getTagCache(TOTorrent torrent)
    • setInitialTags

      public static void setInitialTags(TOTorrent torrent, List<String> tags)
    • getInitialTags

      public static List<String> getInitialTags(TOTorrent torrent)
    • setInitialMetadata

      public static void setInitialMetadata(TOTorrent torrent, Map<String,Object> metadata)
    • getInitialMetadata

      public static Map<String,Object> getInitialMetadata(TOTorrent torrent)
    • getInitialMetadata

      public static Map<String,Object> getInitialMetadata(DownloadManager dm, boolean include_dn)
    • setInitialMetadata

      public static void setInitialMetadata(DownloadManager dm, Map<String,Object> metadata, boolean include_dn)
    • setOriginalHash

      public static void setOriginalHash(TOTorrent torrent, byte[] hash)
    • getOriginalHash

      public static byte[] getOriginalHash(TOTorrent torrent)
    • setHashTreeState

      public static void setHashTreeState(TOTorrent torrent, Map state)
    • getHashTreeState

      public static Map getHashTreeState(TOTorrent torrent)
    • setV2RootHashCache

      public static void setV2RootHashCache(TOTorrent torrent, Map cache)
    • getV2RootHashCache

      public static Map getV2RootHashCache(TOTorrent torrent)
    • getHashForDisplay

      public static byte[] getHashForDisplay(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()
    • getSkipExtensionsSetSupport

      private static Set<String> getSkipExtensionsSetSupport(boolean force)
    • getSkipFileSet

      public static Set<Object> getSkipFileSet()
    • getSkipFileSetSupport

      private static Set<Object> getSkipFileSetSupport(boolean force)
    • getSkipFiles

      public static boolean[] getSkipFiles(TOTorrent torrent)
      Parameters:
      torrent -
      Returns:
      null if no files skipped otherwise entry for each file in torrent
    • getIgnoreSet

      public static Set<String> getIgnoreSet()
    • getIgnoreSetSupport

      private static Set<String> getIgnoreSetSupport(boolean force)
    • 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 format 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 format 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
    • fireAttributeListener

      private static void fireAttributeListener(TOTorrent torrent, String attribute, Object value)
    • 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)
    • getDNSTXTEntry

      public static TorrentUtils.DNSTXTEntry getDNSTXTEntry(URL url)
    • checkDNSTimeouts

      private static void checkDNSTimeouts()
    • getDNSTXTEntry

      private static TorrentUtils.DNSTXTEntry getDNSTXTEntry(String host, boolean force_update, List<String> already_got_records)
    • applyDNSMods

      private static URL applyDNSMods(URL url)
    • applyAllDNSMods

      private static List<URL> applyAllDNSMods(URL url)
    • applyDNSMods

      private static TOTorrentAnnounceURLGroup applyDNSMods(URL announce_url, TOTorrentAnnounceURLGroup group)
    • startTorrentDelete

      public static void startTorrentDelete(DownloadManager[] dms)
    • endTorrentDelete

      public static void endTorrentDelete(DownloadManager[] dms)
    • runTorrentDelete

      public static void runTorrentDelete(DownloadManager[] dms, Runnable target)
    • addPotentialTorrentDeletionListener

      public static void addPotentialTorrentDeletionListener(TorrentUtils.PotentialTorrentDeletionListener l)
    • removePotentialTorrentDeletionListener

      public static void removePotentialTorrentDeletionListener(TorrentUtils.PotentialTorrentDeletionListener l)
    • isTorrentDeleting

      public static boolean isTorrentDeleting()
    • setTorrentDeleted

      public static void setTorrentDeleted()
    • getMillisecondsSinceLastTorrentDelete

      public static long getMillisecondsSinceLastTorrentDelete()
    • propagateExportability

      public static boolean propagateExportability(TOTorrent source, File dest)
    • temporarilyDisableDNSHandling

      public static void temporarilyDisableDNSHandling()
      Disables DNS Handling, but doesn't save it to the config
    • isTrackerAddress

      public static boolean isTrackerAddress(TOTorrent torrent, InetSocketAddress isa)
    • getFilePriorityExtensions

      public static Set<String> getFilePriorityExtensions()
    • getFilePriorityExtensionsIgnoreCase

      public static boolean getFilePriorityExtensionsIgnoreCase()
    • main

      public static void main(String[] args)