use of javax.microedition.rms.RecordStoreException in project J2ME-Loader by nikita36078.
the class AndroidRecordStoreManager method saveToDisk.
/**
* @param recordId -1 for storing only header
*/
private synchronized void saveToDisk(RecordStoreImpl recordStore, int recordId) throws RecordStoreException {
try {
DataOutputStream dos = new DataOutputStream(ContextHolder.openFileOutput(getHeaderFileName(recordStore.getName())));
recordStore.writeHeader(dos);
dos.close();
} catch (IOException e) {
Log.e(TAG, "RecordStore.saveToDisk: ERROR writting object to " + getHeaderFileName(recordStore.getName()), e);
throw new RecordStoreException(e.getMessage());
}
if (recordId != -1) {
try {
DataOutputStream dos = new DataOutputStream(ContextHolder.openFileOutput(getRecordFileName(recordStore.getName(), recordId)));
recordStore.writeRecord(dos, recordId);
dos.close();
} catch (IOException e) {
Log.e(TAG, "RecordStore.saveToDisk: ERROR writting object to " + getRecordFileName(recordStore.getName(), recordId), e);
throw new RecordStoreException(e.getMessage());
}
}
}
use of javax.microedition.rms.RecordStoreException 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;
}
use of javax.microedition.rms.RecordStoreException in project J2ME-Loader by nikita36078.
the class RecordStoreImpl method writeRecord.
public void writeRecord(DataOutputStream dos, int recordId) throws IOException {
dos.writeInt(recordId);
// TODO Tag
dos.writeInt(0);
try {
byte[] data = getRecord(recordId);
if (data == null) {
dos.writeInt(0);
} else {
dos.writeInt(data.length);
dos.write(data);
}
} catch (RecordStoreException e) {
throw new IOException();
}
}
use of javax.microedition.rms.RecordStoreException in project J2ME-Loader by nikita36078.
the class AndroidRecordStoreManager method deleteFromDisk.
private synchronized void deleteFromDisk(RecordStoreImpl recordStore, int recordId) throws RecordStoreException {
try {
DataOutputStream dos = new DataOutputStream(ContextHolder.openFileOutput(getHeaderFileName(recordStore.getName())));
recordStore.writeHeader(dos);
dos.close();
} catch (IOException e) {
Log.e(TAG, "RecordStore.saveToDisk: ERROR writting object to " + getHeaderFileName(recordStore.getName()), e);
throw new RecordStoreException(e.getMessage());
}
ContextHolder.deleteFile(getRecordFileName(recordStore.getName(), recordId));
}
use of javax.microedition.rms.RecordStoreException 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);
}
Aggregations