org.gudy.azureus2.core3.torrent.impl
Class TOTorrentImpl

java.lang.Object
  extended by org.gudy.azureus2.core3.logging.LogRelation
      extended by org.gudy.azureus2.core3.torrent.impl.TOTorrentImpl
All Implemented Interfaces:
TOTorrent
Direct Known Subclasses:
TOTorrentCreateImpl, TOTorrentDeserialiseImpl

public class TOTorrentImpl
extends LogRelation
implements TOTorrent


Field Summary
protected  AEMonitor this_mon
           
protected static List TK_ADDITIONAL_OK_ATTRS
           
protected static String TK_ANNOUNCE
           
protected static String TK_ANNOUNCE_LIST
           
protected static String TK_COMMENT
           
protected static String TK_COMMENT_UTF8
           
protected static String TK_CREATED_BY
           
protected static String TK_CREATION_DATE
           
protected static String TK_FILES
           
protected static String TK_HASH_OVERRIDE
           
protected static String TK_INFO
           
protected static String TK_LENGTH
           
protected static String TK_NAME
           
protected static String TK_NAME_UTF8
           
protected static String TK_PATH
           
protected static String TK_PATH_UTF8
           
protected static String TK_PIECE_LENGTH
           
protected static String TK_PIECES
           
protected static String TK_PRIVATE
           
protected static String TK_WEBSEED_BT
           
protected static String TK_WEBSEED_GR
           
 
Fields inherited from interface org.gudy.azureus2.core3.torrent.TOTorrent
AZUREUS_PRIVATE_PROPERTIES, AZUREUS_PROPERTIES, DEFAULT_IGNORE_FILES, ENCODING_ACTUALLY_UTF8_KEYS
 
Constructor Summary
protected TOTorrentImpl()
          Constructor for deserialisation
protected TOTorrentImpl(String _torrent_name, URL _announce_url, boolean _simple_torrent)
          Constructor for creation
 
Method Summary
protected  void addAdditionalInfoProperty(String name, Object value)
           
protected  void addAdditionalProperty(String name, Object value)
           
 void addListener(TOTorrentListener l)
           
protected  void addTorrentAnnounceURLSet(URL[] urls)
           
protected  URL anonymityTransform(URL url)
           
protected  void fireChanged(int type)
           
 byte[] getAdditionalByteArrayProperty(String name)
           
protected  Map getAdditionalInfoProperties()
           
 List getAdditionalListProperty(String name)
           
 Long getAdditionalLongProperty(String name)
           
 Map getAdditionalMapProperty(String name)
           
protected  Map getAdditionalProperties()
           
 Object getAdditionalProperty(String name)
           
 String getAdditionalStringProperty(String name)
           
 URL getAnnounceURL()
          A torrent must have a URL that identifies the tracker.
 TOTorrentAnnounceURLGroup getAnnounceURLGroup()
          When a group of sets of trackers is defined their URLs are accessed via this method
 byte[] getComment()
          Comment is an optional torrent property
 byte[] getCreatedBy()
           
 long getCreationDate()
          Gets the creation date of the torrent.
 int getFileCount()
           
 TOTorrentFile[] getFiles()
          A torrent consists of one or more files.
 byte[] getHash()
          A torrent has a unique SHA1 (20 byte) hash that is computed from some of its contents.
protected  byte[] getHashOverride()
           
 HashWrapper getHashWrapper()
          convenience method to get a wrapped hash for performance purposes
 AEMonitor getMonitor()
           
 byte[] getName()
          Get the name of the torrent
 int getNumberOfPieces()
           
 long getPieceLength()
          Returns the piece length used for the torrent
 byte[][] getPieces()
           
 boolean getPrivate()
           
 Object[] getQueryableInterfaces()
          Query this class for a reference to another class that it may hold
 String getRelationText()
          A short description of what your class holds that can be printed by the logger
