javax.microedition.rms.RecordStore Java Examples

The following examples show how to use javax.microedition.rms.RecordStore. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BlackBerryImplementation.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void flush() throws IOException {
    if (cache != null) {
        byte[] data = cache.toByteArray();
        if (data.length > 0) {
            RecordStore r = null;
            try {
                r = RecordStore.openRecordStore("" + letter + key, true);
                r.addRecord(data, 0, data.length);
                r.closeRecordStore();
                if (letter == 'Z') {
                    letter = 'a';
                } else {
                    letter++;
                }
                cache.reset();
            } catch (RecordStoreException ex) {
                ex.printStackTrace();
                cleanup(r);
                throw new IOException(ex.toString());
            }
        }
    }
}
 
Example #2
Source File: GameCanvasImplementation.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @inheritDoc
 */
public void cleanup(Object o) {
    try {
        if(o != null) {
            if(o instanceof Connection) {
                ((Connection) o).close();
                return;
            } 
            if(o instanceof RecordEnumeration) {
                ((RecordEnumeration) o).destroy();
                return;
            }
            if(o instanceof RecordStore) {
                ((RecordStore) o).closeRecordStore();
                return;
            }
            super.cleanup(o);
        }
    } catch (Throwable ex) {
        ex.printStackTrace();
    }
}
 
Example #3
Source File: BlackBerryImplementation.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @inheritDoc
 */
public void cleanup(Object o) {
    try {
        if (o != null) {
            if (o instanceof Connection) {
                ((Connection) o).close();
                return;
            }
            if (o instanceof RecordEnumeration) {
                ((RecordEnumeration) o).destroy();
                return;
            }
            if (o instanceof RecordStore) {
                ((RecordStore) o).closeRecordStore();
                return;
            }
            super.cleanup(o);
        }
    } catch (Throwable ex) {
        ex.printStackTrace();
    }
}
 
Example #4
Source File: GameCanvasImplementation.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
public void flush() throws IOException {
    if(cache != null) {
        byte[] data = cache.toByteArray();
        if(data.length > 0) {
            RecordStore r = null;
            try {
                r = RecordStore.openRecordStore("" + letter + key, true);
                r.addRecord(data, 0, data.length);
                r.closeRecordStore();
                if(letter == 'Z') {
                    letter = 'a';
                } else {
                    letter++;
                }
                cache = new ByteArrayOutputStream();
            } catch (RecordStoreException ex) {
                ex.printStackTrace();
                cleanup(r);
                throw new IOException(ex.toString());
            }
        }
    }
}
 
Example #5
Source File: GameCanvasImplementation.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public RMSInputStream(short key) throws IOException {
            this.key = key;
            RecordStore r = null;
            RecordEnumeration e = null;
            char letter = 'A';
            try {
                ByteArrayOutputStream os = new ByteArrayOutputStream();
                r = open("" + letter + key);
                while(r != null) {
                    e = r.enumerateRecords(null, null, false);
                    while(e.hasNextElement()) {
                        byte[] data = e.nextRecord();
                        os.write(data);
                    }
                    e.destroy();
                    r.closeRecordStore();
                    letter++;
                    r = open("" + letter + key);
                    if(letter == 'Z') {
                        letter = 'a' - ((char)1);
                    }
                }
                os.close();
                current = new ByteArrayInputStream(os.toByteArray());
            } catch (RecordStoreException ex) {
                //#ifndef RIM
                ex.printStackTrace();
                //#else
//#                 System.out.println("Exception in object store input stream constructor: " + ex);
                //#endif
                cleanup(r);
                cleanup(e);
                throw new IOException(ex.toString());
            }
        }
 
Example #6
Source File: BlackBerryImplementation.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @inheritDoc
 */
public OutputStream createStorageOutputStream(String name) throws IOException {
    RecordStore r = null;
    RMSOutputStream os = null;
    DataOutputStream out = null;
    try {
        Short key = (Short) fat.get(name);
        if (key == null) {
            // need to add a key to the FAT
            key = new Short(currentKey);
            fat.put(name, key);
            r = RecordStore.openRecordStore("FAT", true);
            byte[] data = toRecord(name, currentKey);
            currentKey++;
            r.addRecord(data, 0, data.length);
            r.closeRecordStore();
            r = null;
        }
        os = new RMSOutputStream(key.shortValue());
        return os;
    } catch (Exception err) {
        cleanup(r);
        cleanup(os);
        cleanup(out);
        throw new IOException(err.getMessage());
    }
}
 
Example #7
Source File: BlackBerryImplementation.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private RecordStore open(String s) {
    try {
        return RecordStore.openRecordStore(s, false);
    } catch (RecordStoreException ex) {
        return null;
    }
}
 
Example #8
Source File: BlackBerryImplementation.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public RMSInputStream(short key) throws IOException {
    this.key = key;
    RecordStore r = null;
    RecordEnumeration e = null;
    char letter = 'A';
    try {
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        r = open("" + letter + key);
        while (r != null) {
            e = r.enumerateRecords(null, null, false);
            while (e.hasNextElement()) {
                byte[] data = e.nextRecord();
                os.write(data);
            }
            e.destroy();
            r.closeRecordStore();
            letter++;
            r = open("" + letter + key);
            if (letter == 'Z') {
                letter = 'a' - ((char) 1);
            }
        }
        os.close();
        current = new ByteArrayInputStream(os.toByteArray());
    } catch (RecordStoreException ex) {
        ex.printStackTrace();
        cleanup(r);
        cleanup(e);
        throw new IOException(ex.toString());
    }
}
 
Example #9
Source File: BlackBerryImplementation.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public RMSOutputStream(short key) {
    this.key = key;

    // first we need to cleanup existing files
    try {
        for (char c = 'A'; c < 'Z'; c++) {
            RecordStore.deleteRecordStore("" + c + key);
        }
    } catch (RecordStoreException e) {
    }

    cache = new ByteArrayOutputStream();
}
 
Example #10
Source File: BlackBerryImplementation.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @inheritDoc
 */
public void deleteStorageFile(String name) {
    Short key = (Short) fat.get(name);
    fat.remove(name);
    resaveFat();
    if (key != null) {
        try {
            for (char c = 'A'; c < 'Z'; c++) {
                RecordStore.deleteRecordStore("" + c + key);
            }
        } catch (RecordStoreException e) {
        }
    }
}
 
Example #11
Source File: GameCanvasImplementation.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @inheritDoc
 */
public OutputStream createStorageOutputStream(String name) throws IOException {
    RecordStore r = null;
    RMSOutputStream os = null;
    DataOutputStream out = null;
    try {
        Short key = (Short)fat.get(name);
        if(key == null) {
            // need to add a key to the FAT
            key = new Short(currentKey);
            fat.put(name, key);
            r = RecordStore.openRecordStore("FAT", true);
            byte[] data = toRecord(name, currentKey);
            currentKey++;
            r.addRecord(data, 0, data.length);
            r.closeRecordStore();
            r = null;
        }
        os = new RMSOutputStream(key.shortValue());
        return os;
    } catch(Exception err) {
        cleanup(r);
        cleanup(os);
        cleanup(out);
        throw new IOException(err.getMessage());
    }
}
 
Example #12
Source File: GameCanvasImplementation.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private RecordStore open(String s) {
    try {
        return RecordStore.openRecordStore(s, false);
    } catch (RecordStoreException ex) {
        return null;
    }
}
 
Example #13
Source File: GameCanvasImplementation.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
public RMSOutputStream(short key) {
    this.key =  key;

    // first we need to cleanup existing files
    try {
        for(char c = 'A' ; c < 'Z' ; c++) {
            RecordStore.deleteRecordStore("" + c + key);
        }
    } catch(RecordStoreException e) {}

    cache = new ByteArrayOutputStream();
}
 
Example #14
Source File: GameCanvasImplementation.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @inheritDoc
 */
public void deleteStorageFile(String name) {
    Short key = (Short)fat.get(name);
    fat.remove(name);
    resaveFat();
    if(key != null) {
        try {
            for(char c = 'A' ; c < 'Z' ; c++) {
                RecordStore.deleteRecordStore("" + c + key);
            }
        } catch(RecordStoreException e) {}
    }
}
 
Example #15
Source File: RecordStoreManager.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
RecordStore openRecordStore(String recordStoreName, boolean createIfNecessary)
throws RecordStoreException;
 
Example #16
Source File: GameCanvasImplementation.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @inheritDoc
 */
public void init(Object m) {
    canvas = createCanvas();
    canvas.setTitle(null);
    if(!disableFullScreen) {
        canvas.setFullScreenMode(!com.codename1.ui.Display.getInstance().isNativeCommands());
    }

    // disable the flashGraphics bug on Nokia phones
    String platform = System.getProperty("microedition.platform");
    if (platform != null && platform.toUpperCase().indexOf("NOKIA") >= 0) {
        flushGraphicsBug = false;
        NOKIA = true;

        // Symbian devices should yield a bit to let the paint thread complete its work
        // problem is we can't differentiate S40 from S60...
        Display.getInstance().setTransitionYield(1);
        //nokia devices cannot use OutputStreamWriter flush when using 
        //MultipartRequest
        MultipartRequest.setCanFlushStream(false);
    } else {
        flushGraphicsBug = true;
        Display.getInstance().setTransitionYield(-1);
    }
    mid = (MIDlet)m;
    display = javax.microedition.lcdui.Display.getDisplay(mid);
    setSoftKeyCodes(mid);

    if(mid.getAppProperty("forceBackCommand") != null) {
        canvas.setCommandListener((CommandListener) canvas);
        canvas.addCommand(MIDP_BACK_COMMAND);
    }
    
    RecordEnumeration e = null;
    RecordStore r = null;
    try {
        r = RecordStore.openRecordStore("FAT", true);
        if (r.getNumRecords() > 0) {
            e = r.enumerateRecords(null, null, false);
            while (e.hasNextElement()) {
                byte[] rec = e.nextRecord();
                ByteArrayInputStream bi = new ByteArrayInputStream(rec);
                DataInputStream di = new DataInputStream(bi);
                String name = di.readUTF();
                short key = di.readShort();
                di.close();
                bi.close();
                fat.put(name, new Short(key));
                if(key >= currentKey) {
                    currentKey += key;
                }
            }
            e.destroy();
            e = null;
        }
        r.closeRecordStore();
        r = null;
    } catch (Exception ex) {
        ex.printStackTrace();
        cleanup(r);
        cleanup(e);
    }        
}
 
Example #17
Source File: RecordEnumerationImpl.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
@Override
public void recordDeleted(RecordStore recordStore, int recordId) {
	rebuild();
}
 
Example #18
Source File: RecordEnumerationImpl.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
@Override
public void recordChanged(RecordStore recordStore, int recordId) {
	rebuild();
}
 
Example #19
Source File: RecordEnumerationImpl.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
@Override
public void recordAdded(RecordStore recordStore, int recordId) {
	rebuild();
}
 
Example #20
Source File: ExtendedRecordListener.java    From J2ME-Loader with Apache License 2.0 votes vote down vote up
void recordEvent(int type, long timestamp, RecordStore recordStore, int recordId);