OpenCard  
 
OCF, the OpenCard Framework is a standard Java framework for working with Smart Cards.  
 

com.ibm.opencard.buffer
Class TLVBuffer

java.lang.Object
  |
  +--com.ibm.opencard.buffer.Buffer
        |
        +--com.ibm.opencard.buffer.TLVBuffer

public class TLVBuffer
extends Buffer

TLVBuffer objects are used to store a sequence of ASN.1 BER encoded TLVs.
A VariableTLVBuffer object has a certain capacity which is determined by the size of the byte array provided to the constructor. If this capacity is exceeded by adding new entries, the capacity is increased by reallocation of memory. If you want to avoid reallocation of memory for performance reasons, you should provided a byte array of sufficient size to the constructor.

Version:
$Id: TLVBuffer.java,v 1.1 1999/12/02 16:06:02 damke Exp $
See Also:
Request, Buffer

Constructor Summary
TLVBuffer(byte[] data, int size)
          Creates a new Buffer from a given byte arra and size.
 
Method Summary
 TLVBuffer addDataEntry(byte[] id, byte[] value)
          Add an entry with given id, which contains the given data to this buffer.
 TLVBuffer addDataEntry(java.lang.String id, byte[] value)
          Add an entry with given id, which contains the given data to this buffer.
 TLVBuffer addTLV(TLV tlv)
          Add a TLV.
 TLVBuffer addValueEntry(java.lang.String id, int value)
          Add an entry with given id, which contains the given positive integer value to this buffer.
 TLVBuffer append(byte[] b)
          Append the contents of a given byte arras to the contents of this buffer.
 boolean check()
          Check the validity of the TLV buffer.
 void clear()
          Clears this buffer.
 TLV findTLV(Tag tag, int[] off)
          Find the next TLV with the given tag.
 byte[] getData(byte[] id)
          Get the data from the entry with the given id.
 byte[] getData(java.lang.String id)
          Get the data from the entry with the given id.
 int getValue(java.lang.String id)
          Get the value from the entry with the given id.
 TLVBuffer removeEntry(byte[] id)
          Remove the first entry with the given id.
 TLVBuffer removeEntry(java.lang.String id)
          Remove the first entry with the given id.
 TLVBuffer set(byte[] b)
          Set the contents of this data buffer to a given byte array.
 java.lang.String toString()
          Return the textual representation of this TLV buffer.
 
Methods inherited from class com.ibm.opencard.buffer.Buffer
data, size, toHexString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TLVBuffer

public TLVBuffer(byte[] data,
                 int size)
Creates a new Buffer from a given byte arra and size.
Parameters:
data - A byte array containing data
size - The size of valid data contained in the data array. If this size is bigger than the actual length of the byte array, it is set to the length of the byte array.
Method Detail

clear

public void clear()
Clears this buffer.
Overrides:
clear in class Buffer

addTLV

public TLVBuffer addTLV(TLV tlv)
Add a TLV.
Parameters:
tlv - The TLV to be added.
Returns:
This VariableTLVBuffer object

findTLV

public TLV findTLV(Tag tag,
                   int[] off)
Find the next TLV with the given tag.
Parameters:
tag - The TLV to be added.
Returns:
The TLV with the given tag on success, null otherwise.

toString

public java.lang.String toString()
Return the textual representation of this TLV buffer.
Overrides:
toString in class Buffer

addValueEntry

public TLVBuffer addValueEntry(java.lang.String id,
                               int value)
Add an entry with given id, which contains the given positive integer value to this buffer. An 'entry' is a TLV looking like this: DATA_ENTRY ( ID( id ) DATA( value ) )
Parameters:
id - The ID for the new entry.
value - The positive integer to be stored in the new entry.
Returns:
This Buffer object

addDataEntry

public TLVBuffer addDataEntry(java.lang.String id,
                              byte[] value)
Add an entry with given id, which contains the given data to this buffer. An 'entry' is a TLV looking like this: DATA_ENTRY ( ID( id ) DATA( value ) )
Parameters:
id - The ID for the new entry.
value - The data to be stored in the new entry.
Returns:
This Buffer object

addDataEntry

public TLVBuffer addDataEntry(byte[] id,
                              byte[] value)
Add an entry with given id, which contains the given data to this buffer. An 'entry' is a TLV looking like this: DATA_ENTRY ( ID( id ) DATA( value ) )
Parameters:
id - The ID for the new entry.
value - The data to be stored in the new entry.
Returns:
This Buffer object

getValue

public int getValue(java.lang.String id)
Get the value from the entry with the given id.
Parameters:
id - The ID to be searched for.
Returns:
The positive integer value stored under the given ID on success, -1 otherwise.

getData

public byte[] getData(java.lang.String id)
Get the data from the entry with the given id.
Parameters:
id - The ID to be searched for.
Returns:
The data stored under the given ID on success, null otherwise.

getData

public byte[] getData(byte[] id)
Get the data from the entry with the given id.
Parameters:
id - The ID to be searched for.
Returns:
The data stored under the given ID on success, null otherwise.

check

public boolean check()
Check the validity of the TLV buffer.

removeEntry

public TLVBuffer removeEntry(java.lang.String id)
Remove the first entry with the given id.
Parameters:
id - The id of the entry to be removed.
Returns:
This Buffer object

removeEntry

public TLVBuffer removeEntry(byte[] id)
Remove the first entry with the given id.
Parameters:
id - The id of the entry to be removed.
Returns:
This Buffer object

append

public TLVBuffer append(byte[] b)
Append the contents of a given byte arras to the contents of this buffer.
Parameters:
b - The byte array to be appended to the buffer.
Returns:
This Buffer object

set

public TLVBuffer set(byte[] b)
Set the contents of this data buffer to a given byte array. All previous data is lost.
Parameters:
b - The byte array to be copied into the buffer.
Returns:
This Buffer object