Package org.klomp.snark.bencode
Class BDecoder
java.lang.Object
org.klomp.snark.bencode.BDecoder
Decodes a bencoded stream to
BEValue
s.
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).- Author:
- Mark Wielaard (mark@klomp.org).
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbdecode()
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 immediatly decodes the first value it sees.Returns the next bencoded value on the stream and makes sure it is a byte array.Returns the next bencoded value on the stream and makes sure it is a list.Returns the next bencoded value on the stream and makes sure it is a map (dictonary).Returns the next bencoded value on the stream and makes sure it is a number.byte[]
Ugly hack.int
Returns what the next bencoded object will be on the stream or -1 when the end of stream has been reached.static void
prints out the decoded data
-
Constructor Details
-
BDecoder
Initalizes a new BDecoder. Nothing is read from the givenInputStream
yet.
-
-
Method Details
-
get_special_map_digest
public byte[] get_special_map_digest()Ugly hack. Return the SHA has over bytes that make up the special map.- Returns:
- null if there was no special map
-
bdecode
Creates a new BDecoder and immediatly decodes the first value it sees.- Returns:
- The first BEValue on the stream or null when the stream has ended.
- Throws:
InvalidBEncodingException
- when the stream doesn't start with a bencoded value or the stream isn't a bencoded stream at all.IOException
- when somthing bad happens with the stream to read from.
-
getNextIndicator
Returns what the next bencoded object will be on the stream or -1 when the end of stream has been reached. Can return something unexpected (not '0' .. '9', 'i', 'l' or 'd') when the stream isn't bencoded. This might or might not read one extra byte from the stream.- Throws:
IOException
-
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.- Throws:
IOException
-
bdecodeBytes
Returns the next bencoded value on the stream and makes sure it is a byte array. If it is not a bencoded byte array it will throw InvalidBEncodingException.- Throws:
IOException
-
bdecodeNumber
Returns the next bencoded value on the stream and makes sure it is a number. If it is not a number it will throw InvalidBEncodingException.- Throws:
IOException
-
bdecodeList
Returns the next bencoded value on the stream and makes sure it is a list. If it is not a list it will throw InvalidBEncodingException.- Throws:
IOException
-
bdecodeMap
Returns the next bencoded value on the stream and makes sure it is a map (dictonary). If it is not a map it will throw InvalidBEncodingException.- Throws:
IOException
-
main
prints out the decoded data- Since:
- 0.9.14
-