Package org.klomp.snark
Class MetaInfo
java.lang.Object
org.klomp.snark.MetaInfo
Note: this class is buggy, as it doesn't propogate custom meta fields into the bencoded
info data, and from there to the info_hash. At the moment, though, it seems to work with
torrents created by I2P-BT, I2PRufus and Azureus.
-
Constructor Summary
ConstructorsConstructorDescriptionMetaInfo(InputStream in) Creates a new MetaInfo from the given InputStream.MetaInfo(String announce, String name, List<List<String>> files, List<Long> lengths, int piece_length, byte[] piece_hashes, long length, boolean privateTorrent, List<List<String>> announce_list, String created_by, List<String> url_list, String comment) Called by Storage when creating a new torrent from local dataMetaInfo(String announce, String name, List<List<String>> files, List<Long> lengths, int piece_length, byte[] piece_hashes, long length, int privateTorrent, List<List<String>> announce_list, String created_by, List<String> url_list, String comment) Preserves privateTorrent int value, for main()Creates a new MetaInfo from a Map of BEValues and the SHA1 over the original bencoded info dictionary (this is a hack, we could reconstruct the bencoded stream and recalculate the hash).MetaInfo(MetaInfo old, String new_announce, List<List<String>> new_announce_list, String new_comment, String new_created_by, List<String> new_url_list) Will not change infohash. -
Method Summary
Modifier and TypeMethodDescriptionbooleancheckPiece(int piece, byte[] hash) Checks that the given piece has the same SHA1 hash as the given byte array.(package private) booleanReturns the string representing the URL of the tracker for this torrent.Returns a list of lists of urls.The comment string or null.The created-by string or null.longThe creation date (ms) or zero.getFiles()Returns a list of lists of file name hierarchies or null if it is a single name.byte[]Side effect: Caches infoBytesLength.intThe size of getInfoBytes().byte[]Returns the original 20 byte SHA1 hash over the bencoded info map.Returns a list of Longs indication the size of the individual files, or null if it is a single file.getName()Returns the requested name for the file or toplevel directory.static StringgetNameAndInfoHash(InputStream in, byte[] infoHashOut) Efficiently returns the name and the 20 byte SHA1 hash of the info dictionary in a torrent file Caller must close stream.byte[]Returns the piece hashes.intgetPieceLength(int piece) Return the length of a piece.intReturns the number of pieces.intbyte[]Called by servlet to save a new torrent file generated from local datalongReturns the total length of the torrent in bytes.Returns a list of urls or null.booleanisPaddingFile(int filenum) Is this file a padding file?booleanIs it a private torrent?static voidreannounce(String announce) Creates a copy of this MetaInfo that shares everything except the announce URL.toString()
-
Constructor Details
-
MetaInfo
public MetaInfo(String announce, String name, List<List<String>> files, List<Long> lengths, int piece_length, byte[] piece_hashes, long length, boolean privateTorrent, List<List<String>> announce_list, String created_by, List<String> url_list, String comment) Called by Storage when creating a new torrent from local data- Parameters:
announce- may be nullfiles- null for single-file torrentlengths- null for single-file torrentannounce_list- may be nullcreated_by- may be nullurl_list- may be nullcomment- may be null- Since:
- public since 0.9.53, was package private
-
MetaInfo
public MetaInfo(String announce, String name, List<List<String>> files, List<Long> lengths, int piece_length, byte[] piece_hashes, long length, int privateTorrent, List<List<String>> announce_list, String created_by, List<String> url_list, String comment) Preserves privateTorrent int value, for main()- Since:
- 0.9.62
-
MetaInfo
public MetaInfo(MetaInfo old, String new_announce, List<List<String>> new_announce_list, String new_comment, String new_created_by, List<String> new_url_list) Will not change infohash. Retains creation date of old MetaInfo if nonzero.- Parameters:
new_announce- may be nullnew_announce_list- may be nullnew_comment- may be nullnew_created_by- may be nullnew_url_list- may be null- Since:
- 0.9.64
-
MetaInfo
Creates a new MetaInfo from the given InputStream. The InputStream must start with a correctly bencoded dictionary describing the torrent. Caller must close the stream.- Throws:
IOException
-
MetaInfo
Creates a new MetaInfo from a Map of BEValues and the SHA1 over the original bencoded info dictionary (this is a hack, we could reconstruct the bencoded stream and recalculate the hash). Will NOT throw a InvalidBEncodingException if the given map does not contain a valid announce string. WILL throw a InvalidBEncodingException if the given map does not contain a valid info dictionary.- Throws:
InvalidBEncodingException
-
-
Method Details
-
getNameAndInfoHash
Efficiently returns the name and the 20 byte SHA1 hash of the info dictionary in a torrent file Caller must close stream.- Parameters:
infoHashOut- 20-byte out parameter- Throws:
IOException- Since:
- 0.8.5
-
getAnnounce
Returns the string representing the URL of the tracker for this torrent.- Returns:
- may be null!
-
getAnnounceList
Returns a list of lists of urls.- Since:
- 0.9.5
-
getWebSeedURLs
Returns a list of urls or null.- Since:
- 0.9.48
-
getInfoHash
public byte[] getInfoHash()Returns the original 20 byte SHA1 hash over the bencoded info map. -
getPieceHashes
public byte[] getPieceHashes()Returns the piece hashes.- Returns:
- not a copy, do not modify
- Since:
- public since 0.9.53, was package private
-
getName
Returns the requested name for the file or toplevel directory. If it is a toplevel directory name getFiles() will return a non-null List of file name hierarchy name. -
isPrivate
public boolean isPrivate()Is it a private torrent?- Since:
- 0.9
-
getPrivateTrackerStatus
public int getPrivateTrackerStatus()- Returns:
- 0 (default), 1 (set to 1), -1 (set to 0)
- Since:
- 0.9.62
-
getFiles
Returns a list of lists of file name hierarchies or null if it is a single name. It has the same size as the list returned by getLengths(). -
isPaddingFile
public boolean isPaddingFile(int filenum) Is this file a padding file?- Since:
- 0.9.48
-
getLengths
Returns a list of Longs indication the size of the individual files, or null if it is a single file. It has the same size as the list returned by getFiles(). -
getComment
The comment string or null. Not available for locally-created torrents.- Since:
- 0.9.7
-
getCreatedBy
The created-by string or null. Not available for locally-created torrents.- Since:
- 0.9.7
-
getCreationDate
public long getCreationDate()The creation date (ms) or zero. As of 0.9.19, available for locally-created torrents.- Since:
- 0.9.7
-
getPieces
public int getPieces()Returns the number of pieces. -
getPieceLength
public int getPieceLength(int piece) Return the length of a piece. All pieces are of equal length except for the last one (getPieces()-1).- Throws:
IndexOutOfBoundsException- when piece is equal to or greater then the number of pieces in the torrent.
-
checkPiece
public boolean checkPiece(int piece, byte[] hash) Checks that the given piece has the same SHA1 hash as the given byte array.- Parameters:
hash- 20 bytes- Throws:
IndexOutOfBoundsException- Since:
- 0.9.71 replaces check of full piece in-memory
-
checkPiece
- Returns:
- good
- Since:
- 0.9.1
-
getTotalLength
public long getTotalLength()Returns the total length of the torrent in bytes. This includes any padding files. -
toString
-
reannounce
Creates a copy of this MetaInfo that shares everything except the announce URL. Drops any announce-list. Preserves infohash and info map, including any non-standard fields.- Parameters:
announce- may be null- Throws:
InvalidBEncodingException
-
getTorrentData
public byte[] getTorrentData()Called by servlet to save a new torrent file generated from local data -
getInfoBytes
public byte[] getInfoBytes()Side effect: Caches infoBytesLength.- Since:
- 0.8.4
-
getInfoBytesLength
public int getInfoBytesLength()The size of getInfoBytes(). Cached.- Since:
- 0.9.48
-
main
- Since:
- 0.8.5
-