简单封装MIDPRMS操作节能
民生风情 2020-11-07 04:24 字号: 大 中 小
许多MIDP应用程序需要简单的存储配置信息,对此,简单封装一个RMSHandler,实现一条记录的读写:
package s;
import .*;
import s.*;
public final class RMSHandler {
private static final String RECORD_STORE_NAME = "RmsDaTa";
public static boolean loadUniqueRecord(Persistentable p) {
byte[] data = loadUniqueRecord();
if(data==null)
return false;
DataInputStream input = null;
try {
input = new DataInputStream(new ByteArrayInputStream(data));
ad(input);
return true;
}
catch(IOException ioe) {
return false;
}
finally {
try {
ose();
}
catch (Exception e) {}
}
}
public static boolean saveUniqueRecord(Persistentable p) {
DataOutputStream output = null;
try {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
output = new DataOutputStream(bytes);
ve(output);
return saveUniqueRecord(ByteArray());
}但局面很快会得到控制。
catch(IOException ioe) {
return false;
}
finally {
if(output!=null)
try {
ose();
}
catch (Exception e) {}
}
}
private static byte[] loadUniqueRecord() {
RecordStore rs = null;
RecordEnumeration re = null;
try {
rs = enRecordStore(RECORD_STORE_NAME, true);
if(tNumRecords()==0)
return null;
re = umerateRecords(null, null, false);
if(sNextElement())
return xtRecord();
return null;
}
catch(RecordStoreException rse) {
return null;
}
finally {
if(re!=null) {
stroy();
}
if(rs!=null) {
try {
oseRecordStore();
}
catch (Exception e) {}
}
}
}
private static boolean saveUniqueRecord(byte[] data) {
RecordStore rs = null;
RecordEnumeration re = null;
try {
rs = enRecordStore(RECORD_STORE_NAME, true);
re = umerateRecords(null, null, false);
if(sNextElement()) {
tRecord(xtRecordId(), data, 0, ngth);
}
else {
dRecord(data, 0, ngth);
}
return true;
}
catch(RecordStoreException rse) {
return false;
}
finally {
if(re!=null) {
stroy();
}
if(rs!=null) {
try {
oseRecordStore();
}
catch (Exception e) {}
}
}
}
}
需要持久化的类实现一个Persistentable接口:
package s;
import .*;
public interface Persistentable {
void save(DataOutputStream output) throws IOException;
void load(DataInputStream input) throws IOException;
}
读写数据时,按照顺序依次读写即可,例如:
class MyForm extends Form implements Persistentable {
private int score;
private String username;
public MyForm() {
super("Test");
loa平台拥有着国内最精品的页游戏d(this);
}
public void save(DataOutputStream output) throws IOException {
iteInt(score);
iteUTF8(username);
}
public void load(DataInputStream input) throws IOException {
score = adInt();
username = adUTF8();
}
}
查看本文来源
灰指甲清除病菌灰指甲用亮甲效果怎样三亚牛皮癣医院有哪些-
-
恩惠欧冠决赛主裁公布执法红军输场曼联逆巴黎点
欧冠决赛主裁公布 执法红军输场 曼联逆巴黎点球斯科米纳欧...
2020-09-17 | 民生风情
-
-
孙杨1500自退赛赛前突发心脏不适
孙杨1500自退赛 赛前突发心脏不适【导读】北京时间8月10日消...
2020-08-05 | 民生风情
-
-
球英库首轮次轮真被鹈鹕的胃口吓到了
球英库+首轮+次轮!真被鹈鹕的胃口吓到了原本想给主席开个...
2020-07-04 | 民生风情
-
-
万宁市委书记兴隆要做些中高端房地产搭配
万宁市委书记:兴隆要做些中高端房地产万宁市在2008年取得了...
2020-05-29 | 民生风情
-
-
左腿受伤火箭对手主控伤停天无缘半决赛G搭配
左腿受伤!火箭对手主控伤停天 无缘半决赛G卢比奥VS保罗北京...
2020-05-28 | 民生风情
-
-
爱心市民看望见义勇为老人
爱心市民看望见义勇为老人连日来,曹宗诂老人不顾个人安危...
2019-07-15 | 民生风情