java.lang.Object
org.klomp.snark.MagnetURI
Magnet URI parser and handler for BitTorrent magnet links.
Field Summary
Modifier and TypeFieldDescriptionprivate final byte[]The info hash, if the link gives one.private final longTotal length, -1 if the link gives none.private final StringTorrent name, null if the link gives none.Trackers named in the link.static final StringMaggot protocol prefix.static final StringBEP 9 magnet prefix.static final StringFull magnet URI prefix with info hash parameter.static final StringLink will contain two xt params.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionprivate static StringDecode %xx encoding, convert to UTF-8 if necessary.byte[]Returns the 20-byte info hash of the torrent.longReturns the length from the xl parameter of the magnet link.getMultiParam(String key, String uri) All decoded parameters, or null.getName()Returns the display name for this magnet link.private static StringThe first decoded parameter, or null.getTrackerParam(String uri) All valid I2P trackers, or null if none.Returns the first valid I2P tracker URL from the magnet link.Returns all valid I2P tracker URLs from the magnet link.
Field Details
_trackers
_name
Torrent name, null if the link gives none._ih
private final byte[] _ihThe info hash, if the link gives one._length
private final long _lengthTotal length, -1 if the link gives none.MAGNET
MAGNET_FULL
Full magnet URI prefix with info hash parameter.- See Also:
MAGGOT
MAGNET_FULL_V2
Link will contain two xt params. Duplicate xt params are not parsed yet, needed for dual v1/v2 links. See also: BitTorrent v2- See Also:
Constructor Details
MagnetURI
Parse a magnet or maggot URI.- Parameters:
util- supplies the localized "Magnet" prefix used to name the torrenturl- non-null- Throws:
IllegalArgumentException
Method Details
getInfoHash
public byte[] getInfoHash()Returns the 20-byte info hash of the torrent.- Returns:
- 20 bytes or null
getLength
public long getLength()Returns the length from the xl parameter of the magnet link.- Returns:
- the length or 0 if not specified.
getName
Returns the display name for this magnet link.- Returns:
- pretty name or null, NOT HTML escaped
getTrackerURL
Returns the first valid I2P tracker URL from the magnet link.- Returns:
- first valid tracker url or null
getTrackerURLs
getParam
getMultiParam
getTrackerParam
decode
Decode %xx encoding, convert to UTF-8 if necessary. Copied from i2ptunnel LocalHTTPServer. Also converts '+' to ' ' so the dn parameter comes out right These are coming in via a application/x-www-form-urlencoded form so the pluses are in there... hopefully any real + is encoded as %2B.- Parameters:
s- the string to decode, %xx escapes and + for space- Returns:
- the decoded string, s unchanged if it contains neither % nor +