J2ME RMS

Basically a blog which is a mixture of anything that comes up in the author's mind. From the technologies that makes his life convenient to the everyday news in his country.

J2ME RMS

Monday, March 10, 2008

(0) Comments

public void writeStringArray(String file, String[] strArr) throws Exception {
RecordStore rs = RecordStore.openRecordStore(file, true, RecordStore.AUTHMODE_PRIVATE, false);
ByteArrayOutputStream bos = null;
DataOutputStream dos = null;
for(int i = 0; i < strArr.length; i++) {
bos = new ByteArrayOutputStream();
dos = new DataOutputStream(bos);
dos.writeUTF(strArr[i]);
byte[] b = bos.toByteArray();
rs.addRecord(b, 0, b.length);
}
dos.close();
bos.close();

rs.closeRecordStore();
}

public boolean deleteRecords(String file, String strKeys[], boolean createFile) throws Exception {
RecordStore rs = RecordStore.openRecordStore(file, createFile, RecordStore.AUTHMODE_PRIVATE, createFile);

if(rs.getNumRecords() > 0) {
RecordEnumeration re = rs.enumerateRecords(null, null, true);
ByteArrayInputStream bis = null;
DataInputStream dis = null;
for(int i = 0; i < strKeys.length; i++) {
while(re.hasNextElement()) {
int id = re.nextRecordId();
bis = new ByteArrayInputStream(rs.getRecord(id));
dis = new DataInputStream(bis);
bis = new ByteArrayInputStream(rs.getRecord(id));
dis = new DataInputStream(bis);
String strRecord = dis.readUTF();
if(strRecord.equals(strKeys[i])) {
System.out.println(strKeys[i]);
rs.deleteRecord(id);
break;
}
}
}
dis.close();
bis.close();
}
rs.closeRecordStore();

return true;
}

public String[] getStringArray(String file, boolean createFile) throws Exception {
RecordStore rs = RecordStore.openRecordStore(file, createFile, RecordStore.AUTHMODE_PRIVATE, createFile);
String strArr[] = null;
int ctr = 0;

if(rs.getNumRecords() > 0) {
RecordEnumeration re = rs.enumerateRecords(null, this, true);

strArr = new String[re.numRecords()];
ByteArrayInputStream bis = null;
DataInputStream dis = null;
while(re.hasNextElement()) {
int id = re.nextRecordId();
bis = new ByteArrayInputStream(rs.getRecord(id));
dis = new DataInputStream(bis);
bis = new ByteArrayInputStream(rs.getRecord(id));
dis = new DataInputStream(bis);
strArr[ctr++] = dis.readUTF();
}
dis.close();
bis.close();
}
rs.closeRecordStore();

return strArr;
}

0 Responses to "J2ME RMS"

Post a Comment

Contributors