Class BencodedInteger

java.lang.Object
com.github.cdefgah.bencoder4j.model.BencodedObject
com.github.cdefgah.bencoder4j.model.BencodedInteger
All Implemented Interfaces:
java.lang.Comparable<BencodedInteger>

public final class BencodedInteger
extends BencodedObject
implements java.lang.Comparable<BencodedInteger>
This class represents b-encoded integer.
See Also:
Bencode reference
  • Field Summary

    Fields 
    Modifier and Type Field Description
    static char SERIALIZED_PREFIX
    Number prefix character in serialized form.

    Fields inherited from class com.github.cdefgah.bencoder4j.model.BencodedObject

    SERIALIZED_SUFFIX
  • Constructor Summary

    Constructors 
    Constructor Description
    BencodedInteger​(long value)
    Class constructor.
    BencodedInteger​(BencodeStreamReader bsr)
    Class constructor, used to de-serialize the class instance from InputStream instance.
  • Method Summary

    Modifier and Type Method Description
    int compareTo​(BencodedInteger anotherObject)
    Compares this object with the specified object for order.
    boolean equals​(java.lang.Object obj)
    Compares the class instance with another instance of this class.
    long getValue()
    Returns the stored numeric value as long integer.
    int hashCode()
    Calculates and returns hashcode for the class instance.
    java.lang.String toString()
    Returns the string representation of the class instance.
    static BencodedInteger valueOf​(java.lang.String string)
    Returns a BencodedInteger object holding the value of the specified String.
    static BencodedInteger valueOf​(java.lang.String string, int radix)
    Returns a BencodedInteger object holding the value extracted from the specified String when parsed with the radix given by the second argument.
    void writeObject​(java.io.OutputStream os)
    Writes the class instance to the output stream.

    Methods inherited from class com.github.cdefgah.bencoder4j.model.BencodedObject

    isCompositeObject

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • BencodedInteger

      public BencodedInteger​(BencodeStreamReader bsr) throws java.io.IOException, BencodeFormatException
      Class constructor, used to de-serialize the class instance from InputStream instance.
      Parameters:
      bsr - stream reader to be used for deserialization purposes.
      Throws:
      java.io.IOException - if there's an I/O error occurred upon the processing.
      BencodeFormatException - if there are b-encoding format errors found upon the processing.
    • BencodedInteger

      public BencodedInteger​(long value)
      Class constructor.
      Parameters:
      value - value to initialize the class instance.
  • Method Details

    • valueOf

      public static BencodedInteger valueOf​(java.lang.String string) throws java.lang.NumberFormatException
      Returns a BencodedInteger object holding the value of the specified String. The argument is interpreted as representing a signed decimal long, exactly as if the argument were given to the Long.parseLong(java.lang.String) method.
      Parameters:
      string - the string to be parsed to long value and then used to build a BencodedInteger instance.
      Returns:
      a BencodedInteger object holding the long integer value represented by the string argument.
      Throws:
      java.lang.NumberFormatException - If the string cannot be parsed as a long.
    • valueOf

      public static BencodedInteger valueOf​(java.lang.String string, int radix) throws java.lang.NumberFormatException
      Returns a BencodedInteger object holding the value extracted from the specified String when parsed with the radix given by the second argument. The first argument is interpreted as representing a signed long in the radix specified by the second argument, exactly as if the arguments were given to the Long.parseLong(java.lang.String, int) method.
      Parameters:
      string - the string to be parsed to long value and then used to build a BencodedInteger instance.
      radix - the radix to be used in interpreting string.
      Returns:
      a BencodedInteger object holding the long integer value represented by the string argument in the specified radix.
      Throws:
      java.lang.NumberFormatException - If the String does not contain a parsable long.
    • equals

      public boolean equals​(java.lang.Object obj)
      Compares the class instance with another instance of this class.
      Overrides:
      equals in class java.lang.Object
      Parameters:
      obj - reference to another instance of this class.
      Returns:
      true, if instances are equal.
    • hashCode

      public int hashCode()
      Calculates and returns hashcode for the class instance.
      Overrides:
      hashCode in class java.lang.Object
      Returns:
      see method description above.
    • getValue

      public long getValue()
      Returns the stored numeric value as long integer.
      Returns:
      the stored numeric value as long integer.
    • toString

      public java.lang.String toString()
      Returns the string representation of the class instance.
      Overrides:
      toString in class java.lang.Object
      Returns:
      the string representation of the class instance.
    • writeObject

      public void writeObject​(java.io.OutputStream os) throws java.io.IOException
      Writes the class instance to the output stream.
      Parameters:
      os - output stream instance.
      Throws:
      java.io.IOException - if there's an input/output error occurred.
    • compareTo

      public int compareTo​(BencodedInteger anotherObject)
      Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
      Specified by:
      compareTo in interface java.lang.Comparable<BencodedInteger>
      Parameters:
      anotherObject - the object to be compared.
      Returns:
      a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.