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.
Field Summary
Constructor Summary
Method Summary
All MethodsModifier and TypeMethodDescriptionbyte[]getBytes()Returns this BEValue as a byte[].intgetInt()Returns this BEValue as int.getList()Returns this BEValue as a List of BEValues.longgetLong()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()Returns the untyped value contained in this BEValue.toString()
Field Details
value
The decoded value - a byte array, a Number, a List or a Map.
Constructor Details
BEValue
public BEValue(byte[] value) Creates a new BEValue wrapping a byte array.- Parameters:
value- the byte array value to wrap
BEValue
Creates a new BEValue wrapping a Number.- Parameters:
value- the Number value to wrap
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.- Returns:
- the String value
- Throws:
InvalidBEncodingException- if the value is not a byte array
getBytes
Returns this BEValue as a byte[]. This operation only succeeds when the BEValue is actually a byte[], otherwise it will throw a InvalidBEncodingException.- Returns:
- the stored array itself, not a copy of it
- Throws:
InvalidBEncodingException- if the value is not a byte array
getNumber
Returns this BEValue as a Number. This operation only succeeds when the BEValue is actually a Number, otherwise it will throw a InvalidBEncodingException.- Returns:
- the Number value
- Throws:
InvalidBEncodingException- if the value is not a Number
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().- Returns:
- the value narrowed by
Number.intValue() - Throws:
InvalidBEncodingException- if the value is not a Number
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().- Returns:
- the value narrowed by
Number.longValue() - Throws:
InvalidBEncodingException- if the value is not a Number
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.- Returns:
- the List value
- Throws:
InvalidBEncodingException- if the value is not a List
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.- Returns:
- the Map value
- Throws:
InvalidBEncodingException- if the value is not a Map
getValue
Returns the untyped value contained in this BEValue.- Returns:
- the underlying value (byte[], Number, List, or Map)
toString