📄 rmsdata.java
字号:
package x;
import javax.microedition.rms.*;
import java.io.*;
import java.util.*;
public class RMSData
{
public static String title,parent,table,child,adress;
public RMSData()
{
}
public static byte[] encode(String title,String parent,String table,String child,String adress)
{
byte[] result=null;
try
{
ByteArrayOutputStream bos=new ByteArrayOutputStream();
DataOutputStream dos=new DataOutputStream(bos);
dos.writeUTF(title);
dos.writeUTF(parent);
dos.writeUTF(table);
dos.writeUTF(child);
dos.writeUTF(adress);
result=bos.toByteArray();
dos.close();
bos.close();
}
catch(Exception e)
{
e.printStackTrace();
}
return result;
}
public static void decode(byte[] data)
{
try
{
ByteArrayInputStream bis=new ByteArrayInputStream(data);
DataInputStream dis=new DataInputStream(bis);
title=dis.readUTF();
parent=dis.readUTF();
table=dis.readUTF();
child=dis.readUTF();
adress=dis.readUTF();
dis.close();
bis.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public static RecordStore openRsAnyway(String table)
{
RecordStore rs=null;
if(table.length()>32)
return null;
try
{
rs=RecordStore.openRecordStore(table,true);
return rs;
}
catch(Exception e)
{
e.printStackTrace();
return null;
}
}
public static boolean writeRS(String tableName,String title,String parent,String table,String child,String adress)
{
RecordStore rs=openRsAnyway(tableName);
if(rs==null)
{
System.out.println("table open fail");
}
else
{
try
{
byte tmp[]=encode(title,parent,table,child,adress);
rs.addRecord(tmp,0,tmp.length);
rs.closeRecordStore();
}
catch(Exception e)
{
e.printStackTrace();
return false;
}
}
return true;
}
public static Vector readRS(String tableName)
{
RecordStore rs=openRsAnyway(tableName);
Vector vector=new Vector();
if(rs==null)
{
System.out.println("table open fail");
}
else
{
try
{
RecordEnumeration re=rs.enumerateRecords(null,null,false);
while(re.hasNextElement())
{
byte tmp[]=re.nextRecord();
decode(tmp);
menuStruct menuStruct=new menuStruct(title,parent,table,child,adress);
vector.addElement(menuStruct);
}
rs.closeRecordStore();
}
catch(Exception e)
{
e.printStackTrace();
}
}
// System.out.println("menu.vector"+vector.size());
return vector;
}
public static boolean deleteRS(String tableName)
{
RecordStore rs=openRsAnyway(tableName);
if(rs==null)
{
System.out.println("table open fail");
}
else
{
try
{
RecordEnumeration re=rs.enumerateRecords(null,null,false);
while(re.hasNextElement())
{
int id=re.nextRecordId();
rs.deleteRecord(id);
}
rs.closeRecordStore();
}
catch(Exception e)
{
e.printStackTrace();
return false;
}
}
return true;
}
public static boolean updateVersion(String tableName,String value)
{
RecordStore rs=openRsAnyway(tableName);
if(rs==null)
{
System.out.println("table open fail");
}
else
{
try
{
RecordEnumeration re=rs.enumerateRecords(null,null,false);
while(re.hasNextElement())
{
int id=re.nextRecordId();
title=value;
byte tmp[]=encode(title,"xx","xx","xx","xx");
rs.setRecord(id,tmp,0,tmp.length);
break;
}
//rs.setRecord(0,tmp,0,tmp.length);
rs.closeRecordStore();
}
catch(Exception e)
{
e.printStackTrace();
return false;
}
}
return true;
}
public static boolean downloadFlag(String tableName,String value)
{ System.out.println("rmsFlag");
RecordStore rs=openRsAnyway(tableName);
boolean Flag=false;
String version;
if(rs==null)
{
System.out.println("table open fail");
}
else
{
try
{
if(rs.getNumRecords()==0)
{
//锟斤拷锟斤拷锟斤拷
rs.closeRecordStore();
updateVersion(tableName,value);
Flag=true;
}
else
{
//锟斤拷锟斤拷
Vector vector=new Vector();
vector=readRS(tableName);
menuStruct menuStruct=(menuStruct)vector.elementAt(0);
version=menuStruct.getTitle();
System.out.println(version+","+value);
if(version.equals(value))
{ System.out.println("version"+version+value);
Flag= false;
}
else
{
updateVersion(tableName,value);
System.out.println(version+","+value);
Flag= true;
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
System.out.println(Flag);
return Flag;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -