📄 settings.java
字号:
// Decompiled by DJ v3.7.7.81 Copyright 2004 Atanas Neshkov Date: 2008-6-16 11:25:35
// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
// Decompiler options: packimports(3)
// Source File Name: Settings.java
package com.eightmotions.util;
import java.io.*;
import java.util.Enumeration;
import java.util.Hashtable;
import javax.microedition.midlet.MIDlet;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;
// Referenced classes of package com.eightmotions.util:
// UtilMidp
public class Settings
{
public static synchronized Settings getInstance(MIDlet midlet, String inName)
throws IOException, RecordStoreException
{
if(m_store == null)
m_store = new Settings(midlet, inName);
return m_store;
}
private Settings(MIDlet midlet, String name)
throws IOException, RecordStoreException
{
m_valuesChanged = false;
m_properties = new Hashtable();
m_midlet = midlet;
recordName = name;
load();
}
boolean exists(String name)
{
return getProperty(name) != null;
}
private synchronized String getProperty(String name)
{
String value = (String)m_properties.get(name);
if(value == null && m_midlet != null)
{
value = m_midlet.getAppProperty(name);
if(value != null)
m_properties.put(name, value);
}
return value;
}
public boolean getBooleanProperty(String name, boolean defaultValue)
{
String value = getProperty(name);
if(value != null)
return value.equals("true") || value.equals("1");
else
return defaultValue;
}
public int getIntProperty(String name, int defaultValue)
{
String value;
value = getProperty(name);
// if(value == null)
// break MISSING_BLOCK_LABEL_17;
return Integer.parseInt(value);
}
public String getStringProperty(String name, String defaultValue)
{
Object value = getProperty(name);
return value == null ? defaultValue : value.toString();
}
private synchronized void load()
throws IOException, RecordStoreException
{
RecordStore rs;
DataInputStream din;
rs = null;
ByteArrayInputStream bin = null;
din = null;
m_valuesChanged = false;
m_properties.clear();
rs = RecordStore.openRecordStore(recordName, true);
if(rs.getNumRecords() == 0)
{
rs.addRecord(null, 0, 0);
} else
{
byte data[] = rs.getRecord(1);
if(data != null)
{
bin = new ByteArrayInputStream(data);
din = new DataInputStream(bin);
int num = din.readInt();
do
{
if(num-- <= 0)
break;
String name = din.readUTF();
String value = din.readUTF();
m_properties.put(name, value);
if(UtilMidp.DEBUG)
System.out.println("Reading " + name + " Value:" + value);
} while(true);
}
}
if(din != null)
try
{
din.close();
}
catch(Exception e) { }
if(rs != null)
try
{
rs.closeRecordStore();
}
catch(Exception e) { }
// break MISSING_BLOCK_LABEL_219;
// Exception exception;
// exception;
if(din != null)
try
{
din.close();
}
catch(Exception e) { }
if(rs != null)
try
{
rs.closeRecordStore();
}
catch(Exception e) { }
// throw exception;
}
public synchronized void save(boolean force)throws Exception
{
RecordStore rs;
ByteArrayOutputStream bout;
DataOutputStream dout;
if(!m_valuesChanged && !force)
return;
rs = null;
bout = new ByteArrayOutputStream();
dout = new DataOutputStream(bout);
dout.writeInt(m_properties.size());
Enumeration e = m_properties.keys();
do
{
if(!e.hasMoreElements())
break;
String name = (String)e.nextElement();
String value = m_properties.get(name).toString();
dout.writeUTF(name);
dout.writeUTF(value);
if(UtilMidp.DEBUG)
System.out.println("SETTING Writing " + name + " Value:" + value);
} while(true);
byte data[] = bout.toByteArray();
rs = RecordStore.openRecordStore(recordName, false);
rs.setRecord(1, data, 0, data.length);
// Exception e;
try
{
dout.close();
}
// Misplaced declaration of an exception variable
catch(Exception e1)
{
e1.printStackTrace();
}
if(rs != null)
try
{
rs.closeRecordStore();
}
// Misplaced declaration of an exception variable
catch(Exception e2)
{
e2.printStackTrace();
}
// break MISSING_BLOCK_LABEL_291;
// e;
// e.printStackTrace();
try
{
dout.close();
}
// Misplaced declaration of an exception variable
catch(Exception e3)
{
e3.printStackTrace();
}
if(rs != null)
try
{
rs.closeRecordStore();
}
// Misplaced declaration of an exception variable
catch(Exception e4)
{
e4.printStackTrace();
}
// break MISSING_BLOCK_LABEL_291;
// Exception exception;
// exception;
try
{
dout.close();
}
catch(Exception e5)
{
e5.printStackTrace();
}
if(rs != null)
try
{
rs.closeRecordStore();
}
catch(Exception e6)
{
e6.printStackTrace();
}
// throw exception;
}
public void setBooleanProperty(String name, boolean value)
{
setStringProperty(name, value ? "true" : "false");
}
public void setIntProperty(String name, int value)
{
setStringProperty(name, Integer.toString(value));
}
public synchronized boolean setStringProperty(String name, String value)
{
if(name == null && value == null)
{
return false;
} else
{
m_properties.put(name, value);
m_valuesChanged = true;
return true;
}
}
public Hashtable getProperties()
{
return m_properties;
}
private static Settings m_store;
private MIDlet m_midlet;
private boolean m_valuesChanged;
private Hashtable m_properties;
private String recordName;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -