Search in sources :

Example 6 with RecordStoreException

use of javax.microedition.rms.RecordStoreException in project J2ME-Loader by nikita36078.

the class RecordStoreImpl method getSize.

@Override
public int getSize() throws RecordStoreNotOpenException {
    if (!open) {
        throw new RecordStoreNotOpenException();
    }
    // TODO include size overhead such as the data structures used to hold the state of the record store
    // Preload all records
    enumerateRecords(null, null, false);
    int result = 0;
    Enumeration keys = records.keys();
    while (keys.hasMoreElements()) {
        int key = ((Integer) keys.nextElement()).intValue();
        try {
            byte[] data = getRecord(key);
            if (data != null) {
                result += data.length;
            }
        } catch (RecordStoreException e) {
            e.printStackTrace();
        }
    }
    return result;
}
Also used : RecordStoreNotOpenException(javax.microedition.rms.RecordStoreNotOpenException) Enumeration(java.util.Enumeration) RecordEnumeration(javax.microedition.rms.RecordEnumeration) RecordStoreException(javax.microedition.rms.RecordStoreException)

Aggregations

RecordStoreException (javax.microedition.rms.RecordStoreException)6 IOException (java.io.IOException)5 DataInputStream (java.io.DataInputStream)2 DataOutputStream (java.io.DataOutputStream)2 RecordEnumeration (javax.microedition.rms.RecordEnumeration)2 RecordStoreNotFoundException (javax.microedition.rms.RecordStoreNotFoundException)2 FileNotFoundException (java.io.FileNotFoundException)1 Enumeration (java.util.Enumeration)1 RecordStoreNotOpenException (javax.microedition.rms.RecordStoreNotOpenException)1