Search in sources :

Example 1 with RecordStoreNotFoundException

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

the class AndroidRecordStoreManager method openRecordStore.

@Override
public RecordStore openRecordStore(String recordStoreName, boolean createIfNecessary) throws RecordStoreException {
    initializeIfNecessary();
    RecordStoreImpl recordStoreImpl;
    try {
        DataInputStream dis = new DataInputStream(ContextHolder.openFileInput(getHeaderFileName(recordStoreName)));
        recordStoreImpl = new RecordStoreImpl(this);
        recordStoreImpl.readHeader(dis);
        recordStoreImpl.setOpen(true);
        dis.close();
    } catch (FileNotFoundException e) {
        if (!createIfNecessary) {
            throw new RecordStoreNotFoundException(recordStoreName);
        }
        recordStoreImpl = new RecordStoreImpl(this, recordStoreName);
        recordStoreImpl.setOpen(true);
        saveToDisk(recordStoreImpl, -1);
    } catch (IOException e) {
        throw new RecordStoreException();
    }
    recordStores.put(recordStoreName, recordStoreImpl);
    return recordStoreImpl;
}
Also used : RecordStoreException(javax.microedition.rms.RecordStoreException) FileNotFoundException(java.io.FileNotFoundException) RecordStoreNotFoundException(javax.microedition.rms.RecordStoreNotFoundException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 2 with RecordStoreNotFoundException

use of javax.microedition.rms.RecordStoreNotFoundException 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)

Aggregations

DataInputStream (java.io.DataInputStream)2 IOException (java.io.IOException)2 RecordStoreException (javax.microedition.rms.RecordStoreException)2 RecordStoreNotFoundException (javax.microedition.rms.RecordStoreNotFoundException)2 FileNotFoundException (java.io.FileNotFoundException)1 RecordEnumeration (javax.microedition.rms.RecordEnumeration)1