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

📄 settings.java

📁 手机的联网应用
💻 JAVA
字号:
package cn.com.javachen;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;

public class Settings extends BaseRMS {
	private String urlString = "61.147.254.71";
	private String port="7878";
	private String name = "0401256";
	private String password = "111";
	private int cmnet=0;
	private int datatype=1;

	public Settings(String rmsName) {
		super(rmsName);
	}

	public void loadSettings() throws Exception {
		try {
			// Will call either loadData() or createDefaultData()
			this.open();

			// Add any other neccessary processing, in this case there is none

			// Close
			if (this.getRecordStore() != null)
				this.close();
		} catch (Exception e) {
			throw new Exception("Error loading Settings" + e);
		}
	}

	public String getUrlString() {
		return urlString;
	}

	public String getPort() {
		return port;
	}

	public String getName() {
		return name;
	}

	public String getPassword() {
		return password;
	}

	public int getCmnet() {
		return cmnet;
	}

	public int getDataType() {
		return datatype;
	}

	public void updateSettings(String urlString,String port, String name, String password,int cmnet,int datatype)
			throws Exception {
		try {
			// load current scores
			this.open();

			// update data
			this.urlString = urlString;
			this.port=port;
			this.name = name;
			this.password = password;
			this.cmnet=cmnet;
			this.datatype=datatype;

			// Update High Scores
			updateData();

			// close
			if (this.getRecordStore() != null)
				this.close();
		} catch (Exception e) {
			throw new Exception(this.getRMSName() + "::updateSettings::" + e);
		}
	}

	protected void loadData() throws Exception {
		try {
			
			byte[] record = this.getRecordStore().getRecord(1);
			DataInputStream istream = new DataInputStream(
					new ByteArrayInputStream(record, 0, record.length));
			urlString=istream.readUTF().toString().trim();
			
			byte[] record1 = this.getRecordStore().getRecord(2);
			DataInputStream istream1 = new DataInputStream(
					new ByteArrayInputStream(record1, 0, record1.length));
			port=istream1.readUTF().toString().trim();
			
			byte[] record2 = this.getRecordStore().getRecord(3);
			DataInputStream istream2 = new DataInputStream(
					new ByteArrayInputStream(record2, 0, record2.length));
			name = istream2.readUTF().toString().trim();
			
			byte[] record3 = this.getRecordStore().getRecord(4);
			DataInputStream istream3 = new DataInputStream(
					new ByteArrayInputStream(record3, 0, record3.length));
			password = istream3.readUTF().toString().trim();
			
			byte[] record4 = this.getRecordStore().getRecord(5);
			DataInputStream istream4 = new DataInputStream(
					new ByteArrayInputStream(record4, 0, record4.length));
			cmnet=istream4.readInt();
			
			byte[] record5=this.getRecordStore().getRecord(6);
			DataInputStream istream5 = new DataInputStream(
					new ByteArrayInputStream(record5, 0, record5.length));
			datatype=istream5.readInt();
			
		} catch (Exception e) {
			throw new Exception(this.getRMSName() + "::loadData::" + e);
		}
	}

