BadRms.java
/*
* Copyright © 2012 Nokia Corporation. All rights reserved.
* Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation.
* Oracle and Java are trademarks or registered trademarks of Oracle and/or its
* affiliates. Other product and company names mentioned herein may be trademarks
* or trade names of their respective owners.
* See LICENSE.TXT for license information.
*/
package com.nokia.example;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
/**
* Bad RMS usage example. RecordStore is opened and closed for each get/set
* operation.
*
* THIS IS NOT THE RECOMMENDED WAY TO USE RMS.
*/
public class BadRms implements RmsConnection {
private String rmsName = "BadRms";
public void open() {
}
public byte[] get() {
byte[] data = null;
try {
RecordStore r = RecordStore.openRecordStore(rmsName, true);
data = r.getRecord(1);
r.closeRecordStore();
} catch (RecordStoreException rse) {
rse.printStackTrace();
}
return data;
}
public void set(byte[] data) {
try {
RecordStore r = RecordStore.openRecordStore(rmsName, true);
r.addRecord(data, 0, data.length);
r.closeRecordStore();
} catch (RecordStoreException rse) {
rse.printStackTrace();
}
}
public void close() {
}
}