Class TorrentUtils
java.lang.Object
com.biglybt.core.util.TorrentUtils
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classprivate static classstatic interfacestatic interfacestatic interfacestatic interfacestatic classprivate static class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static AtomicLongprivate static booleanprivate static final List<byte[]> private static final Set<HashWrapper> private static final AsyncDispatcherprivate static booleanprivate static final intprivate static final Map<String, TorrentUtils.DNSTXTEntry> private static intprivate static final ThreadPool(package private) static final DNSUtils.DNSUtilsIntf(package private) static final Mapstatic final longprivate static final Stringprivate static final Stringprivate static final longprivate static final intprivate static booleanprivate static CopyOnWriteList<TorrentUtils.PotentialTorrentDeletionListener> private static Map<DownloadManager, Integer> private static Map<TorrentUtils.PotentialTorrentDeletionListener, DownloadManager[]> private static final ThreadLocal<Map<String, Object>> private static final CopyOnWriteList<TorrentUtils.torrentAttributeListener> private static final Stringprivate static final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprivate static final Stringprivate static final Stringprivate static final Stringstatic final Stringstatic final Stringprivate static final Stringprivate static final Stringprivate static final Stringstatic final Stringprivate static final Stringprivate static final Stringprivate static final String(package private) static final Map(package private) static final AtomicLong(package private) static longstatic final intstatic final intstatic final int(package private) static final CopyOnWriteList<TorrentUtils.TorrentAnnounceURLChangeListener> (package private) static final HashSetprivate static final booleanprivate static final Pattern -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddCreatedTorrent(TOTorrent torrent) static voidstatic voidstatic voidstatic booleanannounceGroupsContainsURL(TOTorrent torrent, String url) static voidannounceGroupsInsertFirst(TOTorrent torrent, String first_url) static voidannounceGroupsInsertFirst(TOTorrent torrent, URL first_url) static voidannounceGroupsInsertFirst(TOTorrent torrent, URL[] first_urls) static voidannounceGroupsInsertLast(TOTorrent torrent, URL[] first_urls) static voidannounceGroupsSetFirst(TOTorrent torrent, String first_url) announceGroupsToList(TOTorrent torrent) static StringannounceGroupsToText(TOTorrent torrent) static StringannounceGroupsToText(List<List<String>> group) announceTextToGroups(String text) applyAllDNSMods(URL url) private static URLapplyDNSMods(URL url) private static TOTorrentAnnounceURLGroupapplyDNSMods(URL announce_url, TOTorrentAnnounceURLGroup group) static booleanstatic booleancanMergeAnnounceURLs(TOTorrent new_torrent, TOTorrent dest_torrent) private static voidstatic voidclearTorrentFileName(TOTorrent torrent) static TOTorrentcloneTorrent(TOTorrent torrent) static voidcopyToFile(TOTorrent torrent, File file) static FilecopyTorrentFileToSaveDir(File f, boolean persistent) Copy a file to the Torrent Save Directory, taking into account all the user config options related to that.static voidstatic voidstatic TOTorrentstatic TOTorrentstatic voidendTorrentDelete(DownloadManager[] dms) static StringexpandTrackerLists(List<List<String>> groups) private static voidfireAttributeListener(TOTorrent torrent, String attribute, Object value) static longprivate static MapgetAzureusPrivateProperties(TOTorrent torrent) private static MapgetAzureusProperties(TOTorrent torrent) private static StringgetContentMapString(TOTorrent torrent, String key) static URLstatic URLgetDecentralisedURL(byte[] hash) static URLgetDecentralisedURL(TOTorrent torrent) static booleangetDHTBackupEnabled(TOTorrent torrent) static StringgetDisplayName(TOTorrent torrent) private static TorrentUtils.DNSTXTEntrygetDNSTXTEntry(String host, boolean force_update, List<String> already_got_records) static TorrentUtils.DNSTXTEntrygetDNSTXTEntry(URL url) static DownloadManagerGet the DownloadManager related to a torrent's hashBytesstatic booleanstatic booleanstatic byte[]getHashForDisplay(TOTorrent torrent) static MapgetHashTreeState(TOTorrent torrent) getIgnoreSetSupport(boolean force) getInitialLinkage(TOTorrent torrent) getInitialMetadata(DownloadManager dm, boolean include_dn) getInitialMetadata(TOTorrent torrent) getInitialTags(TOTorrent torrent) static StringgetLocalisedName(TOTorrent torrent) getMergedTrackers(DownloadManager[] dms) getMergedTrackers(List<TOTorrent> torrents) getMergedTrackersFromGroups(List<List<List<String>>> all_trackers) static longgetNetworkCache(TOTorrent torrent) static StringgetObtainedFrom(TOTorrent torrent) static byte[]getOriginalHash(TOTorrent torrent) static MapgetPeerCache(TOTorrent torrent) static MapgetPluginMapProperty(TOTorrent torrent, String name) static StringgetPluginStringProperty(TOTorrent torrent, String name) static booleangetPrivate(TOTorrent torrent) getSkipExtensionsSetSupport(boolean force) static boolean[]getSkipFiles(TOTorrent torrent) getSkipFileSetSupport(boolean force) getTagCache(TOTorrent torrent) static ObjectgetTLS()get tls for cloning onto another threadstatic Stringstatic TOTorrentstatic HashWrapperstatic StringgetTorrentFileName(TOTorrent torrent) static StringgetTorrentFileName(TOTorrent torrent, boolean is_mandatory) getUniqueTrackerHosts(TOTorrent torrent) getUniqueTrackerHosts(TOTorrent torrent, boolean include_port) static MapgetV2RootHashCache(TOTorrent torrent) static booleanisCreatedTorrent(TOTorrent torrent) static booleanisDecentralised(TOTorrent torrent) static booleanisDecentralised(String host) static booleanisDecentralised(URL url) static booleanisDHTBackupRequested(TOTorrent torrent) static booleanisFeaturedContent(TOTorrent torrent) static booleanisReallyPrivate(TOTorrent torrent) static booleanstatic booleanisTorrentFile(String filename) Runs a file through a series of test to verify if it is a torrent.static booleanisTrackerAddress(TOTorrent torrent, InetSocketAddress isa) static voidlistToAnnounceGroups(List<List<String>> groups, TOTorrent torrent) static TOTorrentAnnounceURLSet[]listToAnnounceSets(List<List<String>> groups, TOTorrent torrent) This method DOES NOT MODIFY THE TORRENTstatic voidstatic booleanmergeAnnounceURLs(TOTorrent new_torrent, TOTorrent dest_torrent) static booleanstatic StringnicePrintTorrentHash(TOTorrent torrent) A nice string of a Torrent's hashstatic StringnicePrintTorrentHash(TOTorrent torrent, boolean tight) A nice string of a Torrent's hashstatic booleanpropagateExportability(TOTorrent source, File dest) static TorrentUtils.ExtendedTorrentreadDelegateFromFile(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 TOTorrentstatic TOTorrentreadFromFile(File file, boolean create_delegate) static TOTorrentreadFromFile(File file, boolean create_delegate, boolean force_initial_discard) static voidDeletes the given dir and all dirs underneath if empty.static voidrecursiveEmptyDirDelete(File f, boolean log_warnings) Same as #recursiveEmptyDirDelete(File), except allows disabling of logging of any warningsstatic voidregisterMapFluff(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!removeAnnounceURLs(List<List<String>> base_urls, List<List<String>> remove_urls, boolean use_prefix_match) removeAnnounceURLs2(List<List<String>> base_urls, List<String> remove_urls, boolean use_prefix_match) static voidremoveCreatedTorrent(TOTorrent torrent) static voidstatic voidstatic voidstatic booleanreplaceAnnounceURL(TOTorrent torrent, URL old_url, URL new_url) static voidrunTorrentDelete(DownloadManager[] dms, Runnable target) static voidsetDecentralised(TOTorrent torrent) static voidsetDHTBackupEnabled(TOTorrent torrent, boolean enabled) static voidsetDHTBackupRequested(TOTorrent torrent, boolean requested) static voidsetDisplayName(TOTorrent torrent, String str) static voidstatic voidsetHashTreeState(TOTorrent torrent, Map state) static voidsetInitialMetadata(DownloadManager dm, Map<String, Object> metadata, boolean include_dn) static voidsetInitialMetadata(TOTorrent torrent, Map<String, Object> metadata) static voidsetInitialTags(TOTorrent torrent, List<String> tags) static voidsetMemoryOnly(TOTorrent torrent, boolean mem_only) static voidsetNetworkCache(TOTorrent torrent, List<String> networks) static voidsetObtainedFrom(TOTorrent torrent, String str) static voidsetObtainedFrom(File file, String str) static voidsetOriginalHash(TOTorrent torrent, byte[] hash) static voidsetPeerCache(TOTorrent torrent, Map pc) static voidsetPeerCacheValid(TOTorrent torrent) static voidsetPluginMapProperty(TOTorrent torrent, String name, Map value) static voidsetPluginStringProperty(TOTorrent torrent, String name, String value) static voidsetPrivate(TOTorrent torrent, boolean _private) static voidsetResumeDataCompletelyValid(DownloadManagerState download_manager_state) static voidsetResumeDataTotallyIncomplete(DownloadManagerState download_manager_state) static voidsetTagCache(TOTorrent torrent, List<String> tags) static voidstatic voidsetTLSDescription(String desc) static voidsetTLSTorrentHash(HashWrapper hash) static voidstatic voidsetV2RootHashCache(TOTorrent torrent, Map cache) static booleanshouldDeleteTorrentFileAfterAdd(File f, boolean persistent) static voidstatic voidDisables DNS Handling, but doesn't save it to the configstatic voidwriteToFile(TOTorrent torrent) static voidwriteToFile(TOTorrent torrent, boolean force_backup) static voidwriteToFile(TOTorrent torrent, File file, boolean force_backup)
-
Field Details
-
MAX_TORRENT_FILE_SIZE
public static final long MAX_TORRENT_FILE_SIZE- See Also:
-
NO_VALID_URL_URL
- See Also:
-
TORRENT_FLAG_LOW_NOISE
public static final int TORRENT_FLAG_LOW_NOISE- See Also:
-
TORRENT_FLAG_METADATA_TORRENT
public static final int TORRENT_FLAG_METADATA_TORRENT- See Also:
-
TORRENT_FLAG_DISABLE_RCM
public static final int TORRENT_FLAG_DISABLE_RCM- See Also:
-
TORRENT_AZ_PROP_DHT_BACKUP_ENABLE
- See Also:
-
TORRENT_AZ_PROP_DHT_BACKUP_REQUESTED
- See Also:
-
TORRENT_AZ_PROP_TORRENT_FLAGS
- See Also:
-
TORRENT_AZ_PROP_PLUGINS
- See Also:
-
TORRENT_AZ_PROP_OBTAINED_FROM
- See Also:
-
TORRENT_AZ_PROP_DISPLAY_NAME
- See Also:
-
TORRENT_AZ_PROP_NETWORK_CACHE
- See Also:
-
TORRENT_AZ_PROP_TAG_CACHE
- See Also:
-
TORRENT_AZ_PROP_INITIAL_TAGS
- See Also:
-
TORRENT_AZ_PROP_INITIAL_METADATA
- See Also:
-
TORRENT_AZ_PROP_PEER_CACHE
- See Also:
-
TORRENT_AZ_PROP_PEER_CACHE_VALID
- See Also:
-
TORRENT_AZ_PROP_INITIAL_LINKAGE
- See Also:
-
TORRENT_AZ_PROP_INITIAL_LINKAGE2
- See Also:
-
TORRENT_AZ_PROP_ORIGINAL_HASH
- See Also:
-
TORRENT_AZ_PROP_HASHTREE_STATE
- See Also:
-
TORRENT_AZ_PROP_HYBRID_HASH_V2
- See Also:
-
TORRENT_AZ_PROP_V2_ROOT_HASH_CACHE
- See Also:
-
TORRENT_AZ_PROP_SIMPLE_TORRENT_DISABLED
- See Also:
-
MEM_ONLY_TORRENT_PATH
- See Also:
-
PC_MARKER
private static final long PC_MARKER -
created_torrents
-
created_torrents_set
-
tls
-
ignore_files_set
-
skip_extensions_set
-
skip_file_set
-
bSaveTorrentBackup
private static boolean bSaveTorrentBackup -
torrent_attribute_listeners
private static final CopyOnWriteList<TorrentUtils.torrentAttributeListener> torrent_attribute_listeners -
torrent_url_changed_listeners
static final CopyOnWriteList<TorrentUtils.TorrentAnnounceURLChangeListener> torrent_url_changed_listeners -
dispatcher
-
DNS_HANDLING_ENABLE
private static boolean DNS_HANDLING_ENABLE -
TRACE_DNS
private static final boolean TRACE_DNS- See Also:
-
DNS_HISTORY_TIMEOUT
private static final int DNS_HISTORY_TIMEOUT- See Also:
-
dns_mapping
-
dns_mapping_seq_count
private static volatile int dns_mapping_seq_count -
dns_threads
-
dns_utils
-
priority_file_exts
-
priority_file_exts_ignore_case
private static volatile boolean priority_file_exts_ignore_case -
torrent_delete_level
-
torrent_delete_time
static long torrent_delete_time -
announce_group_uid_next
-
PIECE_HASH_TIMEOUT
private static final int PIECE_HASH_TIMEOUT- See Also:
-
torrent_delegates
-
torrentFluffKeyset
-
fluffThombstone
-
txt_pattern
-
ptd_listeners
-
ptd_map
-
ptdl_last
-
tracker_hosts
-
tracker_addresses
-
-
Constructor Details
-
TorrentUtils
public TorrentUtils()
-
-
Method Details
-
getAnnounceGroupUID
public static long getAnnounceGroupUID() -
readFromFile
- 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-force_initial_discard- - use to get rid of pieces immediatelycreate_delegate-- Returns:
- Throws:
TOTorrentException
-
readFromFile
public static TOTorrent readFromFile(File file, boolean create_delegate, boolean force_initial_discard) throws TOTorrentException - Throws:
TOTorrentException
-
readFromBEncodedInputStream
- Throws:
TOTorrentException
-
cloneTorrent
- Throws:
TOTorrentException
-
setMemoryOnly
-
writeToFile
- Throws:
TOTorrentException
-
writeToFile
- Throws:
TOTorrentException
-
writeToFile
public static void writeToFile(TOTorrent torrent, File file, boolean force_backup) throws TOTorrentException - Throws:
TOTorrentException
-
getTorrentFileName
- Throws:
TOTorrentException
-
getTorrentFileName
public static String getTorrentFileName(TOTorrent torrent, boolean is_mandatory) throws TOTorrentException - Throws:
TOTorrentException
-
clearTorrentFileName
-
copyToFile
- Throws:
TOTorrentException
-
delete
- Throws:
TOTorrentException
-
delete
-
move
-
exceptionToText
-
getUniqueTrackerHosts
-
getUniqueTrackerHosts
-
announceGroupsToText
-
announceGroupsToText
-
announceTextToGroups
-
announceGroupsToList
-
expandTrackerLists
-
getMergedTrackers
-
getMergedTrackers
-
getMergedTrackersFromGroups
-
listToAnnounceSets
public static TOTorrentAnnounceURLSet[] listToAnnounceSets(List<List<String>> groups, TOTorrent torrent) This method DOES NOT MODIFY THE TORRENT- Parameters:
groups-torrent-- Returns:
-
listToAnnounceGroups
-
announceGroupsInsertFirst
-
announceGroupsInsertFirst
-
announceGroupsInsertFirst
-
announceGroupsInsertLast
-
announceGroupsSetFirst
-
announceGroupsContainsURL
-
canMergeAnnounceURLs
-
mergeAnnounceURLs
-
mergeAnnounceURLs
-
removeAnnounceURLs
-
removeAnnounceURLs2
-
getClone
-
areIdentical
-
replaceAnnounceURL
-
setResumeDataTotallyIncomplete
-
setResumeDataCompletelyValid
-
getLocalisedName
-
setTLSTorrentHash
-
getTLSTorrentHash
-
getTLSTorrent
-
setTLSDescription
-
getTLSDescription
-
getTLS
-
setTLS
-
getDecentralisedEmptyURL
-
getDecentralisedURL
-
getDecentralisedURL
-
setDecentralised
-
isDecentralised
-
isDecentralised
-
isDecentralised
-
getAzureusProperties
-
getAzureusPrivateProperties
-
getContentMapString
-
isFeaturedContent
-
setObtainedFrom
-
setObtainedFrom
-
getObtainedFrom
-
setDisplayName
-
getDisplayName
-
setNetworkCache
-
getNetworkCache
-
setTagCache
-
getTagCache
-
setInitialTags
-
getInitialTags
-
setInitialMetadata
-
getInitialMetadata
-
getInitialMetadata
-
setInitialMetadata
public static void setInitialMetadata(DownloadManager dm, Map<String, Object> metadata, boolean include_dn) -
setOriginalHash
-
getOriginalHash
-
setHashTreeState
-
getHashTreeState
-
setV2RootHashCache
-
getV2RootHashCache
-
getHashForDisplay
-
setPeerCache
-
setPeerCacheValid
-
getPeerCache
-
setFlag
-
getFlag
-
getInitialLinkage
-
setPluginStringProperty
-
getPluginStringProperty
-
setPluginMapProperty
-
getPluginMapProperty
-
setDHTBackupEnabled
-
getDHTBackupEnabled
-
isDHTBackupRequested
-
setDHTBackupRequested
-
isReallyPrivate
-
getPrivate
-
setPrivate
-
getSkipExtensionsSet
-
getSkipExtensionsSetSupport
-
getSkipFileSet
-
getSkipFileSetSupport
-
getSkipFiles
- Parameters:
torrent-- Returns:
- null if no files skipped otherwise entry for each file in torrent
-
getIgnoreSet
-
getIgnoreSetSupport
-
registerMapFluff
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
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 copypersistent- Whether the torrent is persistent- Returns:
- File after it's been copied (may be the same as f)
- Throws:
IOException
-
shouldDeleteTorrentFileAfterAdd
-
getDownloadManager
Get the DownloadManager related to a torrent's hashBytes- Parameters:
hashBytes-- Returns:
-
recursiveEmptyDirDelete
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
Same as #recursiveEmptyDirDelete(File), except allows disabling of logging of any warnings- Parameters:
f- Dir to deletelog_warnings- Whether to log warning
-
nicePrintTorrentHash
-
nicePrintTorrentHash
-
isTorrentFile
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:
FileNotFoundExceptionIOException
-
addCreatedTorrent
-
removeCreatedTorrent
-
isCreatedTorrent
-
download
- Throws:
IOException
-
download
- Throws:
IOException
-
fireAttributeListener
-
addTorrentAttributeListener
-
removeTorrentAttributeListener
-
addTorrentURLChangeListener
public static void addTorrentURLChangeListener(TorrentUtils.TorrentAnnounceURLChangeListener listener) -
removeTorrentURLChangeListener
public static void removeTorrentURLChangeListener(TorrentUtils.TorrentAnnounceURLChangeListener listener) -
getDNSTXTEntry
-
checkDNSTimeouts
private static void checkDNSTimeouts() -
getDNSTXTEntry
private static TorrentUtils.DNSTXTEntry getDNSTXTEntry(String host, boolean force_update, List<String> already_got_records) -
applyDNSMods
-
applyAllDNSMods
-
applyDNSMods
private static TOTorrentAnnounceURLGroup applyDNSMods(URL announce_url, TOTorrentAnnounceURLGroup group) -
startTorrentDelete
-
endTorrentDelete
-
runTorrentDelete
-
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
-
temporarilyDisableDNSHandling
public static void temporarilyDisableDNSHandling()Disables DNS Handling, but doesn't save it to the config -
isTrackerAddress
-
getFilePriorityExtensions
-
getFilePriorityExtensionsIgnoreCase
public static boolean getFilePriorityExtensionsIgnoreCase() -
main
-