FileDocCategorySizeDatePackage
RecordStoreUtil.javaAPI DocphoneME MR2 API (J2ME)6745Wed May 02 18:00:12 BST 2007com.sun.midp.rms

RecordStoreUtil

public class RecordStoreUtil extends Object
A class implementing record store utility functions.

Fields Summary
Constructors Summary
Methods Summary
static intcalculateBlockSize(int dataSize)
A convenience method for calculating the block size given the data size.

param
dataSize the size of the data in the block.
return
an int corresponding to the size of the block padded to a multiple of the BLOCK HEADER SIZE.

        final int block_header_size = AbstractRecordStoreImpl.BLOCK_HEADER_SIZE;
        int remainder = dataSize % block_header_size; // & 0x07;

        if (remainder == 0) {
            return dataSize + block_header_size;
        } else {
            return dataSize + (block_header_size - remainder) +
                block_header_size;
        }
    
static native voiddeleteFile(int suiteId, java.lang.String name, int extension)
Removes the storage file for record store filename if it exists.

param
suiteId ID of the MIDlet suite that owns the record store
param
name name of the record store
param
extension the extension for the record store file
throws
RecordStoreException if deletion encountered an error internally.

static native booleanexists(int suiteId, java.lang.String name, int extension)
Looks to see if the storage file for record store identified by uidPath exists

param
suiteId ID of the MIDlet suite that owns the record store
param
name name of the record store
param
extension the extension for the record store file
return
true if the file exists, false if it does not.

static intgetInt(byte[] data, int offset)
A convenience method for converting a byte array into an int (assumes big-endian byte ordering).

param
data the byte array returned from the database.
param
offset the offset into the array of the first byte to start from.
return
an int corresponding to the first four bytes of the array passed in.

        int r = data[offset++];
        r = (r << 8) | ((int)(data[offset++]) & 0xff);
        r = (r << 8) | ((int)(data[offset++]) & 0xff);
        r = (r << 8) | ((int)(data[offset++]) & 0xff);
        return r;
    
static longgetLong(byte[] data, int offset)
A convenience method for converting a byte array into a long (assumes big-endian byte ordering).

param
data the byte array returned from the database.
param
offset the offset into the array of the first byte to start from.
return
a long corresponding to the first eight bytes of the array passed in.

        long r = data[offset++];
        r = (r << 8) | ((long)(data[offset++]) & 0xff);
        r = (r << 8) | ((long)(data[offset++]) & 0xff);
        r = (r << 8) | ((long)(data[offset++]) & 0xff);
        r = (r << 8) | ((long)(data[offset++]) & 0xff);
        r = (r << 8) | ((long)(data[offset++]) & 0xff);
        r = (r << 8) | ((long)(data[offset++]) & 0xff);
        r = (r << 8) | ((long)(data[offset++]) & 0xff);
        return r;
    
static intputInt(int i, byte[] data, int offset)
A convenience method for converting an integer into a byte array.

param
i the integer to turn into a byte array.
param
data a place to store the bytes of i.
param
offset starting point within data to store i.
return
the number of bytes written to the array.

        data[offset++] = (byte)((i >> 24) & 0xff);
        data[offset++] = (byte)((i >> 16) & 0xff);
        data[offset++] = (byte)((i >> 8) & 0xff);
        data[offset] = (byte)(i & 0xff);
        return 4;
    
static intputLong(long l, byte[] data, int offset)
A convenience method for converting a long into a byte array.

param
l the long to turn into a byte array.
param
data a place to store the bytes of l.
param
offset Starting point within data to store l.
return
the number of bytes written to the array.

        data[offset++] = (byte)((l >> 56) & 0xff);
        data[offset++] = (byte)((l >> 48) & 0xff);
        data[offset++] = (byte)((l >> 40) & 0xff);
        data[offset++] = (byte)((l >> 32) & 0xff);
        data[offset++] = (byte)((l >> 24) & 0xff);
        data[offset++] = (byte)((l >> 16) & 0xff);
        data[offset++] = (byte)((l >> 8) & 0xff);
        data[offset] = (byte)(l & 0xff);
        return 8;
    
static booleanquietDeleteFile(int suiteId, java.lang.String name, int extension)
Removes record store file without throwing an exception on failure.

param
suiteId ID of the MIDlet suite that owns the record store
param
name name of the record store
param
extension the extension for the record store file
return
true if file was found and deleted successfully, false otherwise.

        try {
            deleteFile(suiteId, name, extension);
        } catch (Throwable t) {
            return false;
        }
        return true;