protected  boolean getSimpleTorrent()
           
 long getSize()
           
 String getUTF8Name()
          Retrieves the utf8 name of the torrent ONLY if the torrent specified one in it's info map.
 boolean hasSameHashAs(TOTorrent other)
          compares two torrents by hash
 boolean isCreated()
           
 boolean isDecentralised()
          This method provides access to the SHA1 hash values (20 bytes each) that correspond to the pieces of the torrent.
 boolean isSimpleTorrent()
          A "simple torrent" is one that consists of a single file on its own (i.e.
 void print()
          A diagnostic method for dumping the tracker contents to "stdout"
protected  String readStringFromMetaData(byte[] value)
           
protected  String readStringFromMetaData(Map meta_data, String name)
           
 void removeAdditionalProperties()
          remove all additional properties to clear out the torrent
 void removeAdditionalProperty(String name)
           
 void removeListener(TOTorrentListener l)
           
 void serialiseToBEncodedFile(File output_file)
          This method will serialise a torrent using the standard "b-encoding" mechanism into a file
protected  byte[] serialiseToByteArray()
           
 Map serialiseToMap()
          This method will serialise a torrent into a Map consistent with that used by the "b-encoding" routines defined elsewhere
 void serialiseToXMLFile(File file)
          This method will serialise a torrent using an XML encoding to a file
 void setAdditionalByteArrayProperty(String name, byte[] value)
           
 void setAdditionalListProperty(String name, List value)
           
 void setAdditionalLongProperty(String name, Long value)
           
 void setAdditionalMapProperty(String name, Map value)
           
 void setAdditionalProperty(String name, Object value)
          set an arbitrary property.
 void setAdditionalStringProperty(String name, String value)
          The additional properties are used for holding non-core data for Azureus' own user
 boolean setAnnounceURL(URL url)
           
protected  void setComment(byte[] _comment)
           
 void setComment(String _comment)
           
 void setCreatedBy(byte[] _created_by)
           
protected  void setCreatedBy(String _created_by)
           
 void setCreationDate(long _creation_date)
           
protected  void setFiles(TOTorrentFileImpl[] _files)
           
protected  void setHashFromInfo(Map info)
           
 void setHashOverride(byte[] hash)
          Only supported for decentralised torrents, allows an alternative hash to be used for them in the DHT
protected  void setName(byte[] _name)
           
protected  void setNameUTF8(byte[] _name)
           
protected  void setPieceLength(long _length)
           
 void setPieces(byte[][] _pieces)
          This method exists to support the temporary discarding of piece hashes to conserver memory.
 void setPrivate(boolean _private_torrent)
          Note - changing the private attribute CHANGES THE TORRENT HASH
protected  void setSimpleTorrent(boolean _simple_torrent)
           
protected  void writeStringToMetaData(Map meta_data, String name, String value)
           
protected  byte[] writeStringToMetaData(String value)
           
 
Methods inherited from class org.gudy.azureus2.core3.logging.LogRelation
propogatedRelationText, queryForClass, queryForClass
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TK_ANNOUNCE

protected static final String TK_ANNOUNCE
See Also:
Constant Field Values

TK_ANNOUNCE_LIST

protected static final String TK_ANNOUNCE_LIST
See Also:
Constant Field Values

TK_COMMENT

protected static final String TK_COMMENT
See Also:
Constant Field Values

TK_CREATION_DATE

protected static final String TK_CREATION_DATE
See Also:
Constant Field Values

TK_CREATED_BY

protected static final String TK_CREATED_BY
See Also:
Constant Field Values

TK_INFO

protected static final String TK_INFO
See Also:
Constant Field Values

TK_NAME

protected static final String TK_NAME
See Also:
Constant Field Values

TK_LENGTH

protected static final String TK_LENGTH
See Also:
Constant Field Values

TK_PATH

protected static final String TK_PATH
See Also:
Constant Field Values

TK_FILES

protected static final String TK_FILES
See Also:
Constant Field Values

TK_PIECE_LENGTH

protected static final String TK_PIECE_LENGTH
See Also:
Constant Field Values

TK_PIECES

protected static final String TK_PIECES
See Also:
Constant Field Values

TK_PRIVATE

protected static final String TK_PRIVATE
See Also:
Constant Field Values

TK_NAME_UTF8

protected static final String TK_NAME_UTF8
See Also:
Constant Field Values

TK_PATH_UTF8

protected static final String TK_PATH_UTF8
See Also:
Constant Field Values

TK_COMMENT_UTF8

protected static final String TK_COMMENT_UTF8
See Also:
Constant Field Values

TK_WEBSEED_BT

protected static final String TK_WEBSEED_BT
See Also:
Constant Field Values

TK_WEBSEED_GR

protected static final String TK_WEBSEED_GR
See Also:
Constant Field Values

TK_HASH_OVERRIDE

protected static final String TK_HASH_OVERRIDE
See Also:
Constant Field Values

TK_ADDITIONAL_OK_ATTRS

protected static final List TK_ADDITIONAL_OK_ATTRS

this_mon

protected AEMonitor this_mon
Constructor Detail

TOTorrentImpl

protected TOTorrentImpl()
Constructor for deserialisation


TOTorrentImpl

protected TOTorrentImpl(String _torrent_name,
                        URL _announce_url,
                        boolean _simple_torrent)
                 throws TOTorrentException
Constructor for creation

Throws:
TOTorrentException
Method Detail

serialiseToBEncodedFile

public void serialiseToBEncodedFile(File output_file)
                             throws TOTorrentException
Description copied from interface: TOTorrent
This method will serialise a torrent using the standard "b-encoding" mechanism into a file

Specified by:
serialiseToBEncodedFile in interface TOTorrent
Throws:
TOTorrentException

serialiseToByteArray

protected byte[] serialiseToByteArray()
                               throws TOTorrentException
Throws:
TOTorrentException

serialiseToMap

public Map serialiseToMap()
                   throws TOTorrentException
Description copied from interface: TOTorrent
This method will serialise a torrent into a Map consistent with that used by the "b-encoding" routines defined elsewhere

Specified by:
serialiseToMap in interface TOTorrent
Returns:
Throws:
TOTorrentException

serialiseToXMLFile

public void serialiseToXMLFile(File file)
                        throws TOTorrentException
Description copied from interface: TOTorrent
This method will serialise a torrent using an XML encoding to a file

Specified by:
serialiseToXMLFile in interface TOTorrent
Throws:
TOTorrentException

getName

public byte[] getName()
Description copied from interface: TOTorrent
Get the name of the torrent

Specified by:
getName in interface TOTorrent
Returns:

setName

protected void setName(byte[] _name)

getUTF8Name

public String getUTF8Name()
Description copied from interface: TOTorrent
Retrieves the utf8 name of the torrent ONLY if the torrent specified one in it's info map. Otherwise, returns null (you'll have to use getName() and decode it yourself)

