📄 storage.java
字号:
import java.io.*;
import javax.microedition.rms.RecordStore;
public class Storage
{
public Storage()
{
}
public byte[] LoadByteArray(String fName, int id)
{
RecordStore rs = null;
while_2_:
do {
while_1_:
do {
while_0_:
do{
do{
byte abyte0[];
try
{
try{
rs = RecordStore.openRecordStore(fName, true);
if(rs.getNumRecords() == 0)
{
rs.addRecord(null, 0, 0);
break;
}
byte data[] = rs.getRecord(id);
rs.closeRecordStore();
if(data == null)
{
break;
}
abyte0 = data;
}
catch(Exception e)
{
break while_0_;
}
}
catch(Exception e)
{
break while_1_;
}
if(rs != null)
{
try
{
rs.closeRecordStore();
}
catch(Exception exception)
{
exception.printStackTrace();
}
}
try
{
return abyte0;
}
catch(Exception rse)
{
break while_0_;
}
}while(false);
if(rs != null)
{
try
{
rs.closeRecordStore();
}
catch(Exception exception)
{
exception.printStackTrace();
}
}
break while_2_;
}while(false);
if(rs != null)
{
try
{
rs.closeRecordStore();
}
catch(Exception exception)
{
exception.printStackTrace();
}
}
break while_2_;
} while (false);
if(rs != null)
{
try
{
rs.closeRecordStore();
}
catch(Exception exception)
{
exception.printStackTrace();
}
}
}while(false);
return null;
}
public int[] LoadInt(String fName, int length, int id)
{
RecordStore rs = null;
ByteArrayInputStream bin = null;
DataInputStream din = null;
int[] buff = new int[length];
try
{
try
{
rs = RecordStore.openRecordStore(fName, true);
if (rs.getNumRecords() == 0)
rs.addRecord(null, 0, 0);
else
{
byte[] data = rs.getRecord(id);
if (data != null)
{
try {
bin = new ByteArrayInputStream(data);
din = new DataInputStream(bin);
for (int i = 0; i < length; i++)
buff[i] = din.readInt();
din.close();
} catch (IOException ioexception)
{
}
}
}
}
catch (javax.microedition.rms.RecordStoreException e)
{
do{
int[] is;
try
{
is = null;
}
catch(Exception ee)
{
break;
}
if (din != null)
{
try
{
din.close();
}
catch (Exception exception)
{
}
}
if (rs != null)
{
try
{
rs.closeRecordStore();
}
catch (Exception exception)
{
}
}
return is;
} while (false);
if (din != null)
{
try
{
din.close();
}
catch (Exception exception)
{
}
}
if (rs != null)
{
try
{
rs.closeRecordStore();
}
catch (Exception exception)
{
}
}
}
}
catch (Exception ee)
{
}
if (din != null)
{
try
{
din.close();
} catch (Exception exception)
{
}
}
if (rs != null)
{
try
{
rs.closeRecordStore();
}
catch (Exception exception)
{
}
}
return buff;
}
public boolean SaveByteArray(String fName, byte newData[], int id)
{
RecordStore rs = null;
ByteArrayOutputStream bout = new ByteArrayOutputStream();
DataOutputStream dout = new DataOutputStream(bout);
try
{
try
{
rs = RecordStore.openRecordStore(fName, true);
while (rs.getNumRecords() < id)
rs.addRecord(null, 0, 0);
rs.setRecord(id, newData, 0, newData.length);
rs.closeRecordStore();
}
catch (Exception e)
{
do
{
boolean bool;
try
{
bool = false;
}
catch (Exception ee)
{
break;
}
try
{
dout.flush();
dout.close();
}
catch (Exception exception)
{
}
if (rs != null)
{
try
{
rs.closeRecordStore();
}
catch (Exception exception)
{
}
}
return bool;
} while (false);
try
{
dout.flush();
dout.close();
}
catch (Exception exception)
{
}
if (rs != null)
{
try
{
rs.closeRecordStore();
}
catch (Exception exception)
{
}
}
}
}
catch (Exception e)
{}
try
{
dout.flush();
dout.close();
}
catch (Exception exception)
{
}
if (rs != null)
{
try
{
rs.closeRecordStore();
}
catch (Exception exception)
{
exception.printStackTrace();
}
}
return true;
}
public boolean SaveString(String fName, String newData, int id)
{
RecordStore rs = null;
ByteArrayOutputStream bout = new ByteArrayOutputStream();
DataOutputStream dout = new DataOutputStream(bout);
try
{
try
{
dout.writeUTF(newData);
byte[] data = bout.toByteArray();
rs = RecordStore.openRecordStore(fName, true);
while (rs.getNumRecords() < id)
rs.addRecord(null, 0, 0);
rs.setRecord(id, data, 0, data.length);
}
catch (Exception exception)
{
do
{
boolean bool;
try
{
bool = false;
}
catch (Exception e)
{
break;
}
try
{
dout.flush();
dout.close();
}
catch (Exception exception1)
{
}
if (rs != null)
{
try
{
rs.closeRecordStore();
}
catch (Exception exception2)
{
}
}
return bool;
} while (false);
Exception ex = exception;
try
{
dout.flush();
dout.close();
} catch (Exception exception3)
{
}
if (rs != null)
{
try
{
rs.closeRecordStore();
}
catch (Exception exception4)
{
}
}
throw ex;
}
}
catch (Exception e)
{
e.printStackTrace();
}
try
{
dout.flush();
dout.close();
} catch (Exception exception)
{
}
if (rs != null)
{
try
{
rs.closeRecordStore();
}
catch (Exception exception)
{
}
}
return true;
}
public boolean SaveInt(String fName, int newData[], int id)
{
RecordStore rs = null;
ByteArrayOutputStream bout = new ByteArrayOutputStream();
DataOutputStream dout = new DataOutputStream(bout);
try
{
try
{
rs = RecordStore.openRecordStore(fName, true);
while (rs.getNumRecords() < id)
rs.addRecord(null, 0, 0);
for (int i = 0; i < newData.length; i++)
dout.writeInt(newData[i]);
byte[] data = bout.toByteArray();
rs.setRecord(id, data, 0, data.length);
} catch (Exception ex) {
do {
boolean bool;
try
{
bool = false;
} catch (Exception ex1)
{
break;
}
try {
dout.flush();
dout.close();
}
catch (Exception exception)
{
}
if (rs != null)
{
try
{
rs.closeRecordStore();
}
catch (Exception exception)
{
}
}
return bool;
} while (false);
try {
dout.flush();
dout.close();
} catch (Exception exception)
{
}
if (rs != null) {
try {
rs.closeRecordStore();
} catch (Exception exception) {
/* empty */
}
}
}
} catch (Exception ex3) {
}
try {
dout.flush();
dout.close();
} catch (Exception exception) {
/* empty */
}
if (rs != null) {
try {
rs.closeRecordStore();
} catch (Exception exception) {
/* empty */
}
}
return true;
}
public String GetStringData(String fName, int id)
{
return new String(LoadByteArray(fName, id));
}
public int GetNumRecord(String fName)
{
RecordStore rs = null;
while_4_:
do {
while_3_:
do {
do {
int i;
try {
try {
rs = RecordStore.openRecordStore(fName, true);
i = rs.getNumRecords();
} catch (Exception PUSH) {
break;
}
} catch (Exception e) {
break while_3_;
}
if (rs != null) {
try {
rs.closeRecordStore();
} catch (Exception exception) {
/* empty */
}
}
try {
return i;
} catch (Exception PUSH) {
/* empty */
}
}
while (false);
try
{
}
catch (Exception e)
{
break;
}
if (rs != null)
{
try
{
rs.closeRecordStore();
}
catch (Exception exception)
{
}
}
break while_4_;
} while (false);
if (rs != null)
{
try
{
rs.closeRecordStore();
}
catch (Exception exception)
{
}
}
} while (false);
return 0;
}
public void DeleteData(String fName)
{
try
{
RecordStore.deleteRecordStore(fName);
}
catch(Exception e)
{
System.out.println("Delete Record Error!!!");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -