本文整理汇总了Java中javax.microedition.io.StreamConnection.openOutputStream方法的典型用法代码示例。如果您正苦于以下问题:Java StreamConnection.openOutputStream方法的具体用法?Java StreamConnection.openOutputStream怎么用?Java StreamConnection.openOutputStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.microedition.io.StreamConnection
的用法示例。
在下文中一共展示了StreamConnection.openOutputStream方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: servicesDiscovered
import javax.microedition.io.StreamConnection; //导入方法依赖的package包/类
public void servicesDiscovered(int transID, ServiceRecord[] servRecord) {
if(servRecord!=null && servRecord.length>0){
connectionURL = servRecord[0].getConnectionURL(0,false);
}
isOK = true;
try {
StreamConnection streamConnection = (StreamConnection) Connector.open(connectionURL);
// send string
OutputStream outStream = streamConnection.openOutputStream();
out = new PrintWriter(new OutputStreamWriter(outStream));
// read response
InputStream inStream = streamConnection.openInputStream();
in = new BufferedReader(new InputStreamReader(inStream));
if(onConnectionSuccessful != null) onConnectionSuccessful.actionPerformed(new ActionEvent(this,ActionEvent.RESERVED_ID_MAX+1,""));
} catch (IOException e) {
e.printStackTrace();
}
}
示例2: testBasicSSLStreamConnection
import javax.microedition.io.StreamConnection; //导入方法依赖的package包/类
void testBasicSSLStreamConnection() throws IOException {
StreamConnection t = (StreamConnection)Connector.open(SOCKET_URL);
try {
SSLStreamConnection s =
new SSLStreamConnection(HOST, PORT, t.openInputStream(), t.openOutputStream(), KEY_STORE);
OutputStream os = s.openOutputStream();
InputStream is = s.openInputStream();
send(os, MESSAGE);
th.check(receive(is), MESSAGE);
os.close();
is.close();
s.close();
} finally {
t.close();
}
}
示例3: testMultipleSendsReceivesOnSameSocket
import javax.microedition.io.StreamConnection; //导入方法依赖的package包/类
void testMultipleSendsReceivesOnSameSocket() throws IOException {
StreamConnection t = (StreamConnection)Connector.open(SOCKET_URL);
try {
SSLStreamConnection s =
new SSLStreamConnection(HOST, PORT, t.openInputStream(), t.openOutputStream(), KEY_STORE);
OutputStream os = s.openOutputStream();
InputStream is = s.openInputStream();
for (int i = 0; i < 100; i++) {
String message = "Message n." + i;
send(os, message);
th.check(receive(is), message);
}
os.close();
is.close();
s.close();
} finally {
t.close();
}
}
示例4: testMultipleSendsReceivesOnMultipleSockets
import javax.microedition.io.StreamConnection; //导入方法依赖的package包/类
void testMultipleSendsReceivesOnMultipleSockets() throws IOException {
for (int i = 0; i < 100; i++) {
StreamConnection t = (StreamConnection)Connector.open(SOCKET_URL);
try {
SSLStreamConnection s =
new SSLStreamConnection(HOST, PORT, t.openInputStream(), t.openOutputStream(), KEY_STORE);
OutputStream os = s.openOutputStream();
InputStream is = s.openInputStream();
String message = "Message n." + i;
send(os, message);
th.check(receive(is), message);
os.close();
is.close();
s.close();
} finally {
t.close();
}
}
}
示例5: testSendOnClosedOutputStream
import javax.microedition.io.StreamConnection; //导入方法依赖的package包/类
void testSendOnClosedOutputStream() throws IOException {
StreamConnection t = (StreamConnection)Connector.open(SOCKET_URL);
try {
SSLStreamConnection s =
new SSLStreamConnection(HOST, PORT, t.openInputStream(), t.openOutputStream(), KEY_STORE);
OutputStream os = s.openOutputStream();
InputStream is = s.openInputStream();
os.close();
try {
send(os, MESSAGE);
th.fail("send on closed output stream");
} catch(Exception e) {
th.check(e, "java.io.InterruptedIOException: Stream closed");
}
is.close();
s.close();
} finally {
t.close();
}
}
示例6: testReceiveOnClosedInputStream
import javax.microedition.io.StreamConnection; //导入方法依赖的package包/类
void testReceiveOnClosedInputStream() throws IOException {
StreamConnection t = (StreamConnection)Connector.open(SOCKET_URL);
try {
SSLStreamConnection s =
new SSLStreamConnection(HOST, PORT, t.openInputStream(), t.openOutputStream(), KEY_STORE);
OutputStream os = s.openOutputStream();
InputStream is = s.openInputStream();
send(os, MESSAGE);
is.close();
try {
receive(is);
th.fail("receive on closed input stream");
} catch(Exception e) {
th.check(e, "java.io.InterruptedIOException: Stream closed");
}
os.close();
s.close();
} finally {
t.close();
}
}
示例7: openFile
import javax.microedition.io.StreamConnection; //导入方法依赖的package包/类
protected File openFile( String filename, boolean readMode, boolean appendMode, boolean updateMode, boolean binaryMode ) throws IOException {
String url = "file:///" + filename;
int mode = readMode? Connector.READ: Connector.READ_WRITE;
StreamConnection conn = (StreamConnection) Connector.open( url, mode );
File f = readMode?
new FileImpl(conn, conn.openInputStream(), null):
new FileImpl(conn, conn.openInputStream(), conn.openOutputStream());
/*
if ( appendMode ) {
f.seek("end",0);
} else {
if ( ! readMode )
conn.truncate(0);
}
*/
return f;
}
示例8: bluetoothServer
import javax.microedition.io.StreamConnection; //导入方法依赖的package包/类
/**
* start server creating an UUID and a connection String,
* then waiting for a device to connect
*/
private void bluetoothServer() {
if (sendReciveMessageThread.isAlive()) {
sendReciveMessageThread.interrupt();
}
try {
//Create a UUID for SPP
UUID uuid = new UUID("1101", true);
//Create the servicve url
String connectionString = "btspp://localhost:" + uuid + ";name=Sample SPP Server";
//open server url
streamConnNotifier = (StreamConnectionNotifier) Connector.open(connectionString);
//Wait for client connection
System.out.println("\nServer Started. Waiting for clients to connect...");
StreamConnection connection = streamConnNotifier.acceptAndOpen();
System.out.println("Remote device address: " + RemoteDevice.getRemoteDevice(connection).getBluetoothAddress());
System.out.println("Remote device name: " + RemoteDevice.getRemoteDevice(connection).getFriendlyName(true));
//the stream is opened both in and out
outStream = connection.openOutputStream();
inStream = connection.openInputStream();
connectionIsAvaible = true;
SingletonStaticGeneralStats.getInstance().setBluetoothServerCreated(true);
sendBluetoothMessage();
} catch (IOException e) {
e.printStackTrace();
//in case of problems, the connection is stopped
closeConnection();
}
}
示例9: getConnected
import javax.microedition.io.StreamConnection; //导入方法依赖的package包/类
/**
public boolean getConnected(){
return carConnected;
}
*/
public void connect() throws IOException {
System.out.println("attempting to connect");
con = (StreamConnection) Connector
.open("btspp://" + carDevice[0].getBluetoothAddress() + ":1");
System.out.println("Connection made");
os = con.openOutputStream();
carConnected = true;
}
示例10: startserver
import javax.microedition.io.StreamConnection; //导入方法依赖的package包/类
public void startserver() {
try {
String url = "btspp://localhost:" + uuid +
// new UUID( 0x1101 ).toString() +
";name=File Server";
StreamConnectionNotifier service = (StreamConnectionNotifier) Connector.open(url);
StreamConnection con = service.acceptAndOpen();
OutputStream dos = con.openOutputStream();
InputStream dis = con.openInputStream();
InputStreamReader daf = new InputStreamReader(System.in);
BufferedReader sd = new BufferedReader(daf);
RemoteDevice dev = RemoteDevice.getRemoteDevice(con);
String greeting = "hi";
dos.write(greeting.getBytes(Charset.forName("utf-8")));
dos.flush();
byte buffer[] = new byte[1024];
int bytes_read = dis.read(buffer);
String received = new String(buffer, 0, bytes_read, Charset.forName("utf-8"));
System.out.println
("Message:" + received + "From:"
+ dev.getBluetoothAddress());
// con.close();
} catch (IOException e) {
System.err.print(e.toString());
}
}
示例11: startclient
import javax.microedition.io.StreamConnection; //导入方法依赖的package包/类
public void startclient() {
try {
String remoteAddr = "001F8100011C";
String url = "btspp://" + remoteAddr + ":2";
StreamConnection con = (StreamConnection) Connector.open(url);
OutputStream os = con.openOutputStream();
InputStream is = con.openInputStream();
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader bufReader = new BufferedReader(isr);
RemoteDevice dev = RemoteDevice.getRemoteDevice(con);
/** if (dev !=null) {
File f = new File("test.xml");
InputStream sis = new FileInputStream("test.xml");
OutputStream oo = new FileOutputStream(f);
byte buf[] = new byte[1024];
int len;
while ((len=sis.read(buf))>0)
oo.write(buf,0,len);
sis.close();
} **/
if (con != null) {
while (true) {
//sender string
System.out.println("Server Found:"
+ dev.getBluetoothAddress() + "\r\n" + "Put your string" + "\r\n");
String str = bufReader.readLine();
os.write(str.getBytes());
//reciever string
byte buffer[] = new byte[1024];
int bytes_read = is.read(buffer);
String received = new String(buffer, 0, bytes_read);
System.out.println("client: " + received + "from:" + dev.getBluetoothAddress());
}
}
} catch (Exception e) {
}
}
示例12: main
import javax.microedition.io.StreamConnection; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException, InterruptedException {
LocalDevice localDevice = LocalDevice.getLocalDevice();
logger.info("Local Device Address: "+localDevice.getBluetoothAddress());
logger.info("Local Device Name: "+localDevice.getFriendlyName());
String device = resolveOBDDevice();
int channel = resolveChannel(device);
//connect to the OBD device
StreamConnection streamConnection = (StreamConnection) Connector.open(
String.format(deviceURL, device, channel));
OutputStream outStream = streamConnection.openOutputStream();
final InputStream inStream = streamConnection.openInputStream();
//initiate the looper
OBDCommandLooper looper = new OBDCommandLooper(inStream, outStream, "1CAF0514A493", new LocalListener(), new ConnectionListener() {
@Override
public void requestConnectionRetry(IOException reason) {
logger.warn("requestConnectionRetry: "+reason.getMessage());
}
@Override
public void onStatusUpdate(String message) {
logger.info("onStatusUpdate");
}
@Override
public void onConnectionVerified() {
logger.info("onConnectionVerified");
}
@Override
public void onAllAdaptersFailed() {
logger.warn("onAllAdaptersFailed");
}
});
looper.initialize(new LocalExecutor());
//do it 10 seconds
Thread.sleep(10000);
looper.stopLooper();
streamConnection.close();
}
示例13: BlaubotJsr82BluetoothConnection
import javax.microedition.io.StreamConnection; //导入方法依赖的package包/类
public BlaubotJsr82BluetoothConnection(IBlaubotDevice remoteDevice, StreamConnection streamConnection) throws IOException {
super(remoteDevice, streamConnection.openInputStream(), streamConnection.openOutputStream());
this.streamConnection = streamConnection;
}
示例14: BTGOEPConnection
import javax.microedition.io.StreamConnection; //导入方法依赖的package包/类
protected BTGOEPConnection(StreamConnection sock) throws IOException {
this.sock = sock;
is = sock.openInputStream();
os = sock.openOutputStream();
}