|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.eclipse.ecf.protocol.bittorrent.TorrentFile
public class TorrentFile
The TorrentFile class is a representation of the information
stored within a .torrent file. Files can be set with the
setTargetFile(File) method and then have its integrity checked
against the torrent's hash sum values validate() method.
| Constructor Summary | |
|---|---|
TorrentFile(java.io.File file)
Creates a new Torrent to analyze the provided torrent
file. |
|
| Method Summary | |
|---|---|
boolean |
equals(java.lang.Object other)
Returns whether this TorrentFile is equal to the given
object. |
java.lang.String[] |
getFilenames()
Retrieves the names of all of the files' that is specified by this Torrent. |
java.lang.String |
getHexHash()
Returns the hexadecimal representation of the hash returned from getInfoHash(). |
java.lang.String |
getInfoHash()
Returns the hash of the info dictionary specified by the
torrent's metainfo. |
long[] |
getLengths()
Retrieve the specified lengths of the files contained within this torrent. |
java.lang.String |
getName()
Retrieves the name of this torrent file. |
int |
getNumPieces()
Returns the number of pieces associated with this torrent. |
int |
getPieceLength()
Returns the length of a piece. |
java.lang.String[] |
getPieces()
Returns a string array that contains the SHA-1 hash of each of the pieces defined by the torrent's metainfo. |
java.io.File |
getTargetFile()
Gets the file that has been set as the target file of this torrent per setTargetFile(File). |
long |
getTotalLength()
Retrieves the total length of all of the files specified within this torrent. |
java.lang.String |
getTracker()
Retrieves the URL of the tracker that's handling the requests for this torrent. |
int |
hashCode()
Returns the hash code of this TorrentFile based on its
info hash. |
boolean |
isMultiFile()
Returns whether this torrent is associated with multiple files or not. |
void |
save(java.io.File file)
Writes the contents of the file that was used to initialize this TorrentFile onto the provided file. |
void |
setTargetFile(java.io.File file)
Sets the target file or folder that this torrent should download to or look for the corresponding files in. |
boolean |
validate()
Checks the integrity of the target file or folder as set by setTargetFile(File) to determine whether its contents pass all
of the hash checks. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public TorrentFile(java.io.File file)
throws java.lang.IllegalArgumentException,
java.io.IOException
Torrent to analyze the provided torrent
file.
file - the torrent file
java.lang.IllegalArgumentException - If file is null or a directory
java.io.IOException - If an I/O error occurs whilst analyzing the torrent file| Method Detail |
|---|
public boolean validate()
throws java.lang.IllegalStateException,
java.io.IOException
setTargetFile(File) to determine whether its contents pass all
of the hash checks.
true if and only if every hash check has been
passed, false otherwise
java.io.FileNotFoundException - If one of the files associated with the torrent could not be
found
java.lang.IllegalStateException - If the target file has not been set yet with
setTargetFile(File)
java.io.IOException - If an I/O error occurs while reading from the files
public void setTargetFile(java.io.File file)
throws java.lang.IllegalArgumentException
file - the target file or folder to use, this should be a file if the
torrent is a single file torrent or a folder if it has
multiple files
java.lang.IllegalArgumentException - If file is null or if file is a
directory when this torrent is only using a single filepublic java.lang.String getInfoHash()
info dictionary specified by the
torrent's metainfo. This is primarily used for torrent identification
when sending messages to the tracker.
info dictionary within the
torrent's metainfo, this will likely contain binary data and will
not be human-readable as a resultpublic java.lang.String getHexHash()
getInfoHash(). This string is forty characters long.
getInfoHash()public long[] getLengths()
getFilenames().
public int getPieceLength()
public java.lang.String getTracker()
public java.lang.String[] getPieces()
public int getNumPieces()
public java.lang.String[] getFilenames()
Torrent. All of the files' lengths can be matched up
against the long value stored within the returned array from
getLengths().
public java.lang.String getName()
.torrent extension. If no such extension
exists, the entire file's name will be returned.
.torrent extension, if presentpublic java.io.File getTargetFile()
setTargetFile(File).
public boolean isMultiFile()
true if this torrent specifies multiple files,
false otherwisepublic long getTotalLength()
getLengths().
public void save(java.io.File file)
throws java.io.IOException
TorrentFile onto the provided file.
file - the file to save to
java.io.IOException - If an I/O error occurs while trying to write to the filepublic boolean equals(java.lang.Object other)
TorrentFile is equal to the given
object. The two are the same if their info hash section of the contained
metainfo is the same. If other is not an instance of a
TorrentFile, false is returned.
equals in class java.lang.Objectother -
true if other is a
TorrentFile and its info hash is the same as this
one, false otherwisepublic int hashCode()
TorrentFile based on its
info hash.
hashCode in class java.lang.ObjecthashCode() on the returned
string from getInfoHash()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||