Specified by:
getUTF8Name in interface TOTorrent

setNameUTF8

protected void setNameUTF8(byte[] _name)

isSimpleTorrent

public boolean isSimpleTorrent()
Description copied from interface: TOTorrent
A "simple torrent" is one that consists of a single file on its own (i.e. not in a nested directory).

Specified by:
isSimpleTorrent in interface TOTorrent
Returns:

getComment

public byte[] getComment()
Description copied from interface: TOTorrent
Comment is an optional torrent property

Specified by:
getComment in interface TOTorrent
Returns:

setComment

protected void setComment(byte[] _comment)

setComment

public void setComment(String _comment)
Specified by:
setComment in interface TOTorrent

getAnnounceURL

public URL getAnnounceURL()
Description copied from interface: TOTorrent
A torrent must have a URL that identifies the tracker. This method returns it. However an extension to this exists to allow multiple trackers, and their backups, to be defined. See below

Specified by:
getAnnounceURL in interface TOTorrent
Returns:

setAnnounceURL

public boolean setAnnounceURL(URL url)
Specified by:
setAnnounceURL in interface TOTorrent
Returns:
true-changed; false-not changed

isDecentralised

public boolean isDecentralised()
Description copied from interface: TOTorrent
This method provides access to the SHA1 hash values (20 bytes each) that correspond to the pieces of the torrent.

Specified by:
isDecentralised in interface TOTorrent
Returns:

getCreationDate

public long getCreationDate()
Description copied from interface: TOTorrent
Gets the creation date of the torrent. Optional property, 0 returned if not set

Specified by:
getCreationDate in interface TOTorrent
Returns:

setCreationDate

