bluetoothconsole.java

来自「一个基于PlaceLab的室内和室外的智能导航系统」· Java 代码 · 共 71 行

JAVA
71
字号
/* * Created on Sep 24, 2004 * */package org.placelab.midp;import java.io.DataOutputStream;import java.io.IOException;import javax.microedition.io.Connector;import javax.microedition.io.StreamConnection;import javax.microedition.rms.RecordEnumeration;import javax.microedition.rms.RecordStore;import javax.microedition.rms.RecordStoreException;import org.placelab.midp.server.BluetoothService;import org.placelab.util.StringUtil;public class BluetoothConsole {		private static BluetoothConsole instance = null;		private DataOutputStream out;		private BluetoothConsole() throws RecordStoreException, IOException {		RecordStore store = RecordStore.openRecordStore(BluetoothClient.RECORDSTORE_NAME, false);		RecordEnumeration re = store.enumerateRecords(null, null, false);		while (re.hasNextElement()) {			try {				String[] server = StringUtil.split(new String(re.nextRecord()));				StreamConnection conn = (StreamConnection)Connector.open(server[1]);				out = conn.openDataOutputStream();				out.writeByte(BluetoothService.CONSOLE_SERVICE);				out.flush();				break;			} catch (IOException e) {				out = null;				continue;			}		}		store.closeRecordStore();		if (out == null) throw new IOException("No Placelab Server Found");	}		private static BluetoothConsole getInstance() {		try {			if (instance == null) instance = new BluetoothConsole();		} catch (Exception e) {			instance = null;		}				return instance;	}		public static void println(String line) {		BluetoothConsole console = getInstance();		if (console == null) return;				console.send(line);	}		private void send(String line) {		try {			out.writeUTF(line);			out.flush();		} catch (IOException e) {}	}}

⌨️ 快捷键说明

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