org.klomp.snark.bencode
Class BEValue

java.lang.Object
  extended by org.klomp.snark.bencode.BEValue

public class BEValue
extends java.lang.Object

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
BEValue(byte[] value)
           
BEValue(java.util.List value)
           
BEValue(java.util.Map value)
           
BEValue(java.lang.Number value)
           
 
Method Summary
 byte[] getBytes()
          Returns this BEValue as a byte[].
 int getInt()
          Returns this BEValue as int.
 java.util.List getList()
          Returns this BEValue as a List of BEValues.
 long getLong()
          Returns this BEValue as long.
 java.util.Map getMap()
          Returns this BEValue as a Map of BEValue keys and BEValue values.
 java.lang.Number getNumber()
          Returns this BEValue as a Number.
 java.lang.String getString()
          Returns this BEValue as a String.
 java.lang.Object getValue()
          return the untyped value
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BEValue

public BEValue(byte[] value)

BEValue

public BEValue(java.lang.Number value)

BEValue

public BEValue(java.util.List value)

BEValue

public BEValue(java.util.Map value)
Method Detail

getString

public java.lang.String getString()
                           throws InvalidBEncodingException
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

public byte[] getBytes()
                throws InvalidBEncodingException
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

public java.lang.Number getNumber()
                           throws InvalidBEncodingException
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

public int getInt()
           throws InvalidBEncodingException
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 of Number.intValue().

Throws:
InvalidBEncodingException

getLong

public long getLong()
             throws InvalidBEncodingException
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 of Number.longValue().

Throws:
InvalidBEncodingException

getList

public java.util.List getList()
                       throws InvalidBEncodingException
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

public java.util.Map getMap()
                     throws InvalidBEncodingException
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

public java.lang.Object getValue()
return the untyped value


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object