public void setCreationDate(long _creation_date)
Specified by:
setCreationDate in interface TOTorrent

setCreatedBy

public void setCreatedBy(byte[] _created_by)
Specified by:
setCreatedBy in interface TOTorrent

setCreatedBy

protected void setCreatedBy(String _created_by)

getCreatedBy

public byte[] getCreatedBy()
Specified by:
getCreatedBy in interface TOTorrent

isCreated

public boolean isCreated()
Specified by:
isCreated in interface TOTorrent

getHash

public byte[] getHash()
               throws TOTorrentException
Description copied from interface: TOTorrent
A torrent has a unique SHA1 (20 byte) hash that is computed from some of its contents. It is used, for example, when contacting a tracker to identify the torrent.

Specified by:
getHash in interface TOTorrent
Returns:
Throws:
TOTorrentException

getHashWrapper

public HashWrapper getHashWrapper()
                           throws TOTorrentException
Description copied from interface: TOTorrent
convenience method to get a wrapped hash for performance purposes

Specified by:
getHashWrapper in interface TOTorrent
Returns:
Throws:
TOTorrentException

hasSameHashAs

public boolean hasSameHashAs(TOTorrent other)
Description copied from interface: TOTorrent
compares two torrents by hash

Specified by:
hasSameHashAs in interface TOTorrent
Returns:

setHashFromInfo

protected void setHashFromInfo(Map info)
                        throws TOTorrentException
Throws:
TOTorrentException

setHashOverride

public void setHashOverride(byte[] hash)
                     throws TOTorrentException
Description copied from interface: TOTorrent
Only supported for decentralised torrents, allows an alternative hash to be used for them in the DHT

Specified by:
setHashOverride in interface TOTorrent
Throws:
TOTorrentException

getHashOverride

protected byte[] getHashOverride()

setPrivate

public void setPrivate(boolean _private_torrent)
                throws TOTorrentException
Description copied from interface: TOTorrent
Note - changing the private attribute CHANGES THE TORRENT HASH

Specified by:
setPrivate in interface TOTorrent
Throws:
TOTorrentException

getPrivate

public boolean getPrivate()
Specified by:
getPrivate in interface TOTorrent

getAnnounceURLGroup

public TOTorrentAnnounceURLGroup getAnnounceURLGroup()
Description copied from interface: TOTorrent
When a group of sets of trackers is defined their URLs are accessed via this method

Specified by:
getAnnounceURLGroup in interface TOTorrent
Returns:
the group, always present, which may have 0 members

addTorrentAnnounceURLSet

protected void addTorrentAnnounceURLSet(URL[] urls)

getSize

public long getSize()
Specified by:
getSize in interface TOTorrent

getPieceLength

public long getPieceLength()
Description copied from interface: TOTorrent
Returns the piece length used for the torrent

Specified by:
getPieceLength in interface TOTorrent
Returns:

setPieceLength

protected void setPieceLength(long _length)

getNumberOfPieces

public int getNumberOfPieces()
Specified by:
getNumberOfPieces in interface TOTorrent

getPieces

public byte[][] getPieces()
Specified by:
getPieces in interface TOTorrent

setPieces

public void setPieces(byte[][] _pieces)
Description copied from interface: TOTorrent
This method exists to support the temporary discarding of piece hashes to conserver memory. It should only be used with care!

Specified by:
setPieces in interface TOTorrent

getFileCount

public int getFileCount()
Specified by:
getFileCount in interface TOTorrent

getFiles

public TOTorrentFile[] getFiles()
Description copied from interface: TOTorrent
A torrent consists of one or more files. These are accessed via this method.

Specified by:
getFiles in interface TOTorrent
Returns:

setFiles

protected void setFiles(TOTorrentFileImpl[] _files)

getSimpleTorrent

protected boolean getSimpleTorrent()

setSimpleTorrent

protected void setSimpleTorrent(boolean _simple_torrent)

getAdditionalProperties

protected Map getAdditionalProperties()

setAdditionalStringProperty

public void setAdditionalStringProperty(String name,
                                        String value)
Description copied from interface: TOTorrent
The additional properties are used for holding non-core data for Azureus' own user

