public class BDecoder extends Object
BEValues.A bencoded byte stream can represent byte arrays, numbers, lists and maps (dictionaries).
It currently contains a hack to indicate a name of a dictionary of which a SHA-1 digest hash should be calculated (the hash over the original bencoded bytes).
| Constructor and Description |
|---|
BDecoder(InputStream in)Initializes a new BDecoder. |
| Modifier and Type | Method and Description |
|---|---|
BEValue | bdecode()Gets the next indicator and returns either null when the stream has ended or bdecodes the
rest of the stream and returns the appropriate BEValue encoded object. |
static BEValue | bdecode(InputStream in)Creates a new BDecoder and immediately decodes the first value it sees. |
BEValue | bdecodeBytes()Returns the next bencoded value on the stream and makes sure it is a byte array. |
BEValue | bdecodeList()Returns the next bencoded value on the stream and makes sure it is a list. |
BEValue | bdecodeMap()Returns the next bencoded value on the stream and makes sure it is a map (dictionary). |
BEValue | bdecodeNumber()Returns the next bencoded value on the stream and makes sure it is a number. |
byte[] | get_special_map_digest()Returns the SHA-1 digest over bytes that make up the special map (info map). |
int | getNextIndicator()Returns what the next bencoded object will be on the stream, or -1 at end of stream. |
static void | main(String[] args)Prints out the decoded data from a torrent file. |
public BDecoder(InputStream in)
in - the InputStream to decode frompublic BEValue bdecode() throws IOException
IOException - if an I/O error occurs or the stream is not bencodedpublic static BEValue bdecode(InputStream in) throws IOException
in - the InputStream to decode fromIOException - when something bad happens with the streampublic BEValue bdecodeBytes() throws IOException
IOException - if an I/O error occursInvalidBEncodingException - if the next value is not a byte arraypublic BEValue bdecodeList() throws IOException
IOException - if an I/O error occursInvalidBEncodingException - if the next value is not a listpublic BEValue bdecodeMap() throws IOException
IOException - if an I/O error occursInvalidBEncodingException - if the next value is not a mappublic BEValue bdecodeNumber() throws IOException
IOException - if an I/O error occursInvalidBEncodingException - if the next value is not a numberpublic byte[] get_special_map_digest()
public int getNextIndicator()
throws IOExceptionIOException - if an I/O error occurspublic static void main(String[] args)
args - command line arguments (expects one argument: the torrent file path)