Search in sources :

Example 1 with RecordEnumeration

use of javax.microedition.rms.RecordEnumeration in project CodenameOne by codenameone.

the class BlackBerryImplementation method resaveFat.

private void resaveFat() {
    RecordStore r = null;
    RecordEnumeration e = null;
    try {
        r = RecordStore.openRecordStore("FAT", true);
        Vector keys = new Vector();
        Enumeration fatKeys = fat.keys();
        while (fatKeys.hasMoreElements()) {
            keys.addElement(fatKeys.nextElement());
        }
        e = r.enumerateRecords(null, null, false);
        while (e.hasNextElement()) {
            int recordId = e.nextRecordId();
            byte[] rec = r.getRecord(recordId);
            ByteArrayInputStream bi = new ByteArrayInputStream(rec);
            DataInputStream di = new DataInputStream(bi);
            String name = di.readUTF();
            short key = di.readShort();
            di.close();
            bi.close();
            Short fatKey = (Short) fat.get(name);
            if (fatKey == null) {
                // we need to remove this record...
                r.deleteRecord(recordId);
            } else {
                // we need to update the record
                if (fatKey.shortValue() != key) {
                    byte[] bd = toRecord(name, fatKey.shortValue());
                    r.setRecord(recordId, bd, 0, bd.length);
                }
            }
            keys.removeElement(name);
        }
        e.destroy();
        e = null;
        Enumeration remainingKeys = keys.elements();
        while (remainingKeys.hasMoreElements()) {
            String name = (String) remainingKeys.nextElement();
            Short key = (Short) fat.get(name);
            byte[] bd = toRecord(name, key.shortValue());
            r.addRecord(bd, 0, bd.length);
        }
        r.closeRecordStore();
    } catch (Exception err) {
        // This might be a valid exception and some platforms (e..g. RIM) don't respond well to PST
        // err.printStackTrace();
        cleanup(e);
        cleanup(r);
    }
}
Also used : Enumeration(java.util.Enumeration) RecordEnumeration(javax.microedition.rms.RecordEnumeration) ByteArrayInputStream(java.io.ByteArrayInputStream) RecordStore(javax.microedition.rms.RecordStore) RecordEnumeration(javax.microedition.rms.RecordEnumeration) DataInputStream(java.io.DataInputStream) Vector(java.util.Vector) IOException(java.io.IOException) RecordStoreException(javax.microedition.rms.RecordStoreException) MediaException(javax.microedition.media.MediaException) ConnectionNotFoundException(javax.microedition.io.ConnectionNotFoundException)

Example 2 with RecordEnumeration

use of javax.microedition.rms.RecordEnumeration in project CodenameOne by codenameone.

the class BlackBerryImplementation method init.