Specified by:
setAdditionalStringProperty in interface TOTorrent
Parameters:
name - name of the property (e.g. "encoding")
value - value. This will be encoded with default encoding

getAdditionalStringProperty

public String getAdditionalStringProperty(String name)
Specified by:
getAdditionalStringProperty in interface TOTorrent

setAdditionalByteArrayProperty

public void setAdditionalByteArrayProperty(String name,
                                           byte[] value)
Specified by:
setAdditionalByteArrayProperty in interface TOTorrent

setAdditionalProperty

public void setAdditionalProperty(String name,
                                  Object value)
Description copied from interface: TOTorrent
set an arbitrary property. Make sure its compatible with bencoding!

Specified by:
setAdditionalProperty in interface TOTorrent

getAdditionalByteArrayProperty

public byte[] getAdditionalByteArrayProperty(String name)
Specified by:
getAdditionalByteArrayProperty in interface TOTorrent

setAdditionalLongProperty

public void setAdditionalLongProperty(String name,
                                      Long value)
Specified by:
setAdditionalLongProperty in interface TOTorrent

getAdditionalLongProperty

public Long getAdditionalLongProperty(String name)
Specified by:
getAdditionalLongProperty in interface TOTorrent

setAdditionalListProperty

public void setAdditionalListProperty(String name,
                                      List value)
Specified by:
setAdditionalListProperty in interface TOTorrent

getAdditionalListProperty

public List getAdditionalListProperty(String name)
Specified by:
getAdditionalListProperty in interface TOTorrent

setAdditionalMapProperty

public void setAdditionalMapProperty(String name,
                                     Map value)
Specified by:
setAdditionalMapProperty in interface TOTorrent

getAdditionalMapProperty

public Map getAdditionalMapProperty(String name)
Specified by:
getAdditionalMapProperty in interface TOTorrent

getAdditionalProperty

public Object getAdditionalProperty(String name)
Specified by:
getAdditionalProperty in interface TOTorrent

removeAdditionalProperty

public void removeAdditionalProperty(String name)
Specified by:
removeAdditionalProperty in interface TOTorrent

removeAdditionalProperties

public void removeAdditionalProperties()
Description copied from interface: TOTorrent
remove all additional properties to clear out the torrent

Specified by:
removeAdditionalProperties in interface TOTorrent

addAdditionalProperty

protected void addAdditionalProperty(String name,
                                     Object value)

addAdditionalInfoProperty

protected void addAdditionalInfoProperty(String name,
                                         Object value)

getAdditionalInfoProperties

protected Map getAdditionalInfoProperties()

readStringFromMetaData

protected String readStringFromMetaData(Map meta_data,
                                        String name)
                                 throws TOTorrentException
Throws:
TOTorrentException

readStringFromMetaData

protected String readStringFromMetaData(byte[] value)
                                 throws TOTorrentException
Throws:
TOTorrentException

writeStringToMetaData

protected void writeStringToMetaData(Map meta_data,
                                     String name,
                                     String value)
                              throws TOTorrentException
Throws:
TOTorrentException

writeStringToMetaData

protected byte[] writeStringToMetaData(String value)
                                throws TOTorrentException
Throws:
TOTorrentException

anonymityTransform

protected URL anonymityTransform(URL url)

print

public void print()
Description copied from interface: TOTorrent
A diagnostic method for dumping the tracker contents to "stdout"

Specified by:
print in interface TOTorrent

fireChanged

protected void fireChanged(int type)

addListener

public void addListener(TOTorrentListener l)
Specified by:
addListener in interface TOTorrent

removeListener

public void removeListener(TOTorrentListener l)
Specified by:
removeListener in interface TOTorrent

getMonitor

public AEMonitor getMonitor()
Specified by:
getMonitor in interface TOTorrent

getRelationText

public String getRelationText()
Description copied from class: LogRelation
A short description of what your class holds that can be printed by the logger

Overrides:
getRelationText in class LogRelation
Returns:

getQueryableInterfaces

public Object[] getQueryableInterfaces()
Description copied from class: LogRelation
Query this class for a reference to another class that it may hold

Overrides:
getQueryableInterfaces in class LogRelation
Returns:
If found, the class desired. Otherwise, null.