ds.ov2.util
Class Resizable_buffer

java.lang.Object
  extended by ds.ov2.util.Resizable_buffer
All Implemented Interfaces:
APDU_Serializable

public class Resizable_buffer
extends Object
implements APDU_Serializable

APDU_Serializable wrapper around a byte array that can provide the illusion of different sizes. Used in the test frame for the OV-chip protocol layer. The resize method set_size is always available in contrast to the test-frame-only resize methods in the bignat library. The underlying byte array in buf does of course never change its size.

CPP Preprocessing
This class uses the following cpp defines: PACKAGE, PUBLIC, ASSERT, JAVACARD_APPLET
Execution Environment:
host, card
Author:
Hendrik Tews
Version:
$Revision: 1.12 $
Last Commit:
$Date: 2009-06-19 20:37:36 $ by $Author: tews $

Field Summary
 byte[] buf
          The buffer.
private  short size
          Current size of the buffer.
 
Constructor Summary
Resizable_buffer(short max_size)
          Convenience constructor for the host driver.
Resizable_buffer(short max_size, boolean in_ram)
          Normal constructor.
 
Method Summary
 short from_byte_array(short len, short this_index, byte[] byte_array, short byte_index)
          Deserialize this buffer.
 boolean is_compatible_with(Object o)
          Compatibility check for the OV-chip protocol layer.
 void set_size(short size)
          Set the pretended size.
 short size()
          Current pretended size in bytes.
 short to_byte_array(short len, short this_index, byte[] byte_array, short byte_index)
          Serialize this buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

size

private short size
Current size of the buffer. Is always smaller than buf.length.


buf

public byte[] buf
The buffer. The portion of the buffer that is used is determined by the size field.

Constructor Detail

Resizable_buffer

public Resizable_buffer(short max_size,
                        boolean in_ram)
Normal constructor.

Parameters:
max_size - maximal size of the buffer, this is also the initial pretended size
in_ram - allocate in transient RAM memory on the card

Resizable_buffer

public Resizable_buffer(short max_size)
Convenience constructor for the host driver. Calls Resizable_buffer(max_size, false).

Only available if JAVACARD_APPLET is not defined.

Parameters:
max_size - maximal size of the buffer, this is also the initial pretended size
Method Detail

size

public short size()
Current pretended size in bytes. Size for the OV-chip protocol layer, see APDU_Serializable.size().

Specified by:
size in interface APDU_Serializable
Returns:
pretended size in bytes

set_size

public void set_size(short size)
Set the pretended size. If size is larger than the constructor argument max_size, which determines the length of the underlying byte array buf, the set size request is ignored.

Parameters:
size - new pretended size, should be smaller than the max_size argument of the constructor.

is_compatible_with

public boolean is_compatible_with(Object o)
Compatibility check for the OV-chip protocol layer. See the compatibility check explanations and also APDU_Serializable.is_compatible_with.

This object is only compatible to instances of this class with the same pretended size.

Specified by:
is_compatible_with in interface APDU_Serializable
Parameters:
o - actual argument or result
Returns:
true if o is an instance of Resizable_buffer with the same pretended size

to_byte_array

public short to_byte_array(short len,
                           short this_index,
                           byte[] byte_array,
                           short byte_index)
Serialize this buffer. See APDU_Serializable.to_byte_array.

Specified by:
to_byte_array in interface APDU_Serializable
Parameters:
len - available space in byte_array
this_index - number of bytes that have already been written in preceeding calls
byte_array - data array to serialize the state into
byte_index - index in byte_array
Returns:
the number of bytes actually written, except for the case where serialization finished by writing precisely len bytes, in this case len + 1 is returned.

from_byte_array

public short from_byte_array(short len,
                             short this_index,
                             byte[] byte_array,
                             short byte_index)
Deserialize this buffer. See APDU_Serializable.from_byte_array.

Specified by:
from_byte_array in interface APDU_Serializable
Parameters:
len - available data in byte_array
this_index - number of bytes that have already been read in preceeding calls
byte_array - data array to deserialize from
byte_index - index in byte_array
Returns:
the number of bytes actually read, except for the case where deserialization finished by reading precisely len bytes, in this case len + 1 is returned.