org.klomp.snark.bencode

## Class BEValue

- java.lang.Object
- - org.klomp.snark.bencode.BEValue

-     public class BEValue
      extends 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.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `BEValue(byte[] value)` Creates a new BEValue wrapping a byte array.
    `BEValue(List<BEValue> value)` Creates a new BEValue wrapping a List.
    `BEValue(Map<String,BEValue> value)` Creates a new BEValue wrapping a Map.
    `BEValue(Number value)` Creates a new BEValue wrapping a Number.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `byte[]` | `getBytes()` Returns this BEValue as a byte[].
    `int` | `getInt()` Returns this BEValue as int.
    `List<BEValue>` | `getList()` Returns this BEValue as a List of BEValues.
    `long` | `getLong()` Returns this BEValue as long.
    `Map<String,BEValue>` | `getMap()` Returns this BEValue as a Map of BEValue keys and BEValue values.
    `Number` | `getNumber()` Returns this BEValue as a Number.
    `String` | `getString()` Returns this BEValue as a String.
    `Object` | `getValue()` Returns the untyped value contained in this BEValue.
    `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)

      Creates a new BEValue wrapping a byte array.
      Parameters:
        `value` - the byte array value to wrap

    - #### BEValue

          public BEValue(List<BEValue> value)

      Creates a new BEValue wrapping a List.
      Parameters:
        `value` - the List value to wrap

    - #### BEValue

          public BEValue(Map<String,BEValue> value)

      Creates a new BEValue wrapping a Map.
      Parameters:
        `value` - the Map value to wrap

    - #### BEValue

          public BEValue(Number value)

      Creates a new BEValue wrapping a Number.
      Parameters:
        `value` - the Number value to wrap

  - ### Method Detail

    - #### 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.
      Returns:
        the byte array value
      Throws:
        `InvalidBEncodingException` - if the value is not a byte array

    - #### 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()`.
      Returns:
        the int value
      Throws:
        `InvalidBEncodingException` - if the value is not a Number

    - #### getList

          public List<BEValue> 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.
      Returns:
        the List value
      Throws:
        `InvalidBEncodingException` - if the value is not a List

    - #### 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()`.
      Returns:
        the long value
      Throws:
        `InvalidBEncodingException` - if the value is not a Number

    - #### getMap

          public Map<String,BEValue> 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.
      Returns:
        the Map value
      Throws:
        `InvalidBEncodingException` - if the value is not a Map

    - #### getNumber

          public 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.
      Returns:
        the Number value
      Throws:
        `InvalidBEncodingException` - if the value is not a Number

    - #### getString

          public 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.
      Returns:
        the String value
      Throws:
        `InvalidBEncodingException` - if the value is not a byte array

    - #### getValue

          public Object getValue()

      Returns the untyped value contained in this BEValue.
      Returns:
        the underlying value (byte[], Number, List, or Map)

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`