Class BerValue
- java.lang.Object
-
- org.apache.directory.api.asn1.ber.tlv.BerValue
-
public class BerValue extends Object
This class stores the data decoded from a TLV.- Author:
- Apache Directory Project
-
-
Field Summary
Fields Modifier and Type Field Description private intcurrentPosThe current position of the last byte in the data bufferprivate byte[]dataThe data buffer.private static byte[]ENCODED_FALSEPre-encoded PDUs for a FALSE TLVprivate static byte[]ENCODED_TRUEPre-encoded PDUs for a TRUE TLVstatic byteFALSE_VALUEThe encoded byte for a FALSE valueprivate static longFIVE_BYTE_MAXInteger limits for encoding : 0x7FFFFFFFFFprivate static longFIVE_BYTE_MINInteger limits for encoding : -0x7FFFFFFFFFprivate static longFOUR_BYTE_MAXInteger limits for encoding : 0x7FFFFFFFprivate static longFOUR_BYTE_MINInteger limits for encoding : -0x7FFFFFFFprivate static intONE_BYTE_MAXInteger limits for encoding : 0x7Fprivate static intONE_BYTE_MINInteger limits for encoding : -0x7Fprivate static longSEVEN_BYTE_MAXInteger limits for encoding : 0x7FFFFFFFFFFFprivate static longSEVEN_BYTE_MINInteger limits for encoding : -0x7FFFFFFFFFFFprivate static longSIX_BYTE_MAXInteger limits for encoding : 0x7FFFFFFFFFFFprivate static longSIX_BYTE_MINInteger limits for encoding : -0x7FFFFFFFFFFFprivate static intTHREE_BYTE_MAXInteger limits for encoding : 0x7FFFFFprivate static intTHREE_BYTE_MINInteger limits for encoding : -0x7FFFFFstatic byteTRUE_VALUEThe encoded byte for a TRUE valueprivate static intTWO_BYTE_MAXInteger limits for encoding : 0x7FFFprivate static intTWO_BYTE_MINInteger limits for encoding : -0x7FFF
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddData(byte[] array)Append some bytes to the data buffer.voidaddData(ByteBuffer buffer)Append some bytes to the data buffer.static voidencode(ByteBuffer buffer, boolean bool)Encode a boolean valuestatic voidencode(ByteBuffer buffer, byte[] bytes)Encode an OctetString valuestatic voidencode(ByteBuffer buffer, byte tag, int value)Encode an integer valuestatic voidencode(ByteBuffer buffer, int value)Encode an integer valuestatic voidencode(ByteBuffer buffer, long value)Encode a long valuestatic voidencode(ByteBuffer buffer, String string)Encode a String valuestatic voidencode(ByteBuffer buffer, org.apache.directory.api.asn1.util.BitString bitString)Encode a BIT STRING valuestatic voidencode(ByteBuffer buffer, org.apache.directory.api.asn1.util.Oid oid)Encode an OID valuestatic voidencodeBoolean(org.apache.directory.api.asn1.util.Asn1Buffer buffer, boolean bool)Encode a boolean valuestatic voidencodeBoolean(org.apache.directory.api.asn1.util.Asn1Buffer buffer, byte tag, boolean bool)Encode a boolean valuestatic voidencodeEnumerated(ByteBuffer buffer, int value)Encode an enumerated valuestatic voidencodeEnumerated(org.apache.directory.api.asn1.util.Asn1Buffer buffer, byte tag, int value)Encode an enumerated valuestatic voidencodeEnumerated(org.apache.directory.api.asn1.util.Asn1Buffer buffer, int value)Encode an enumerated valuestatic voidencodeInteger(org.apache.directory.api.asn1.util.Asn1Buffer buffer, byte tag, int value)Encode an integer value, with a specific tagstatic voidencodeInteger(org.apache.directory.api.asn1.util.Asn1Buffer buffer, byte tag, long value)Encode an integer value, with a specific tagstatic voidencodeInteger(org.apache.directory.api.asn1.util.Asn1Buffer buffer, int value)Encode an integer valuestatic voidencodeInteger(org.apache.directory.api.asn1.util.Asn1Buffer buffer, long value)Encode an integer valuestatic voidencodeOctetString(org.apache.directory.api.asn1.util.Asn1Buffer buffer, byte[] data)Encode an OctetStringstatic voidencodeOctetString(org.apache.directory.api.asn1.util.Asn1Buffer buffer, byte tag, byte[] data)Encode an OctetStringstatic voidencodeOctetString(org.apache.directory.api.asn1.util.Asn1Buffer buffer, byte tag, String value)Encode an OctetStringstatic voidencodeOctetString(org.apache.directory.api.asn1.util.Asn1Buffer buffer, String value)Encode an OctetStringstatic voidencodeSequence(org.apache.directory.api.asn1.util.Asn1Buffer buffer)Encode a Sequencestatic voidencodeSequence(org.apache.directory.api.asn1.util.Asn1Buffer buffer, byte tag)Encode a Sequence, with a specific tagstatic voidencodeSequence(org.apache.directory.api.asn1.util.Asn1Buffer buffer, byte tag, int start)Encode a Sequence, with a specific length and tagstatic voidencodeSequence(org.apache.directory.api.asn1.util.Asn1Buffer buffer, int start)Encode a Sequence, with a specific lengthstatic voidencodeSet(org.apache.directory.api.asn1.util.Asn1Buffer buffer)Encode a Setstatic voidencodeSet(org.apache.directory.api.asn1.util.Asn1Buffer buffer, byte tag)Encode a Set, with a specific tagstatic voidencodeSet(org.apache.directory.api.asn1.util.Asn1Buffer buffer, byte tag, int start)Encode a Set, with a specific length and tagstatic voidencodeSet(org.apache.directory.api.asn1.util.Asn1Buffer buffer, int start)Encode a Set, with a specific lengthstatic byte[]getBytes(int value)Utility function that return a byte array representing the Value We must respect the ASN.1 BER encoding scheme :static byte[]getBytes(long value)Utility function that return a byte array representing the Value.intgetCurrentLength()byte[]getData()Get the Values'datastatic intgetNbBytes(int value)Utility function that return the number of bytes necessary to store an integer value.static intgetNbBytes(long value)Utility function that return the number of bytes necessary to store a long value.voidinit(int size)Initialize the Valuevoidreset()Reset the Value so that it can be reusedvoidsetData(byte[] data)Set a block of bytes in the ValuevoidsetData(ByteBuffer data)Set a block of bytes in the ValueStringtoString()Return a string representing the Value
-
-
-
Field Detail
-
data
private byte[] data
The data buffer.
-
currentPos
private int currentPos
The current position of the last byte in the data buffer
-
TRUE_VALUE
public static final byte TRUE_VALUE
The encoded byte for a TRUE value- See Also:
- Constant Field Values
-
FALSE_VALUE
public static final byte FALSE_VALUE
The encoded byte for a FALSE value- See Also:
- Constant Field Values
-
ENCODED_TRUE
private static final byte[] ENCODED_TRUE
Pre-encoded PDUs for a TRUE TLV
-
ENCODED_FALSE
private static final byte[] ENCODED_FALSE
Pre-encoded PDUs for a FALSE TLV
-
ONE_BYTE_MAX
private static final int ONE_BYTE_MAX
Integer limits for encoding : 0x7F- See Also:
- Constant Field Values
-
ONE_BYTE_MIN
private static final int ONE_BYTE_MIN
Integer limits for encoding : -0x7F- See Also:
- Constant Field Values
-
TWO_BYTE_MAX
private static final int TWO_BYTE_MAX
Integer limits for encoding : 0x7FFF- See Also:
- Constant Field Values
-
TWO_BYTE_MIN
private static final int TWO_BYTE_MIN
Integer limits for encoding : -0x7FFF- See Also:
- Constant Field Values
-
THREE_BYTE_MAX
private static final int THREE_BYTE_MAX
Integer limits for encoding : 0x7FFFFF- See Also:
- Constant Field Values
-
THREE_BYTE_MIN
private static final int THREE_BYTE_MIN
Integer limits for encoding : -0x7FFFFF- See Also:
- Constant Field Values
-
FOUR_BYTE_MAX
private static final long FOUR_BYTE_MAX
Integer limits for encoding : 0x7FFFFFFF- See Also:
- Constant Field Values
-
FOUR_BYTE_MIN
private static final long FOUR_BYTE_MIN
Integer limits for encoding : -0x7FFFFFFF- See Also:
- Constant Field Values
-
FIVE_BYTE_MAX
private static final long FIVE_BYTE_MAX
Integer limits for encoding : 0x7FFFFFFFFF- See Also:
- Constant Field Values
-
FIVE_BYTE_MIN
private static final long FIVE_BYTE_MIN
Integer limits for encoding : -0x7FFFFFFFFF- See Also:
- Constant Field Values
-
SIX_BYTE_MAX
private static final long SIX_BYTE_MAX
Integer limits for encoding : 0x7FFFFFFFFFFF- See Also:
- Constant Field Values
-
SIX_BYTE_MIN
private static final long SIX_BYTE_MIN
Integer limits for encoding : -0x7FFFFFFFFFFF- See Also:
- Constant Field Values
-
SEVEN_BYTE_MAX
private static final long SEVEN_BYTE_MAX
Integer limits for encoding : 0x7FFFFFFFFFFF- See Also:
- Constant Field Values
-
SEVEN_BYTE_MIN
private static final long SEVEN_BYTE_MIN
Integer limits for encoding : -0x7FFFFFFFFFFF- See Also:
- Constant Field Values
-
-
Method Detail
-
init
public void init(int size)
Initialize the Value- Parameters:
size- The data size to allocate.
-
reset
public void reset()
Reset the Value so that it can be reused
-
getData
public byte[] getData()
Get the Values'data- Returns:
- Returns the data.
-
setData
public void setData(ByteBuffer data)
Set a block of bytes in the Value- Parameters:
data- The data to set.
-
addData
public void addData(ByteBuffer buffer)
Append some bytes to the data buffer.- Parameters:
buffer- The data to append.
-
setData
public void setData(byte[] data)
Set a block of bytes in the Value- Parameters:
data- The data to set.
-
addData
public void addData(byte[] array)
Append some bytes to the data buffer.- Parameters:
array- The data to append.
-
getCurrentLength
public int getCurrentLength()
- Returns:
- The number of bytes actually stored
-
getNbBytes
public static int getNbBytes(int value)
Utility function that return the number of bytes necessary to store an integer value. Note that this value must be in [Integer.MIN_VALUE, Integer.MAX_VALUE].- Parameters:
value- The value to store in a byte array- Returns:
- The number of bytes necessary to store the value.
-
getNbBytes
public static int getNbBytes(long value)
Utility function that return the number of bytes necessary to store a long value. Note that this value must be in [Long.MIN_VALUE, Long.MAX_VALUE].- Parameters:
value- The value to store in a byte array- Returns:
- The number of bytes necessary to store the value.
-
getBytes
public static byte[] getBytes(int value)
Utility function that return a byte array representing the Value We must respect the ASN.1 BER encoding scheme :1) positive integer - [0 - 0x7F] : 0xVV - [0x80 - 0xFF] : 0x00 0xVV - [0x0100 - 0x7FFF] : 0xVV 0xVV - [0x8000 - 0xFFFF] : 0x00 0xVV 0xVV - [0x010000 - 0x7FFFFF] : 0xVV 0xVV 0xVV - [0x800000 - 0xFFFFFF] : 0x00 0xVV 0xVV 0xVV - [0x01000000 - 0x7FFFFFFF] : 0xVV 0xVV 0xVV 0xVV 2) Negative number - (~value) + 1
- Parameters:
value- The value to store in a byte array- Returns:
- The byte array representing the value.
-
getBytes
public static byte[] getBytes(long value)
Utility function that return a byte array representing the Value. We must respect the ASN.1 BER encoding scheme :
1) positive integer - [0 - 0x7F] : 0xVV - [0x80 - 0xFF] : 0x00 0xVV - [0x0100 - 0x7FFF] : 0xVV 0xVV - [0x8000 - 0xFFFF] : 0x00 0xVV 0xVV - [0x010000 - 0x7FFFFF] : 0xVV 0xVV 0xVV - [0x800000 - 0xFFFFFF] : 0x00 0xVV 0xVV 0xVV - [0x01000000 - 0x7FFFFFFF] : 0xVV 0xVV 0xVV 0xVV 2) Negative number - (~value) + 1
They are encoded following the table (the
encode bytes are those enclosed by squared braquets) :
-1 -> FF FF FF FF FF FF FF [FF] -127 -> FF FF FF FF FF FF FF [81] -128 -> FF FF FF FF FF FF FF [80] -129 -> FF FF FF FF FF FF [FF 7F] -255 -> FF FF FF FF FF FF [FF 01] -256 -> FF FF FF FF FF FF [FF 00] -257 -> FF FF FF FF FF FF [FE FF] -32767 -> FF FF FF FF FF FF [80 01] -32768 -> FF FF FF FF FF FF [80 00] -32769 -> FF FF FF FF FF [FF 7F FF] -65535 -> FF FF FF FF FF [FF 00 01] -65536 -> FF FF FF FF FF [FF 00 00] -65537 -> FF FF FF FF FF [FE FF FF] -8388607 -> FF FF FF FF FF [80 00 01] -8388608 -> FF FF FF FF FF [80 00 00] -8388609 -> FF FF FF FF [FF 7F FF FF] -16777215 -> FF FF FF FF [FF 00 00 01] -16777216 -> FF FF FF FF [FF 00 00 00] -16777217 -> FF FF FF FF [FE FF FF FF] -2147483647 -> FF FF FF FF [80 00 00 01] -2147483648 -> FF FF FF FF [80 00 00 00] -2147483649 -> FF FF FF [FF 7F FF FF FF] -4294967295 -> FF FF FF [FF 00 00 00 01] -4294967296 -> FF FF FF [FF 00 00 00 00] -4294967297 -> FF FF FF [FE FF FF FF FF] -549755813887 -> FF FF FF [80 00 00 00 01] -549755813888 -> FF FF FF [80 00 00 00 00] -549755813889 -> FF FF [FF 7F FF FF FF FF] -1099511627775 -> FF FF [FF 00 00 00 00 01] -1099511627776 -> FF FF [FF 00 00 00 00 00] -1099511627777 -> FF FF [FE FF FF FF FF FF] -140737488355327 -> FF FF [80 00 00 00 00 01] -140737488355328 -> FF FF [80 00 00 00 00 00] -140737488355329 -> FF [FF 7F FF FF FF FF FF] -281474976710655 -> FF [FF 00 00 00 00 00 01] -281474976710656 -> FF [FF 00 00 00 00 00 00] -281474976710657 -> FF [FE FF FF FF FF FF FF] -36028797018963967 -> FF [80 00 00 00 00 00 01] -36028797018963968 -> FF [80 00 00 00 00 00 00] -36028797018963969 -> [FF 7F FF FF FF FF FF FF] -72057594037927936 -> [FF 00 00 00 00 00 00 00] -72057594037927937 -> [FE FF FF FF FF FF FF FF] -9223372036854775807 -> [80 00 00 00 00 00 00 01] -9223372036854775808 -> [80 00 00 00 00 00 00 00]
- Parameters:
value- The value to store in a byte array- Returns:
- The byte array representing the value.
-
encodeBoolean
public static void encodeBoolean(org.apache.directory.api.asn1.util.Asn1Buffer buffer, boolean bool)Encode a boolean value- Parameters:
buffer- The PDU in which the value will be putbool- The boolean to be encoded
-
encodeBoolean
public static void encodeBoolean(org.apache.directory.api.asn1.util.Asn1Buffer buffer, byte tag, boolean bool)Encode a boolean value- Parameters:
buffer- The PDU in which the value will be puttag- the TAG to usebool- The boolean to be encoded
-
encodeInteger
public static void encodeInteger(org.apache.directory.api.asn1.util.Asn1Buffer buffer, int value)Encode an integer value- Parameters:
buffer- The PDU in which the value will be putvalue- The integer to be encoded
-
encodeInteger
public static void encodeInteger(org.apache.directory.api.asn1.util.Asn1Buffer buffer, byte tag, int value)Encode an integer value, with a specific tag- Parameters:
buffer- The PDU in which the value will be puttag- The tag to usevalue- The integer to be encoded
-
encodeInteger
public static void encodeInteger(org.apache.directory.api.asn1.util.Asn1Buffer buffer, long value)Encode an integer value- Parameters:
buffer- The PDU in which the value will be putvalue- The long to be encoded
-
encodeInteger
public static void encodeInteger(org.apache.directory.api.asn1.util.Asn1Buffer buffer, byte tag, long value)Encode an integer value, with a specific tag- Parameters:
buffer- The PDU in which the value will be puttag- The tag to usevalue- The long to be encoded
-
encodeOctetString
public static void encodeOctetString(org.apache.directory.api.asn1.util.Asn1Buffer buffer, byte[] data)Encode an OctetString- Parameters:
buffer- The PDU in which the value will be putdata- The byte[] to be encoded
-
encodeOctetString
public static void encodeOctetString(org.apache.directory.api.asn1.util.Asn1Buffer buffer, String value)Encode an OctetString- Parameters:
buffer- The PDU in which the value will be putvalue- The String to be encoded
-
encodeOctetString
public static void encodeOctetString(org.apache.directory.api.asn1.util.Asn1Buffer buffer, byte tag, byte[] data)Encode an OctetString- Parameters:
buffer- The PDU in which the value will be puttag- The tag to usedata- The OctetString to be encoded
-
encodeOctetString
public static void encodeOctetString(org.apache.directory.api.asn1.util.Asn1Buffer buffer, byte tag, String value)Encode an OctetString- Parameters:
buffer- The PDU in which the value will be puttag- The tag to usevalue- The OctetString to be encoded
-
encodeSequence
public static void encodeSequence(org.apache.directory.api.asn1.util.Asn1Buffer buffer)
Encode a Sequence- Parameters:
buffer- The PDU in which the Sequence will be put
-
encodeSequence
public static void encodeSequence(org.apache.directory.api.asn1.util.Asn1Buffer buffer, int start)Encode a Sequence, with a specific length- Parameters:
buffer- The PDU in which the Sequence will be putstart- The Sequence length
-
encodeSequence
public static void encodeSequence(org.apache.directory.api.asn1.util.Asn1Buffer buffer, byte tag)Encode a Sequence, with a specific tag- Parameters:
buffer- The PDU in which the Sequence will be puttag- The tag to use
-
encodeSequence
public static void encodeSequence(org.apache.directory.api.asn1.util.Asn1Buffer buffer, byte tag, int start)Encode a Sequence, with a specific length and tag- Parameters:
buffer- The PDU in which the Sequence will be puttag- The tag to usestart- The position in the buffer this Sequence starts
-
encodeSet
public static void encodeSet(org.apache.directory.api.asn1.util.Asn1Buffer buffer)
Encode a Set- Parameters:
buffer- The PDU in which the Set will be put
-
encodeSet
public static void encodeSet(org.apache.directory.api.asn1.util.Asn1Buffer buffer, int start)Encode a Set, with a specific length- Parameters:
buffer- The PDU in which the Set will be putstart- The Set length
-
encodeSet
public static void encodeSet(org.apache.directory.api.asn1.util.Asn1Buffer buffer, byte tag)Encode a Set, with a specific tag- Parameters:
buffer- The PDU in which the value will be puttag- The tag to use
-
encodeSet
public static void encodeSet(org.apache.directory.api.asn1.util.Asn1Buffer buffer, byte tag, int start)Encode a Set, with a specific length and tag- Parameters:
buffer- The PDU in which the set will be puttag- The tag to usestart- The position in the buffer this Set starts
-
encode
public static void encode(ByteBuffer buffer, String string) throws org.apache.directory.api.asn1.EncoderException
Encode a String value- Parameters:
buffer- The PDU in which the value will be putstring- The String to be encoded. It is supposed to be UTF-8- Throws:
org.apache.directory.api.asn1.EncoderException- if the PDU in which the value should be encoded is two small
-
encode
public static void encode(ByteBuffer buffer, org.apache.directory.api.asn1.util.BitString bitString) throws org.apache.directory.api.asn1.EncoderException
Encode a BIT STRING value- Parameters:
buffer- The PDU in which the value will be putbitString- The BitString to be encoded.- Throws:
org.apache.directory.api.asn1.EncoderException- if the PDU in which the value should be encoded is two small
-
encode
public static void encode(ByteBuffer buffer, byte[] bytes) throws org.apache.directory.api.asn1.EncoderException
Encode an OctetString value- Parameters:
buffer- The PDU in which the value will be putbytes- The bytes to be encoded- Throws:
org.apache.directory.api.asn1.EncoderException- if the PDU in which the value should be encoded is two small
-
encode
public static void encode(ByteBuffer buffer, org.apache.directory.api.asn1.util.Oid oid) throws org.apache.directory.api.asn1.EncoderException
Encode an OID value- Parameters:
buffer- The PDU in which the value will be putoid- The OID to be encoded- Throws:
org.apache.directory.api.asn1.EncoderException- if the PDU in which the value should be encoded is two small
-
encode
public static void encode(ByteBuffer buffer, int value) throws org.apache.directory.api.asn1.EncoderException
Encode an integer value- Parameters:
buffer- The PDU in which the value will be putvalue- The integer to be encoded- Throws:
org.apache.directory.api.asn1.EncoderException- if the PDU in which the value should be encoded is two small
-
encode
public static void encode(ByteBuffer buffer, long value) throws org.apache.directory.api.asn1.EncoderException
Encode a long value- Parameters:
buffer- The PDU in which the value will be putvalue- The long to be encoded- Throws:
org.apache.directory.api.asn1.EncoderException- if the PDU in which the value should be encoded is two small
-
encode
public static void encode(ByteBuffer buffer, byte tag, int value) throws org.apache.directory.api.asn1.EncoderException
Encode an integer value- Parameters:
buffer- The PDU in which the value will be puttag- The tag if it's not an UNIVERSAL onevalue- The integer to be encoded- Throws:
org.apache.directory.api.asn1.EncoderException- if the PDU in which the value should be encoded is two small
-
encodeEnumerated
public static void encodeEnumerated(org.apache.directory.api.asn1.util.Asn1Buffer buffer, int value)Encode an enumerated value- Parameters:
buffer- The PDU in which the value will be putvalue- The integer to be encoded
-
encodeEnumerated
public static void encodeEnumerated(org.apache.directory.api.asn1.util.Asn1Buffer buffer, byte tag, int value)Encode an enumerated value- Parameters:
buffer- The PDU in which the value will be puttag- The tag to usevalue- The integer to be encoded
-
encodeEnumerated
public static void encodeEnumerated(ByteBuffer buffer, int value) throws org.apache.directory.api.asn1.EncoderException
Encode an enumerated value- Parameters:
buffer- The PDU in which the value will be putvalue- The integer to be encoded- Throws:
org.apache.directory.api.asn1.EncoderException- if the PDU in which the value should be encoded is two small
-
encode
public static void encode(ByteBuffer buffer, boolean bool) throws org.apache.directory.api.asn1.EncoderException
Encode a boolean value- Parameters:
buffer- The PDU in which the value will be putbool- The boolean to be encoded- Throws:
org.apache.directory.api.asn1.EncoderException- if the PDU in which the value should be encoded is two small
-
-