Class 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.
    Author:
    Mark Wielaard (mark@klomp.org)
    • Constructor Detail

      • BEValue

        public BEValue​(byte[] value)
      • BEValue

        public BEValue​(Number value)
    • Method Detail

      • 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.
        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
      • 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
      • getValue

        public Object getValue()
        return the untyped value