com.dalsemi.onewire.container
Class ResponseAPDU

java.lang.Object
  |
  +--com.dalsemi.onewire.container.ResponseAPDU

public class ResponseAPDU
extends java.lang.Object

A ResponseAPDU represents an Application Protocol Data Unit (APDU) received from the smart card in response to a previous CommandAPDU. A ResponseAPDU consists of an optional body and a mandatory Status Word (SW).

According to ISO 7816-4, a ResponseAPDU has the following format:

          DATA   |  STATUS WORD
         [data]  |  SW1     SW2

 
where

Version:
0.00, 28 Aug 2000

Constructor Summary
ResponseAPDU(byte[] buffer)
          Constructs a new ResponseAPDU initialized with the given buffer byte array.
 
Method Summary
 byte getByte(int index)
          Gets the byte value at the specified position in the internal buffer.
 byte[] getBytes()
          Gets a byte array holding the internal ResponseAPDU buffer.
 byte[] getData()
          Gets the data field of the ResponseAPDU.
 int getLength()
          Gets the length of the internal buffer.
 int getSW()
          Gets the value of SW1 and SW2 as an integer.
 byte getSW1()
          Gets the value of SW1.
 byte getSW2()
          Gets the value of SW2.
 java.lang.String toString()
          Gets a string representation of this ResponseAPDU.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ResponseAPDU

public ResponseAPDU(byte[] buffer)
Constructs a new ResponseAPDU initialized with the given buffer byte array. The internal buffer length is set to the length of the buffer passed.
Parameters:
buffer - the byte array with data for the internal apduBuffer.
Throws:
java.lang.RuntimeException - thrown when buffer is invalid.
See Also:
getLength()
Method Detail

getData

public byte[] getData()
Gets the data field of the ResponseAPDU.
Returns:
a byte array containing the ResponseAPDU data field.

getSW

public final int getSW()
Gets the value of SW1 and SW2 as an integer. It is computed as: (((SW1<<8) & 0xFF00) | (SW2 & 0xFF)).
Returns:
value (((SW1<<8) & 0xFF00) | (SW2 & 0xFF)) as integer.

getSW1

public final byte getSW1()
Gets the value of SW1.
Returns:
value of SW1 as a byte.

getSW2

public final byte getSW2()
Gets the value of SW2.
Returns:
value of SW2 as a byte.

getByte

public final byte getByte(int index)
Gets the byte value at the specified position in the internal buffer.
Parameters:
index - the position in the buffer
Returns:
the value at the given position, or -1 if the position is invalid
See Also:
getLength()

getBytes

public final byte[] getBytes()
Gets a byte array holding the internal ResponseAPDU buffer.
Returns:
the internal buffer copied into a new array.

getLength

public final int getLength()
Gets the length of the internal buffer.
Returns:
the length of the buffer currently stored

toString

public java.lang.String toString()
Gets a string representation of this ResponseAPDU.
Overrides:
toString in class java.lang.Object
Returns:
a string describing this ResponseAPDU.