Class MifareWriter

java.lang.Object
  extended by MifareWriter
All Implemented Interfaces:
java.lang.Runnable

public class MifareWriter
extends java.lang.Object
implements java.lang.Runnable

MifareWriter is responsible for communication with the java card application

Since:
1.0
Author:
Magnus Egeberg

Field Summary
private  byte[] buf
           
private  java.lang.String BUSY_READING_TICKET
           
private  java.lang.String BUSY_SAVING_TICKET
           
private  java.lang.String BUSY_TICKET_READ
           
private  java.lang.String BUSY_TICKET_SAVED
           
private static byte CMD_TICKET
           
private  ConfirmationAlert confAlert
           
private  java.lang.String CONFIRMATION_TITLE
           
private  int count
           
private static byte[] MF_PASSWORD
           
private  byte[] newTotal
           
private  boolean read
           
private  byte[] readticket
           
private  SecureChipHandler secureChip
           
private static byte[] SELECT
           
private  TicketingSystemMIDlet ts
           
private  int value
           
private  byte[] writeticket
           
 
Constructor Summary
MifareWriter(SecureChipHandler sc, TicketingSystemMIDlet ts, byte[] data, boolean read)
          Initiates the communication with the MIFARE memory
 
Method Summary
private static java.lang.String getHexString(byte[] data)
          Converts a byte array to string representation
private  int getShort(byte[] data)
          Reads a short and return it as an int
 void getTicket()
          Reads the existing ticket
 byte[] readFromChip(int pos)
          Reads the ticket from the MIFARE memory
 void run()
          Sets the communication mode of the secure chip to internal Identifies the operation, either read or write
private  void sleep()
          Puts the current thread to sleep
private  void update()
          Gets the existing credit on the secure chip and adds the credit from the new ticket
 void writeShort(int theShort)
          Writes an int to a short
private  void writeToChip(int pos, byte[] ticket)
          Writes to the MIFARE memory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CONFIRMATION_TITLE

private final java.lang.String CONFIRMATION_TITLE
See Also:
Constant Field Values

BUSY_READING_TICKET

private final java.lang.String BUSY_READING_TICKET
See Also:
Constant Field Values

BUSY_SAVING_TICKET

private final java.lang.String BUSY_SAVING_TICKET
See Also:
Constant Field Values

BUSY_TICKET_SAVED

private final java.lang.String BUSY_TICKET_SAVED
See Also:
Constant Field Values

BUSY_TICKET_READ

private final java.lang.String BUSY_TICKET_READ
See Also:
Constant Field Values

buf

private byte[] buf

newTotal

private byte[] newTotal

readticket

private byte[] readticket

writeticket

private byte[] writeticket

count

private int count

value

private int value

confAlert

private ConfirmationAlert confAlert

secureChip

private SecureChipHandler secureChip

ts

private TicketingSystemMIDlet ts

read

private boolean read

CMD_TICKET

private static final byte CMD_TICKET
See Also:
Constant Field Values

MF_PASSWORD

private static final byte[] MF_PASSWORD

SELECT

private static final byte[] SELECT
Constructor Detail

MifareWriter

public MifareWriter(SecureChipHandler sc,
                    TicketingSystemMIDlet ts,
                    byte[] data,
                    boolean read)
Initiates the communication with the MIFARE memory

Parameters:
sc - The handler of the communication with the secure chip
ts - The MIDlet
data - The new ticket
read - The task to be done, true when read
Method Detail

run

public void run()
Sets the communication mode of the secure chip to internal Identifies the operation, either read or write

Specified by:
run in interface java.lang.Runnable

update

private void update()
Gets the existing credit on the secure chip and adds the credit from the new ticket


writeToChip

private void writeToChip(int pos,
                         byte[] ticket)
                  throws java.io.IOException,
                         APDUCommandException,
                         java.lang.Exception
Writes to the MIFARE memory

Parameters:
pos - The block number to write
ticket - The ticket to write
Throws:
java.io.IOException
APDUCommandException
java.lang.Exception

getTicket

public void getTicket()
Reads the existing ticket


readFromChip

public byte[] readFromChip(int pos)
                    throws java.io.IOException,
                           APDUCommandException
Reads the ticket from the MIFARE memory

Parameters:
pos - The block # to read
Returns:
The ticket that is read
Throws:
java.io.IOException
APDUCommandException

getHexString

private static java.lang.String getHexString(byte[] data)
Converts a byte array to string representation

Parameters:
data - The byte array to
Returns:
the string representation of the byte array

getShort

private int getShort(byte[] data)
Reads a short and return it as an int

Returns:
The int value of the bytes
Throws:
java.lang.Exception - when failing to read the short
See Also:
ByteArrayInputStream, DataInputStream

writeShort

public void writeShort(int theShort)
                throws java.lang.Exception
Writes an int to a short

Parameters:
theShort - The int value to write
Throws:
java.lang.Exception
See Also:
ByteArrayOutputStream, DataOutputStream

sleep

private void sleep()
Puts the current thread to sleep