当前位置: 首页>>代码示例>>Java>>正文


Java StreamConnection.openInputStream方法代码示例

本文整理汇总了Java中javax.microedition.io.StreamConnection.openInputStream方法的典型用法代码示例。如果您正苦于以下问题:Java StreamConnection.openInputStream方法的具体用法?Java StreamConnection.openInputStream怎么用?Java StreamConnection.openInputStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.microedition.io.StreamConnection的用法示例。


在下文中一共展示了StreamConnection.openInputStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
    }
}
 
开发者ID:arminkz,项目名称:BluetoothChat,代码行数:19,代码来源:SPPClient.java

示例2: main

import javax.microedition.io.StreamConnection; //导入方法依赖的package包/类
public static void main(String[] args) {
    // Default to indicate error
    int returnCode = -1;
    try {
        StreamConnection connection = (StreamConnection) Connector.open("uei:");
        DataOutputStream out = connection.openDataOutputStream();
        out.writeInt(args.length);
        for (int i=0; i < args.length; i++) {
            out.writeUTF(args[i]);
        }
        out.close();
        InputStream in = connection.openInputStream();
        returnCode = in.read();
        in.close();
    } catch (Throwable t) {
        t.printStackTrace();
    } finally {
        System.exit(returnCode);
    }
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:21,代码来源:Launcher.java

示例3: 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();
    }
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:19,代码来源:TestSSLStreamConnection.java

示例4: 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();
    }
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:22,代码来源:TestSSLStreamConnection.java

示例5: 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();
        }
    }
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:22,代码来源:TestSSLStreamConnection.java

示例6: 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();
    }
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:23,代码来源:TestSSLStreamConnection.java

示例7: 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();
    }
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:24,代码来源:TestSSLStreamConnection.java

示例8: 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;
}
 
开发者ID:gnosygnu,项目名称:luaj_xowa,代码行数:18,代码来源:JmeIoLib.java

示例9: call

import javax.microedition.io.StreamConnection; //导入方法依赖的package包/类
@Override
public StreamConnection call() throws Exception {
	StreamConnection s = connectionTask.call();
	InputStream in = s.openInputStream();
	while (in.available() == 0) {
		LOG.info("Waiting for data");
		Thread.sleep(1000);
	}
	LOG.info("Data available");
	return s;
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:12,代码来源:BluetoothPlugin.java

示例10: 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();
    }
}
 
开发者ID:andrea9293,项目名称:pcstatus,代码行数:38,代码来源:BluetoothSPPServer.java

示例11: 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());
    }
}
 
开发者ID:Blaubot,项目名称:Blaubot,代码行数:30,代码来源:rfcommserver.java

示例12: 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) {
    }
}
 
开发者ID:Blaubot,项目名称:Blaubot,代码行数:40,代码来源:rfcommclient.java

示例13: 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();
}
 
开发者ID:matthesrieke,项目名称:OBDig,代码行数:48,代码来源:OBDTestClient.java

示例14: BlaubotJsr82BluetoothConnection

import javax.microedition.io.StreamConnection; //导入方法依赖的package包/类
public BlaubotJsr82BluetoothConnection(IBlaubotDevice remoteDevice, StreamConnection streamConnection) throws IOException {
    super(remoteDevice, streamConnection.openInputStream(), streamConnection.openOutputStream());
    this.streamConnection = streamConnection;
}
 
开发者ID:Blaubot,项目名称:Blaubot,代码行数:5,代码来源:BlaubotJsr82BluetoothConnection.java

示例15: BTGOEPConnection

import javax.microedition.io.StreamConnection; //导入方法依赖的package包/类
protected BTGOEPConnection(StreamConnection sock) throws IOException {
    this.sock = sock;
    is = sock.openInputStream();
    os = sock.openOutputStream();
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:6,代码来源:BTGOEPConnection.java


注:本文中的javax.microedition.io.StreamConnection.openInputStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。