Class IntegerDecoder
- java.lang.Object
-
- org.apache.directory.api.asn1.ber.tlv.IntegerDecoder
-
public final class IntegerDecoder extends Object
Parse and decode an Integer value.- Author:
- Apache Directory Project
-
-
Field Summary
Fields Modifier and Type Field Description private static int[]MASKA mask used to get only the necessary bytes
-
Constructor Summary
Constructors Modifier Constructor Description privateIntegerDecoder()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intparse(BerValue value)Parse a byte buffer and send back an integerstatic intparse(BerValue value, int min, int max)Parse a byte buffer and send back an integer, controlling that this number is in a specified interval.private static intparseInt(BerValue value)Helper method used to parse the integer.
-
-
-
Method Detail
-
parse
public static int parse(BerValue value, int min, int max) throws IntegerDecoderException
Parse a byte buffer and send back an integer, controlling that this number is in a specified interval.- Parameters:
value- The Value containing the byte[] to parsemin- Lowest value allowed, includedmax- Highest value allowed, included- Returns:
- An integer
- Throws:
IntegerDecoderException- Thrown if the byte[] does not contains an integer
-
parse
public static int parse(BerValue value) throws IntegerDecoderException
Parse a byte buffer and send back an integer- Parameters:
value- The byte buffer to parse- Returns:
- An integer
- Throws:
IntegerDecoderException- Thrown if the byte stream does not contains an integer
-
parseInt
private static int parseInt(BerValue value) throws IntegerDecoderException
Helper method used to parse the integer. We don't check any minimal or maximal bound. An BER encoded int can be either positive or negative. It uses the minimum number of bytes necessary to encode the value. The high order bit gives the sign of the integer : if it's 1, then it's a negative value, otherwise it's a positive value. Integer with a high order bit set to 1 but prefixed by a 0x00 are positive. If the integer is negative, then the 2 complement value is stored
Here are a few samples :- 0x02 0x01 0x00 : integer 0
- 0x02 0x01 0x01 : integer 1
- 0x02 0x01 0x7F : integer 127
- 0x02 0x01 0x80 : integer -128
- 0x02 0x01 0x81 : integer -127
- 0x02 0x01 0xFF : integer -1
- 0x02 0x02 0x00 0x80 : integer 128
- 0x02 0x02 0x00 0x81 : integer 129
- 0x02 0x02 0x00 0xFF : integer 255
- Parameters:
value- the BER PDU to parse- Returns:
- The decoded value
- Throws:
IntegerDecoderException- If the BER contains an invalid integer value
-
-