FileDocCategorySizeDatePackage
WimFileSystem.javaAPI DocphoneME MR2 API (J2ME)4187Wed May 02 18:00:38 BST 2007com.sun.satsa.pki

WimFileSystem

public class WimFileSystem extends FileSystemAbstract
This class provides interface to WIM file system.

Fields Summary
private int
CARD_BUFFER
Constant defines size of the card buffer
private int
P1_P2
Constant defines parameters P1, P2 in the apdu command
Constructors Summary
public WimFileSystem(Connection apdu)
Constructs new WimFileSystem object.

param
apdu connection to be used by this object.


                      
       
        super(apdu);
        apdu.setCLAbyte((byte)0x80);
    
Methods Summary
public byte[]readData(int offset, int length, int fileOffset)
Reads part of selected file.

param
offset the offset into data buffer where data should be placed
param
length data length
param
fileOffset file data offset
throws
IOException if IO error occurs
return
data byte array of the data

        byte[] data = new byte[length + offset];
        while (length != 0) {
            int len = length > CARD_BUFFER ? CARD_BUFFER : length;
            byte[] result = apdu.resetCommand().
                           sendCommand(INS_READ, fileOffset, len, true);
           System.arraycopy(result, 0, data, offset, len);
            offset += len;
            fileOffset += len;
            length -= len;
        }
        return data;
    
public voidselect(short id)
Selects file by ID.

param
id file ID
throws
IOException if IOError occurs


        byte[] data = apdu.resetCommand().
                           putShort(id).
                           sendCommand(INS_SELECT, P1_P2);

        isEFSelected = false;
        currentFileSize = 0;

        if (data.length == 2) {
            return;       // FCI is empty
        }

        TLV t;              // parse FCI
        try {
            t = new TLV(data, 0);
        } catch (TLVException e) {
            throw new IOException();
        }

        t = t.child;
        while (t != null) {
            if (t.type == 0x80) {
                isEFSelected = true;
                currentFileSize = Utils.getU2(data, t.valueOffset);
                return;
            }
            t = t.next;
        }
        return;
    
public voidwriteData(byte[] data, int offset, int length, int fileOffset)
Writes data into selected file.

param
data buffer that contains data
param
offset offset of data in the buffer
param
length length of data in the buffer
param
fileOffset offset of updated data in the file
throws
IOException if I/O error occurs


        while (length != 0) {
            int len = length > CARD_BUFFER ? CARD_BUFFER : length;
            apdu.resetCommand().
                 putBytes(data, offset, len).
                 sendCommand(INS_UPDATE, fileOffset, len, true);
            offset += len;
            fileOffset += len;
            length -= len;
        }