org.apache.asn1new.ber.tlv
Class Value

java.lang.Object
  extended byorg.apache.asn1new.ber.tlv.Value
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class Value
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

This class stores the data decoded from a TLV.

Author:
Apache Directory Project
See Also:
Serialized Form

Field Summary
private  int currentPos
          The current position of the last byte in the data buffer
private  byte[] data
          The data buffer.
private static byte[] ENCODED_FALSE
           
private static byte[] ENCODED_TRUE
          Pre-encoded PDUs for a TRUE and FALSE TLV
static byte FALSE_VALUE
          The encoded byte for a FALSE value
private static int FOUR_BYTE_MAX
           
private static int FOUR_BYTE_MIN
           
private static int ONE_BYTE_MAX
          Integer limits for encoding
private static int ONE_BYTE_MIN
           
static long serialVersionUID
           
private static int THREE_BYTE_MAX
           
private static int THREE_BYTE_MIN
           
static byte TRUE_VALUE
          The encoded byte for a TRUE value
private static int TWO_BYTE_MAX
           
private static int TWO_BYTE_MIN
           
 
Constructor Summary
Value()
          The constructor.
Value(byte[] value)
          The constructor.
 
Method Summary
 void addData(byte[] data)
          Append some bytes to the data buffer.
 void addData(java.nio.ByteBuffer data)
          Append some bytes to the data buffer.
 java.lang.Object clone()
          Clone the Value
static void encode(java.nio.ByteBuffer buffer, boolean bool)
          Encode a boolean value
static void encode(java.nio.ByteBuffer buffer, byte[] bytes)
          Encode an OctetString value
static void encode(java.nio.ByteBuffer buffer, int value)
          Encode an integer value
static void encode(java.nio.ByteBuffer buffer, OctetString string)
          Encode an OctetString value
static void encode(java.nio.ByteBuffer buffer, OID oid)
          Encode an OID value
static void encode(java.nio.ByteBuffer buffer, java.lang.String string)
          Encode a String value
static void encodeEnumerated(java.nio.ByteBuffer buffer, int value)
          Encode an enumerated value
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 - [0x80000000 - 0xFFFFFFFF] : 0x00 0xVV 0xVV 0xVV 0xVV 2) Negative number - (~value) + 1
 int getCurrentLength()
           
 byte[] getData()
          Get the Values'data
static int getNbBytes(int value)
          Utility function that return the number of bytes necessary to store an integer value.
 void init(int size)
          Initialize the Value
 void reset()
          Reset the Value so that it can be reused
 void setData(byte[] data)
          Set a block of bytes in the Value
 void setData(java.nio.ByteBuffer data)
          Set a block of bytes in the Value
 java.lang.String toString()
          Return a string representing the Value
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

public static final long serialVersionUID
See Also:
Constant Field Values

data

private byte[] data
The data buffer. TODO Create a streamed data to store large data


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 and FALSE TLV


ENCODED_FALSE

private static final byte[] ENCODED_FALSE

ONE_BYTE_MAX

private static final int ONE_BYTE_MAX
Integer limits for encoding

See Also:
Constant Field Values

ONE_BYTE_MIN

private static final int ONE_BYTE_MIN
See Also:
Constant Field Values

TWO_BYTE_MAX

private static final int TWO_BYTE_MAX
See Also:
Constant Field Values

TWO_BYTE_MIN

private static final int TWO_BYTE_MIN
See Also:
Constant Field Values

THREE_BYTE_MAX

private static final int THREE_BYTE_MAX
See Also:
Constant Field Values

THREE_BYTE_MIN

private static final int THREE_BYTE_MIN
See Also:
Constant Field Values

FOUR_BYTE_MAX

private static final int FOUR_BYTE_MAX
See Also:
Constant Field Values

FOUR_BYTE_MIN

private static final int FOUR_BYTE_MIN
See Also:
Constant Field Values
Constructor Detail

Value

public Value(byte[] value)
The constructor.


Value

public Value()
The constructor.

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


clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Clone the Value

Returns:
An object that is a copy of this Value
Throws:
java.lang.CloneNotSupportedException - Thrown when the cloning failed

getData

public byte[] getData()
Get the Values'data

Returns:
Returns the data.

setData

public void setData(java.nio.ByteBuffer data)
Set a block of bytes in the Value

Parameters:
data - The data to set.

addData

public void addData(java.nio.ByteBuffer data)
Append some bytes to the data buffer.

Parameters:
data - 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[] data)
Append some bytes to the data buffer.

Parameters:
data - 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.

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 - [0x80000000 - 0xFFFFFFFF] : 0x00 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.

encode

public static void encode(java.nio.ByteBuffer buffer,
                          java.lang.String string)
                   throws org.apache.asn1.codec.EncoderException
Encode a String value

Parameters:
buffer - The PDU in which the value will be put
string - The String to be encoded. It is supposed to be UTF-8
Throws:
org.apache.asn1.codec.EncoderException

encode

public static void encode(java.nio.ByteBuffer buffer,
                          OctetString string)
                   throws org.apache.asn1.codec.EncoderException
Encode an OctetString value

Parameters:
buffer - The PDU in which the value will be put
string - The OctetString to be encoded
Throws:
org.apache.asn1.codec.EncoderException

encode

public static void encode(java.nio.ByteBuffer buffer,
                          byte[] bytes)
                   throws org.apache.asn1.codec.EncoderException
Encode an OctetString value

Parameters:
buffer - The PDU in which the value will be put
Throws:
org.apache.asn1.codec.EncoderException

encode

public static void encode(java.nio.ByteBuffer buffer,
                          OID oid)
                   throws org.apache.asn1.codec.EncoderException
Encode an OID value

Parameters:
buffer - The PDU in which the value will be put
Throws:
org.apache.asn1.codec.EncoderException

encode

public static void encode(java.nio.ByteBuffer buffer,
                          int value)
                   throws org.apache.asn1.codec.EncoderException
Encode an integer value

Parameters:
buffer - The PDU in which the value will be put
value - The integer to be encoded
Throws:
org.apache.asn1.codec.EncoderException

encodeEnumerated

public static void encodeEnumerated(java.nio.ByteBuffer buffer,
                                    int value)
                             throws org.apache.asn1.codec.EncoderException
Encode an enumerated value

Parameters:
buffer - The PDU in which the value will be put
value - The integer to be encoded
Throws:
org.apache.asn1.codec.EncoderException

encode

public static void encode(java.nio.ByteBuffer buffer,
                          boolean bool)
                   throws org.apache.asn1.codec.EncoderException
Encode a boolean value

Parameters:
buffer - The PDU in which the value will be put
bool - The boolean to be encoded
Throws:
org.apache.asn1.codec.EncoderException

toString

public java.lang.String toString()
Return a string representing the Value

Returns:
A string representing the value


Copyright © 2005-2006 . All Rights Reserved.