javax.microedition.rms.RecordStoreException Java Examples
The following examples show how to use
javax.microedition.rms.RecordStoreException.
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: RecordStoreImpl.java From J2ME-Loader with Apache License 2.0 | 6 votes |
@Override public void closeRecordStore() throws RecordStoreNotOpenException, RecordStoreException { if (!open) { throw new RecordStoreNotOpenException(); } if (recordListeners != null) { recordListeners.removeAllElements(); } records.clear(); open = false; Log.d(TAG, "RecordStore " + recordStoreName + " closed"); }
Example #2
Source File: RecordEnumerationImpl.java From J2ME-Loader with Apache License 2.0 | 6 votes |
@Override public byte[] nextRecord() throws InvalidRecordIDException, RecordStoreNotOpenException, RecordStoreException { if (!recordStoreImpl.isOpen()) { throw new RecordStoreNotOpenException(); } if (currentRecord >= numRecords()) { throw new InvalidRecordIDException(); } byte[] result = enumerationRecords.elementAt(currentRecord).value; currentRecord++; return result; }
Example #3
Source File: BlackBerryImplementation.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
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 #4
Source File: RecordStoreImpl.java From J2ME-Loader with Apache License 2.0 | 6 votes |
@Override public void deleteRecord(int recordId) throws RecordStoreNotOpenException, InvalidRecordIDException, RecordStoreException { if (!open) { throw new RecordStoreNotOpenException(); } synchronized (this) { // throws InvalidRecordIDException when no record found getRecord(recordId); records.remove(new Integer(recordId)); version++; lastModified = System.currentTimeMillis(); size--; } recordStoreManager.deleteRecord(this, recordId); fireRecordListener(ExtendedRecordListener.RECORD_DELETE, recordId); Log.d(TAG, "Record " + recordStoreName + "." + recordId + " deleted"); }
Example #5
Source File: RecordStoreImpl.java From J2ME-Loader with Apache License 2.0 | 6 votes |
@Override public int getRecordSize(int recordId) throws RecordStoreNotOpenException, InvalidRecordIDException, RecordStoreException { if (!open) { throw new RecordStoreNotOpenException(); } synchronized (this) { byte[] data = records.get(new Integer(recordId)); if (data == null) { recordStoreManager.loadRecord(this, recordId); data = records.get(new Integer(recordId)); if (data == null) { throw new InvalidRecordIDException(); } } return data.length; } }
Example #6
Source File: RecordStoreImpl.java From J2ME-Loader with Apache License 2.0 | 6 votes |
public void writeRecord(DataOutputStream dos, int recordId) throws IOException { dos.writeInt(recordId); dos.writeInt(0); // TODO Tag 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(); } }
Example #7
Source File: RecordStoreImpl.java From J2ME-Loader with Apache License 2.0 | 6 votes |
@Override public byte[] getRecord(int recordId) throws RecordStoreNotOpenException, InvalidRecordIDException, RecordStoreException { if (!open) { throw new RecordStoreNotOpenException(); } byte[] data; synchronized (this) { data = new byte[getRecordSize(recordId)]; getRecord(recordId, data, 0); } return data.length < 1 ? null : data; }
Example #8
Source File: GameCanvasImplementation.java From CodenameOne with GNU General Public License v2.0 | 6 votes |
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 #9
Source File: AndroidRecordStoreManager.java From J2ME-Loader with Apache License 2.0 | 5 votes |
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)); }
Example #10
Source File: RecordEnumerationImpl.java From J2ME-Loader with Apache License 2.0 | 5 votes |
@Override public byte[] previousRecord() throws InvalidRecordIDException, RecordStoreNotOpenException, RecordStoreException { if (!recordStoreImpl.isOpen()) { throw new RecordStoreNotOpenException(); } if (currentRecord < 0) { throw new InvalidRecordIDException(); } currentRecord--; return enumerationRecords.elementAt(currentRecord).value; }
Example #11
Source File: GameCanvasImplementation.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * @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 #12
Source File: GameCanvasImplementation.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
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 #13
Source File: GameCanvasImplementation.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
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 #14
Source File: GameCanvasImplementation.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
private RecordStore open(String s) { try { return RecordStore.openRecordStore(s, false); } catch (RecordStoreException ex) { return null; } }
Example #15
Source File: BlackBerryImplementation.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
/** * @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 #16
Source File: BlackBerryImplementation.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
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 #17
Source File: BlackBerryImplementation.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
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 #18
Source File: BlackBerryImplementation.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
private RecordStore open(String s) { try { return RecordStore.openRecordStore(s, false); } catch (RecordStoreException ex) { return null; } }
Example #19
Source File: RecordStoreImpl.java From J2ME-Loader with Apache License 2.0 | 5 votes |
@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(); try { byte[] data = getRecord(key); if (data != null) { result += data.length; } } catch (RecordStoreException e) { e.printStackTrace(); } } return result; }
Example #20
Source File: AndroidRecordStoreManager.java From J2ME-Loader with Apache License 2.0 | 5 votes |
@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); Log.d(TAG, "RecordStore " + recordStoreName + " deleted"); }
Example #21
Source File: RecordStoreImpl.java From J2ME-Loader with Apache License 2.0 | 5 votes |
@Override public int getNextRecordID() throws RecordStoreNotOpenException, RecordStoreException { if (!open) { throw new RecordStoreNotOpenException(); } // lastRecordId needs to hold correct number, all records have to be preloaded enumerateRecords(null, null, false); synchronized (this) { return lastRecordId + 1; } }
Example #22
Source File: RecordStoreImpl.java From J2ME-Loader with Apache License 2.0 | 5 votes |
@Override public int addRecord(byte[] data, int offset, int numBytes) throws RecordStoreNotOpenException, RecordStoreException, RecordStoreFullException { if (!open) { throw new RecordStoreNotOpenException(); } if (data == null && numBytes > 0) { throw new NullPointerException(); } if (numBytes > recordStoreManager.getSizeAvailable(this)) { throw new RecordStoreFullException(); } // lastRecordId needs to hold correct number, all records have to be preloaded enumerateRecords(null, null, false); byte[] recordData = new byte[numBytes]; if (data != null) { System.arraycopy(data, offset, recordData, 0, numBytes); } int nextRecordID = getNextRecordID(); synchronized (this) { records.put(new Integer(nextRecordID), recordData); version++; lastModified = System.currentTimeMillis(); lastRecordId++; size++; } recordStoreManager.saveRecord(this, nextRecordID); fireRecordListener(ExtendedRecordListener.RECORD_ADD, nextRecordID); Log.d(TAG, "Record " + recordStoreName + "." + nextRecordID + " added"); return nextRecordID; }
Example #23
Source File: RecordStoreImpl.java From J2ME-Loader with Apache License 2.0 | 5 votes |
@Override public int getRecord(int recordId, byte[] buffer, int offset) throws RecordStoreNotOpenException, InvalidRecordIDException, RecordStoreException { int recordSize; synchronized (this) { recordSize = getRecordSize(recordId); System.arraycopy(records.get(new Integer(recordId)), 0, buffer, offset, recordSize); } fireRecordListener(ExtendedRecordListener.RECORD_READ, recordId); return recordSize; }
Example #24
Source File: RecordStoreImpl.java From J2ME-Loader with Apache License 2.0 | 5 votes |
@Override public void setRecord(int recordId, byte[] newData, int offset, int numBytes) throws RecordStoreNotOpenException, InvalidRecordIDException, RecordStoreException, RecordStoreFullException { if (!open) { throw new RecordStoreNotOpenException(); } // FIXME fixit if (numBytes > recordStoreManager.getSizeAvailable(this)) { throw new RecordStoreFullException(); } byte[] recordData = new byte[numBytes]; System.arraycopy(newData, offset, recordData, 0, numBytes); synchronized (this) { // throws InvalidRecordIDException when no record found getRecord(recordId); records.put(new Integer(recordId), recordData); version++; lastModified = System.currentTimeMillis(); } recordStoreManager.saveRecord(this, recordId); fireRecordListener(ExtendedRecordListener.RECORD_CHANGE, recordId); Log.d(TAG, "Record " + recordStoreName + "." + recordId + " set"); }
Example #25
Source File: AndroidRecordStoreManager.java From J2ME-Loader with Apache License 2.0 | 4 votes |
@Override public void deleteRecord(RecordStoreImpl recordStoreImpl, int recordId) throws RecordStoreNotOpenException, RecordStoreException { deleteFromDisk(recordStoreImpl, recordId); }
Example #26
Source File: RecordStoreManager.java From J2ME-Loader with Apache License 2.0 | 4 votes |
void deleteRecordStore(String recordStoreName) throws RecordStoreNotFoundException, RecordStoreException;
Example #27
Source File: RecordStoreManager.java From J2ME-Loader with Apache License 2.0 | 4 votes |
RecordStore openRecordStore(String recordStoreName, boolean createIfNecessary) throws RecordStoreException;
Example #28
Source File: RecordStoreManager.java From J2ME-Loader with Apache License 2.0 | 4 votes |
void loadRecord(RecordStoreImpl recordStoreImpl, int recordId) throws RecordStoreNotOpenException, InvalidRecordIDException, RecordStoreException;
Example #29
Source File: RecordStoreManager.java From J2ME-Loader with Apache License 2.0 | 4 votes |
void deleteRecord(RecordStoreImpl recordStoreImpl, int recordId) throws RecordStoreNotOpenException, RecordStoreException;
Example #30
Source File: RecordStoreManager.java From J2ME-Loader with Apache License 2.0 | 4 votes |
void saveRecord(RecordStoreImpl recordStoreImpl, int recordId) throws RecordStoreNotOpenException, RecordStoreException;