	protected void createDefaultData() throws Exception {
		try {
			ByteArrayOutputStream bstream = new ByteArrayOutputStream(12);
			DataOutputStream ostream = new DataOutputStream(bstream);
			ostream.writeUTF(urlString);			
			ostream.flush();
			ostream.close();
			byte[] record = bstream.toByteArray();
			this.getRecordStore().addRecord(record, 0, record.length);
			
			ByteArrayOutputStream bstream1 = new ByteArrayOutputStream(12);
			DataOutputStream ostream1 = new DataOutputStream(bstream1);
			ostream1.writeUTF(port);			
			ostream1.flush();
			ostream1.close();
			byte[] record1 = bstream1.toByteArray();
			this.getRecordStore().addRecord(record1, 0, record1.length);
			
			ByteArrayOutputStream bstream2 = new ByteArrayOutputStream(12);
			DataOutputStream ostream2 = new DataOutputStream(bstream2);
			ostream2.writeUTF(name);			
			ostream2.flush();
			ostream2.close();
			byte[] record2 = bstream2.toByteArray();
			this.getRecordStore().addRecord(record2, 0, record2.length);
			
			ByteArrayOutputStream bstream3 = new ByteArrayOutputStream(12);
			DataOutputStream ostream3 = new DataOutputStream(bstream3);
			ostream3.writeUTF(password);			
			ostream3.flush();
			ostream3.close();
			byte[] record3 = bstream3.toByteArray();
			this.getRecordStore().addRecord(record3, 0, record3.length);
			
			ByteArrayOutputStream bstream4 = new ByteArrayOutputStream(12);
			DataOutputStream ostream4 = new DataOutputStream(bstream4);
			ostream4.writeInt(cmnet);			
			ostream4.flush();
			ostream4.close();
			byte[] record4 = bstream4.toByteArray();
			this.getRecordStore().addRecord(record4, 0, record4.length);
			
			ByteArrayOutputStream bstream5 = new ByteArrayOutputStream(12);
			DataOutputStream ostream5 = new DataOutputStream(bstream5);
			ostream5.writeInt(datatype);			
			ostream5.flush();
			ostream5.close();
			byte[] record5 = bstream5.toByteArray();
			this.getRecordStore().addRecord(record5, 0, record5.length);
		} catch (Exception e) {
			throw new Exception(this.getRMSName() + "::createDefaultData::" + e);
		}
	}

	protected void updateData() throws Exception {
		try {
			ByteArrayOutputStream bstream = new ByteArrayOutputStream(12);
			DataOutputStream ostream = new DataOutputStream(bstream);
			ostream.writeUTF(urlString);			
			ostream.flush();
			ostream.close();
			byte[] record = bstream.toByteArray();
			this.getRecordStore().setRecord(1, record, 0, record.length);
			
			ByteArrayOutputStream bstream1 = new ByteArrayOutputStream(12);
			DataOutputStream ostream1 = new DataOutputStream(bstream1);
			ostream1.writeUTF(port);			
			ostream1.flush();
			ostream1.close();
			byte[] record1 = bstream1.toByteArray();
			this.getRecordStore().setRecord(2, record1, 0, record1.length);
			
			ByteArrayOutputStream bstream2= new ByteArrayOutputStream(12);
			DataOutputStream ostream2 = new DataOutputStream(bstream2);
			ostream2.writeUTF(name);			
			ostream2.flush();
			ostream2.close();
			byte[] record2 = bstream2.toByteArray();
			this.getRecordStore().setRecord(3, record2, 0, record2.length);
			
			ByteArrayOutputStream bstream3= new ByteArrayOutputStream(12);
			DataOutputStream ostream3 = new DataOutputStream(bstream3);
			ostream3.writeUTF(password);			
			ostream3.flush();
			ostream3.close();
			byte[] record3 = bstream3.toByteArray();
			this.getRecordStore().setRecord(4, record3, 0, record3.length);
			
			ByteArrayOutputStream bstream4= new ByteArrayOutputStream(12);
			DataOutputStream ostream4 = new DataOutputStream(bstream4);
			ostream4.writeInt(cmnet);			
			ostream4.flush();
			ostream4.close();
			byte[] record4 = bstream4.toByteArray();
			this.getRecordStore().setRecord(5, record4, 0, record4.length);
			
			ByteArrayOutputStream bstream5 = new ByteArrayOutputStream(12);
			DataOutputStream ostream5 = new DataOutputStream(bstream5);
			ostream5.writeInt(datatype);			
			ostream5.flush();
			ostream5.close();
			byte[] record5 = bstream5.toByteArray();
			this.getRecordStore().setRecord(6,record5, 0, record5.length);
		} catch (Exception e) {
			throw new Exception(this.getRMSName() + "::updateData::" + e);
		}
	}
}

⌨️ 快捷键说明

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