public void init(Object m) {
    instance = this;
    app = (CodenameOneUiApplication) m;
    if (askForPermission) {
        app.invokeAndWait(new Runnable() {

            public void run() {
                ApplicationPermissions permRequest = new ApplicationPermissions();
                permRequest.addPermission(ApplicationPermissions.PERMISSION_EMAIL);
                permRequest.addPermission(ApplicationPermissions.PERMISSION_FILE_API);
                permRequest.addPermission(ApplicationPermissions.PERMISSION_WIFI);
                try {
                    // ApplicationPermissions.PERMISSION_CROSS_APPLICATION_COMMUNICATION
                    permRequest.addPermission(11);
                } catch (Exception e) {
                }
                try {
                    // ApplicationPermissions.PERMISSION_MEDIA
                    permRequest.addPermission(21);
                } catch (Exception e) {
                }
                try {
                    // ApplicationPermissions.PERMISSION_INPUT_SIMULATION
                    permRequest.addPermission(6);
                } catch (Exception e) {
                }
                try {
                    // ApplicationPermissions.PERMISSION_LOCATION_DATA
                    permRequest.addPermission(14);
                } catch (Exception e) {
                }
                try {
                    // ApplicationPermissions.PERMISSION_ORGANIZER_DATA
                    permRequest.addPermission(16);
                } catch (Exception e) {
                }
                try {
                    // ApplicationPermissions.PERMISSION_INTERNET
                    permRequest.addPermission(7);
                } catch (Exception e) {
                }
                try {
                    // ApplicationPermissions.PERMISSION_RECORDING
                    permRequest.addPermission(17);
                } catch (Exception e) {
                }
                ApplicationPermissionsManager apm = ApplicationPermissionsManager.getInstance();
                if (!apm.invokePermissionsRequest(permRequest)) {
                    exitApplication();
                    return;
                }
            }
        });
    }
    app.enableKeyUpEvents(true);
    if (!app.isHandlingEvents()) {
        new Thread() {

            public void run() {
                app.enterEventDispatcher();
            }
        }.start();
    }
    Dialog.setCommandsAsButtons(true);
    UIManager.getInstance().addThemeRefreshListener(new ActionListener() {

        public void actionPerformed(ActionEvent evt) {
            Hashtable themeProps = new Hashtable();
            themeProps.put("SoftButton.margin", "0,0,0,0");
            themeProps.put("SoftButton.padding", "0,0,0,0");
            UIManager.getInstance().addThemeProps(themeProps);
        }
    });
    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);
    }
}
Also used : ActionEvent(com.codename1.ui.events.ActionEvent) Hashtable(java.util.Hashtable) RecordEnumeration(javax.microedition.rms.RecordEnumeration) ApplicationPermissions(net.rim.device.api.applicationcontrol.ApplicationPermissions) DataInputStream(java.io.DataInputStream) IOException(java.io.IOException) RecordStoreException(javax.microedition.rms.RecordStoreException) MediaException(javax.microedition.media.MediaException) ConnectionNotFoundException(javax.microedition.io.ConnectionNotFoundException) ActionListener(com.codename1.ui.events.ActionListener) ByteArrayInputStream(java.io.ByteArrayInputStream) RecordStore(javax.microedition.rms.RecordStore) ApplicationPermissionsManager(net.rim.device.api.applicationcontrol.ApplicationPermissionsManager)

Example 3 with RecordEnumeration

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

the class AndroidRecordStoreManager method deleteRecordStore.

@Override
public void deleteRecordStore(final String recordStoreName) throws RecordStoreNotFoundException, RecordStoreException {
    initializeIfNecessary();
    Object value = recordStores.get(recordStoreName);
    if (value == null) {
        throw new RecordStoreNotFoundException(recordStoreName);
    }
    if (value instanceof RecordStoreImpl && ((RecordStoreImpl) value).isOpen()) {
        throw new RecordStoreException();
    }
    RecordStoreImpl recordStoreImpl;
    try {
        DataInputStream dis = new DataInputStream(ContextHolder.openFileInput(getHeaderFileName(recordStoreName)));
        recordStoreImpl = new RecordStoreImpl(this);
        recordStoreImpl.readHeader(dis);
        dis.close();
    } catch (IOException e) {
        Log.e(TAG, "RecordStore.deleteRecordStore: ERROR reading " + getHeaderFileName(recordStoreName), e);
        throw new RecordStoreException();
    }
    recordStoreImpl.setOpen(true);
    RecordEnumeration re = recordStoreImpl.enumerateRecords(null, null, false);
    while (re.hasNextElement()) {
        ContextHolder.deleteFile(getRecordFileName(recordStoreName, re.nextRecordId()));
    }
    recordStoreImpl.setOpen(false);
    ContextHolder.deleteFile(getHeaderFileName(recordStoreName));
    recordStores.remove(recordStoreName);
}
Also used : RecordStoreException(javax.microedition.rms.RecordStoreException) RecordEnumeration(javax.microedition.rms.RecordEnumeration) RecordStoreNotFoundException(javax.microedition.rms.RecordStoreNotFoundException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 4 with RecordEnumeration

use of javax.microedition.rms.RecordEnumeration in project CodenameOne by codenameone.

the class GameCanvasImplementation method resaveFat.

private void resaveFat() {
    RecordStore r = null;
    RecordEnumeration e = null;
    try {
        r = RecordStore.openRecordStore("FAT", true);
        Vector keys = new Vector();
        Enumeration fatKeys = fat.keys();
        while (fatKeys.hasMoreElements()) {
            keys.addElement(fatKeys.nextElement());
        }
        e = r.enumerateRecords(null, null, false);
        while (e.hasNextElement()) {
            int recordId = e.nextRecordId();
            byte[] rec = r.getRecord(recordId);
            ByteArrayInputStream bi = new ByteArrayInputStream(rec);
            DataInputStream di = new DataInputStream(bi);
            String name = di.readUTF();
            short key = di.readShort();
            di.close();
            bi.close();
            Short fatKey = (Short) fat.get(name);
            if (fatKey == null) {
                // we need to remove this record...
                r.deleteRecord(recordId);
            } else {
                // we need to update the record
                if (fatKey.shortValue() != key) {
                    byte[] bd = toRecord(name, fatKey.shortValue());
                    r.setRecord(recordId, bd, 0, bd.length);
                }
            }
            keys.removeElement(name);
        }
        e.destroy();
        e = null;
        Enumeration remainingKeys = keys.elements();
        while (remainingKeys.hasMoreElements()) {
            String name = (String) remainingKeys.nextElement();
            Short key = (Short) fat.get(name);
            byte[] bd = toRecord(name, key.shortValue());
            r.addRecord(bd, 0, bd.length);
        }
        r.closeRecordStore();
    } catch (Exception err) {
        // This might be a valid exception and some platforms (e..g. RIM) don't respond well to PST
        // err.printStackTrace();
        cleanup(e);
        cleanup(r);
    }
}
Also used : Enumeration(java.util.Enumeration) RecordEnumeration(javax.microedition.rms.RecordEnumeration) ByteArrayInputStream(java.io.ByteArrayInputStream) RecordStore(javax.microedition.rms.RecordStore) RecordEnumeration(javax.microedition.rms.RecordEnumeration) DataInputStream(java.io.DataInputStream) Vector(java.util.Vector) RecordStoreException(javax.microedition.rms.RecordStoreException) MediaException(javax.microedition.media.MediaException) IOException(java.io.IOException) ConnectionNotFoundException(javax.microedition.io.ConnectionNotFoundException)

Example 5 with RecordEnumeration

use of javax.microedition.rms.RecordEnumeration in project CodenameOne by codenameone.

the class GameCanvasImplementation method init.

/**
 * @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);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RecordStore(javax.microedition.rms.RecordStore) RecordEnumeration(javax.microedition.rms.RecordEnumeration) DataInputStream(java.io.DataInputStream) RecordStoreException(javax.microedition.rms.RecordStoreException) MediaException(javax.microedition.media.MediaException) IOException(java.io.IOException) ConnectionNotFoundException(javax.microedition.io.ConnectionNotFoundException)

Aggregations

DataInputStream (java.io.DataInputStream)5 IOException (java.io.IOException)5 RecordEnumeration (javax.microedition.rms.RecordEnumeration)5 RecordStoreException (javax.microedition.rms.RecordStoreException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ConnectionNotFoundException (javax.microedition.io.ConnectionNotFoundException)4 MediaException (javax.microedition.media.MediaException)4 RecordStore (javax.microedition.rms.RecordStore)4 Enumeration (java.util.Enumeration)2 Vector (java.util.Vector)2 ActionEvent (com.codename1.ui.events.ActionEvent)1 ActionListener (com.codename1.ui.events.ActionListener)1 Hashtable (java.util.Hashtable)1 RecordStoreNotFoundException (javax.microedition.rms.RecordStoreNotFoundException)1 ApplicationPermissions (net.rim.device.api.applicationcontrol.ApplicationPermissions)1 ApplicationPermissionsManager (net.rim.device.api.applicationcontrol.ApplicationPermissionsManager)1