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 charSERIALIZED_PREFIXNumber prefix character in serialized form. -
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 intcompareTo(BencodedInteger anotherObject)Compares this object with the specified object for order.booleanequals(java.lang.Object obj)Compares the class instance with another instance of this class.longgetValue()Returns the stored numeric value as long integer.inthashCode()Calculates and returns hashcode for the class instance.java.lang.StringtoString()Returns the string representation of the class instance.static BencodedIntegervalueOf(java.lang.String string)Returns a BencodedInteger object holding the value of the specified String.static BencodedIntegervalueOf(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.voidwriteObject(java.io.OutputStream os)Writes the class instance to the output stream.
-
Field Details
-
SERIALIZED_PREFIX
public static final char SERIALIZED_PREFIXNumber prefix character in serialized form.- See Also:
- Constant Field Values
-
-
Constructor Details
-
BencodedInteger
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.NumberFormatExceptionReturns 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.NumberFormatExceptionReturns 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:
equalsin classjava.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:
hashCodein classjava.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:
toStringin classjava.lang.Object- Returns:
- the string representation of the class instance.
-
writeObject
public void writeObject(java.io.OutputStream os) throws java.io.IOExceptionWrites 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
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:
compareToin interfacejava.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.
-