📄 rms.java
字号:
import java.io.PrintStream;
import java.util.Vector;
import javax.microedition.rms.RecordStore;
public class RMS
{
private static String id = "Worms.7650";
private static Vector variables = new Vector();
private static Vector values = new Vector();
public RMS()
{
}
private static boolean exist()
{
String as[] = RecordStore.listRecordStores();
if(as == null)
return false;
for(int i = 0; i < as.length; i++)
if(id.equals(as[i]))
return true;
return false;
}
public static boolean load()
{
if(!exist())
return false;
try
{
RecordStore recordstore = RecordStore.openRecordStore(id, true);
int i = recordstore.getNumRecords();
for(int j = 0; j < i >> 1; j++)
{
String s = new String(recordstore.getRecord((j << 1) + 0 + 1));
byte abyte0[] = recordstore.getRecord((j << 1) + 1 + 1);
put(s, abyte0);
}
recordstore.closeRecordStore();
}
catch(Exception exception)
{
return false;
}
return true;
}
public static void save()
{
try
{
RecordStore recordstore = RecordStore.openRecordStore(id, true);
int i = recordstore.getNumRecords();
for(int j = 0; j < i / 2; j++)
{
byte abyte0[] = ((String)variables.elementAt(j)).getBytes();
byte abyte1[] = (byte[])values.elementAt(j);
recordstore.setRecord(j * 2 + 0 + 1, abyte0, 0, abyte0.length);
recordstore.setRecord(j * 2 + 1 + 1, abyte1, 0, abyte1.length);
}
for(int k = 0; k < variables.size() - i; k++)
{
byte abyte2[] = ((String)variables.elementAt(k + i)).getBytes();
byte abyte3[] = (byte[])values.elementAt(k + i);
recordstore.addRecord(abyte2, 0, abyte2.length);
recordstore.addRecord(abyte3, 0, abyte3.length);
}
recordstore.closeRecordStore();
}
catch(Exception exception)
{
System.out.println(exception);
}
}
public static byte[] getAsData(String s)
{
s = s.toLowerCase();
for(int i = 0; i < variables.size(); i++)
{
String s1 = (String)variables.elementAt(i);
if(s1.equals(s))
return (byte[])values.elementAt(i);
}
return null;
}
public static String getAsString(String s)
{
byte abyte0[] = getAsData(s);
if(abyte0 != null)
return new String(abyte0);
else
return null;
}
public static int getAsInteger(String s)
{
byte abyte0[] = getAsData(s);
if(abyte0 != null)
{
int i = abyte0[0] >= 0 ? ((int) (abyte0[0])) : abyte0[0] + 256;
int j = abyte0[1] >= 0 ? ((int) (abyte0[1])) : abyte0[1] + 256;
int k = abyte0[2] >= 0 ? ((int) (abyte0[2])) : abyte0[2] + 256;
int l = abyte0[3] >= 0 ? ((int) (abyte0[3])) : abyte0[3] + 256;
int i1 = abyte0[4] >= 0 ? ((int) (abyte0[4])) : abyte0[4] + 256;
int j1 = (15 - (i & 0xf)) + (64 - (j & 0xf)) + (32 - (k & 0xf)) + (15 - (l & 0xf));
if(j1 != i1)
{
System.out.println("CRC-fail in variable '" + s + "'");
return 0;
} else
{
return (i << 24) + (j << 16) + (k << 8) + (l << 0);
}
} else
{
System.out.println(s);
return 0;
}
}
public static void put(String s, String s1)
{
put(s, s1.getBytes());
}
public static void put(String s, int i)
{
int j = i >> 24 & 0xff;
int k = i >> 16 & 0xff;
int l = i >> 8 & 0xff;
int i1 = i >> 0 & 0xff;
int j1 = (15 - (j & 0xf)) + (64 - (k & 0xf)) + (32 - (l & 0xf)) + (15 - (i1 & 0xf)) & 0xff;
byte abyte0[] = {
(byte)j, (byte)k, (byte)l, (byte)i1, (byte)j1
};
put(s, abyte0);
}
public static void put(String s, byte abyte0[])
{
s = s.toLowerCase();
for(int i = 0; i < variables.size(); i++)
{
String s1 = (String)variables.elementAt(i);
if(s1.equals(s))
{
values.setElementAt(abyte0, i);
return;
}
}
variables.addElement(s);
values.addElement(abyte0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -