?? sysparam.java
字號:
/* * SysParamter.java * * Created on 2003年11月21日, 上午10:12 */package handenglish;import java.util.*;import java.io.*;import javax.microedition.rms.*;/* * @author Administrator */public class SysParam { public long lastUpdate; public String storeName; public int storeNo; public int storeVolume; public long msgPostDate; public boolean isRead; public String msg; public int curUnit; // private boolean loaded; private Hashtable m_diffIndex; private static SysParam instance; public static int MAX_DIFF_NUMBER=50; //難記單詞庫最大存儲個數 /** Creates a new instance of SysParamter */ private SysParam() { m_diffIndex=new Hashtable(); getParameter(); } public static synchronized SysParam getInstance() { if ( instance == null ) instance = new SysParam(); return instance; } /* public long getLastUpdate() { return lastUpdate; } public String getStoreName() { return storeName; } public int getStoreNo() { return storeNo; } public int getStoreVolume() { return storeVolume; } */ private void getParameter() { DbApi systemDb = new DbApi( "systemdb" ); RecordEnumeration tempEnumRecord = systemDb.getAllRecord(); if(tempEnumRecord.hasNextElement()) { try{ byte[] tempRecord = tempEnumRecord.nextRecord(); ByteArrayInputStream tempDb = new ByteArrayInputStream(tempRecord); DataInputStream tempSysDb=new DataInputStream(tempDb); lastUpdate = tempSysDb.readLong(); storeNo = tempSysDb.readInt(); storeName=tempSysDb.readUTF(); storeVolume = tempSysDb.readInt(); isRead = tempSysDb.readBoolean(); msgPostDate = tempSysDb.readLong(); msg = tempSysDb.readUTF(); curUnit = tempSysDb.readInt(); // if ( curUnit <= 0 ) curUnit =1; }catch(Exception e){} } else { lastUpdate = 0; storeName = ""; storeNo = -1; storeVolume = -1; isRead = true; msg =""; msgPostDate = 0; curUnit = 1; } // loaded = true; boolean close=systemDb.closeDatabase(); } /* public void setLastUpdate(long newDate) { lastUpdate = newDate; } public void setStoreName( String newName ) { storeName = newName; } public void setStoreNo( int newNo ) { storeNo = newNo; } public void setStoreVolume( int newVol ) { storeVolume = newVol; } */ public void setParameter() { DbApi systemDb = new DbApi( "systemdb" ); systemDb.deleteAll(); ByteArrayOutputStream tempBos=new ByteArrayOutputStream(); DataOutputStream tempDos=new DataOutputStream(tempBos); try { tempDos.writeLong(lastUpdate); tempDos.writeInt(storeNo); tempDos.writeUTF(storeName); tempDos.writeInt(storeVolume); tempDos.writeBoolean( isRead ); tempDos.writeLong( msgPostDate ); tempDos.writeUTF( msg ); tempDos.writeInt( curUnit ); byte[] tempB=tempBos.toByteArray(); tempBos.close(); systemDb.addDatabase(tempB); } catch ( Exception e ){} finally { systemDb.closeDatabase(); } } public void getUnit(int nowUnitId,int nowNup,Vector nowVector){ int totalNumber=0; DbApi dbApi=new DbApi( "wordsdb" ); try{ byte[] tData = new byte[100]; int tId,tLen; RecordEnumeration tempEnumRecord = dbApi.getAllRecord(); ByteArrayInputStream tempDb = new ByteArrayInputStream(tData); DataInputStream tempWordsDb=new DataInputStream(tempDb); while(tempEnumRecord.hasNextElement()) { tId = tempEnumRecord.nextRecordId(); //byte[] tempRecord = tempEnumRecord.nextRecord(); if(totalNumber>=nowUnitId*20&&totalNumber<=nowUnitId*20+19){ tLen = dbApi.myRecordStore.getRecordSize( tId ); if ( tLen > 100 ) tData = new byte[tLen+40]; dbApi.myRecordStore.getRecord( tId,tData,0 ); tempDb.reset(); String tempS; tempS=tempWordsDb.readUTF(); nowVector.addElement(tempS); tempS=tempWordsDb.readUTF(); nowVector.addElement(tempS); tempS=tempWordsDb.readUTF(); nowVector.addElement(tempS); tempDb.close(); } else if(totalNumber>=nowUnitId*20+20){ break; } totalNumber++; } }catch(Exception e) {} finally { dbApi.closeDatabase(); } } public boolean haveDiffSpace() { DbApi m_diffDb=new DbApi( "diffdb" ); if(m_diffDb.getRecordNum()==MAX_DIFF_NUMBER){ boolean close=m_diffDb.closeDatabase(); return false; } else{ boolean close=m_diffDb.closeDatabase(); return true; } } public void getDiffUnit(Vector nowVector) { DbApi m_diffDb=new DbApi( "diffdb" ); try{ byte[] tData = new byte[100]; int tId,tLen; RecordEnumeration tempEnumRecord = m_diffDb.getAllRecord(); ByteArrayInputStream tempDb = new ByteArrayInputStream(tData); DataInputStream tempWordsDb=new DataInputStream(tempDb); while(tempEnumRecord.hasNextElement()) { tId = tempEnumRecord.nextRecordId(); //byte[] tempRecord = tempEnumRecord.nextRecord(); tLen = m_diffDb.myRecordStore.getRecordSize( tId ); if ( tLen > tData.length ) tData = new byte[tLen+40]; m_diffDb.myRecordStore.getRecord( tId,tData,0 ); tempDb.reset(); String tempS; tempWordsDb.readInt(); tempS=tempWordsDb.readUTF(); nowVector.addElement(tempS); tempS=tempWordsDb.readUTF(); nowVector.addElement(tempS); tempS=tempWordsDb.readUTF(); nowVector.addElement(tempS); tempDb.close(); } }catch(Exception e) {} finally { m_diffDb.closeDatabase(); } } public void writeWord(String nowWord, String nowChinese, String nowSpell) { DbApi m_diffDb=new DbApi( "diffdb" ); byte[] tempB; if (!haveDiffSpace()){ return; } try { if(m_diffDb!=null) { Integer tempInteger=(Integer)m_diffIndex.get(nowWord); if(tempInteger==null) { int tempI=m_diffDb.myRecordStore.getNextRecordID(); ByteArrayOutputStream tempBos=new ByteArrayOutputStream(); DataOutputStream tempDos=new DataOutputStream(tempBos); tempDos.writeInt(tempI); tempDos.writeUTF(nowWord); tempDos.writeUTF(nowChinese); tempDos.writeUTF(nowSpell); tempB=tempBos.toByteArray(); tempBos.close(); tempI=m_diffDb.addDatabase(tempB); if (tempI>0) { m_diffIndex.put(nowWord,new Integer(tempI)); } } } } catch(Exception dbE) {} finally{ m_diffDb.closeDatabase();} } public boolean deleteWord(String nowWord) { DbApi m_diffDb=new DbApi( "diffdb" ); m_diffDb.recordIndex(m_diffIndex); Integer tempId; tempId=(Integer)m_diffIndex.get(nowWord); if(tempId!=null) { m_diffIndex.remove(nowWord); return m_diffDb.deleteRecord(tempId.intValue()); } else return false; }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -