Class 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
    • data is an optional byte array of data received from the smart card.
    • SW1 is the status byte 1 containing command processing status.
    • SW2 is the status byte 2 containing command processing qualifier.

    Usage

    1.    byte[] buffer = {(byte)0x01, (byte)0x02, (byte)0x90, (byte)0x00};
         ResponseAPDU rapdu = new ResponseAPDU(buffer); 
    2.    OneWireContainer16 owc16 = new OneWireContainer16(adapter, address);
         byte[] buffer = {(byte)0x90, (byte)0x00, (byte)0x00, (byte)0x00, 
                          (byte)0x01, (byte)0x02, (byte)0x03};
         CommandAPDU capdu = new CommandAPDU(buffer);
         ResponseAPDU rapdu = owc16.sendAPDU(capdu, runTime); 

    Additional information

    http://www.opencard.org
    See Also:
    CommandAPDU, com.dalsemi.onewire.container.OneWireContainer16
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected byte[] apduBuffer
      byte array containing the entire ResponseAPDU
      protected int apduLength
      length of this ResponseAPDU currently in the apduBuffer
    • Constructor Summary

      Constructors 
      Constructor Description
      ResponseAPDU​(byte[] buffer)
      Constructs a new ResponseAPDU with the given buffer byte array.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte getByte​(int index)
      Gets the byte value at the specified offset in apduBuffer.
      byte[] getBytes()
      Gets a byte array holding this ResponseAPDU apduBuffer.
      byte[] getData()
      Gets the data field of this ResponseAPDU.
      int getLength()
      Gets the length of apduBuffer.
      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

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • apduBuffer

        protected byte[] apduBuffer
        byte array containing the entire ResponseAPDU
      • apduLength

        protected int apduLength
        length of this ResponseAPDU currently in the apduBuffer
    • Constructor Detail

      • ResponseAPDU

        public ResponseAPDU​(byte[] buffer)
        Constructs a new ResponseAPDU with the given buffer byte array. The internal apduLength 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 length < 2.
        See Also:
        CommandAPDU
    • Method Detail

      • getData

        public byte[] getData()
        Gets the data field of this ResponseAPDU.
        Returns:
        a byte array containing this 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:
        (((SW1 << 8) & 0xFF00) | (SW2 & 0xFF)) as an 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 offset in apduBuffer.
        Parameters:
        index - the offset in the apduBuffer
        Returns:
        the value at the given offset, or -1 if the offset is invalid
        See Also:
        getBytes(), getLength()
      • getBytes

        public final byte[] getBytes()
        Gets a byte array holding this ResponseAPDU apduBuffer.
        Returns:
        apduBuffer copied into a new array
        See Also:
        getByte(int), getLength()
      • getLength

        public final int getLength()
        Gets the length of apduBuffer.
        Returns:
        apduLength the length of the apduBuffer 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