Package org.klomp.snark.bencode
Class BEValue
java.lang.Object
org.klomp.snark.bencode.BEValue
Holds different types that a bencoded byte array can represent.
You need to call the correct get method to get the correct java
type object. If the BEValue wasn't actually of the requested type
you will get a InvalidBEncodingException.
- Author:
- Mark Wielaard (mark@klomp.org)
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionbyte[]
getBytes()
Returns this BEValue as a byte[].int
getInt()
Returns this BEValue as int.getList()
Returns this BEValue as a List of BEValues.long
getLong()
Returns this BEValue as long.getMap()
Returns this BEValue as a Map of BEValue keys and BEValue values.Returns this BEValue as a Number.Returns this BEValue as a String.getValue()
return the untyped valuetoString()
-
Constructor Details
-
BEValue
public BEValue(byte[] value) -
BEValue
-
BEValue
-
BEValue
-
-
Method Details
-
getString
Returns this BEValue as a String. This operation only succeeds when the BEValue is a byte[], otherwise it will throw a InvalidBEncodingException. The byte[] will be interpreted as UTF-8 encoded characters.- Throws:
InvalidBEncodingException
-
getBytes
Returns this BEValue as a byte[]. This operation only succeeds when the BEValue is actually a byte[], otherwise it will throw a InvalidBEncodingException.- Throws:
InvalidBEncodingException
-
getNumber
Returns this BEValue as a Number. This operation only succeeds when the BEValue is actually a Number, otherwise it will throw a InvalidBEncodingException.- Throws:
InvalidBEncodingException
-
getInt
Returns this BEValue as int. This operation only succeeds when the BEValue is actually a Number, otherwise it will throw a InvalidBEncodingException. The returned int is the result ofNumber.intValue()
.- Throws:
InvalidBEncodingException
-
getLong
Returns this BEValue as long. This operation only succeeds when the BEValue is actually a Number, otherwise it will throw a InvalidBEncodingException. The returned long is the result ofNumber.longValue()
.- Throws:
InvalidBEncodingException
-
getList
Returns this BEValue as a List of BEValues. This operation only succeeds when the BEValue is actually a List, otherwise it will throw a InvalidBEncodingException.- Throws:
InvalidBEncodingException
-
getMap
Returns this BEValue as a Map of BEValue keys and BEValue values. This operation only succeeds when the BEValue is actually a Map, otherwise it will throw a InvalidBEncodingException.- Throws:
InvalidBEncodingException
-
getValue
return the untyped value -
toString
-