⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rmstore.java

📁 j2me radius soket radius client
💻 JAVA
字号:
package org.httpClient.com;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.*;
import javax.microedition.io.*;
import java.io.*;
import java.util.Date;
public class RMStore{
  private String cookie = null;
  private RecordStore rs = null;  
  private String name = null;
  private boolean newLog = false;
  private boolean logOpen = false;
  public RMStore(String name)
  {
	this.name = name;
    openRecStore();   
    readCookie();                      //因为cookie要
      // System.out.println("Client cookie: " + cookie);        
  }
  public void openRecStore()
  {
    try
    {
      // The second parameter indicates that the record store
      // should be created if it does not exist
      rs = RecordStore.openRecordStore(name, true);
    }
    catch (Exception e)
    {
    	e.printStackTrace();
    }
  }    
  public void closeRecStore()
  {
    try
    {
      rs.closeRecordStore();
    }
    catch (Exception e)
    {
    	e.printStackTrace();
    }
  }

  /*--------------------------------------------------
  * Write cookie to rms
  *-------------------------------------------------*/
  public void writeRecordLog(String str,boolean logOpen)
  {
	newLog = true;
    
    try
    {
          if(!this.logOpen){
        	  if(logOpen){
        		  String open =new Date()+ " 日志功能已开     ";
        		  byte[] openbyte = open.getBytes();
        		  rs.addRecord(openbyte,0,openbyte.length);
        		  this.logOpen = logOpen;
        	  }
          }else{
        	  if(!logOpen){
        		  String open =new Date()+ " 日志功能已关     ";
        		  byte[] openbyte = open.getBytes();
        		  rs.addRecord(openbyte,0,openbyte.length);
        		  this.logOpen = logOpen; 
        	  }
          }
         if(str.equals("")){
        	 //关闭信息
         }else{
        	 byte[] rec = str.getBytes();
        	 rs.addRecord(rec, 0, rec.length);        	
         }   
    }catch (Exception e){
       e.printStackTrace();
    }
  }
  public void writeRecord(String str)
  {
    byte[] rec = str.getBytes();
    try
    {
      rs.addRecord(rec, 0, rec.length);
    }
    catch (Exception e)
    {
       e.printStackTrace();
    }
  }
  /*--------------------------------------------------
  * Read cookie from rms
  *-------------------------------------------------*/
  public void readCookie()
  {
    try
    {
      byte[] recData = new byte[25]; 
      int len;

      if (rs.getNumRecords() > 0)
      {
        // Only one record will ever be written, safe to use '1'      
        if (rs.getRecordSize(1) > recData.length)
          recData = new byte[rs.getRecordSize(1)];
        len = rs.getRecord(1, recData, 0);

        cookie = new String(recData);
      }
    }
    catch (Exception e)  {
       e.printStackTrace();
    }
  }
  public String getCookie(){
	  return cookie;
  }
  public void setCookie(String cookie){
	   this.cookie = cookie;
  }
  public String readLog(){
	  String record = "",result =""; 
	  try{
		  for(int i=1;i< rs.getNextRecordID();i++){
			  record = new String(rs.getRecord(i));  
			  result = result + record;			  
		  }		
		  System.out.println("result is: "+result);
	  }catch(Exception e){
		  e.printStackTrace();
	  }
	  newLog = false;
	  return result;
  }
  public boolean getNewLog(){
	  return newLog;
  }
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -