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


Java StreamConnection.close方法代码示例

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


在下文中一共展示了StreamConnection.close方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: disconnect

import javax.microedition.io.StreamConnection; //导入方法依赖的package包/类
/** 
 * Disconnect from the underlying socket transport.
 * Closes the low level socket connection and the input and 
 * output streams used by the socket.
 * <p>
 * Warning: A subclass that implements connect, should also implement this
 * method without calling this method.
 *
 * @param connection connection return from {@link #connect()}
 * @param inputStream input stream opened from <code>connection</code>
 * @param outputStream output stream opened from <code>connection</code>
 * @exception IOException if an I/O error occurs while
 *                  the connection is terminated.
 * @exception IOException is thrown if the connection or 
 *                        associated streams cannot be closed
 */
protected void disconnect(StreamConnection connection,
       InputStream inputStream, OutputStream outputStream)
       throws IOException {
    try {
        if (connection != null) {
            connection.close();
        }
    } finally {
        try {
            if (outputStream != null) {
                outputStream.close();
            }
        } finally {
            if (inputStream != null) {
                inputStream.close();
            }
        }
    }
}
 
开发者ID:tomatsu,项目名称:squawk,代码行数:36,代码来源:Protocol.java

示例2: run

import javax.microedition.io.StreamConnection; //导入方法依赖的package包/类
@Override
public void run() {
	LOG.info("Listening for invitation connections");
	// Listen until a connection is received or the socket is closed
	try {
		StreamConnection s = serverSocket.acceptAndOpen();
		LOG.info("Incoming connection");
		if(!socketLatch.set(s)) {
			LOG.info("Closing redundant connection");
			s.close();
		}
	} catch(IOException e) {
		// This is expected when the socket is closed
		if(LOG.isLoggable(INFO)) LOG.info(e.toString());
	}
}
 
开发者ID:kiggundu,项目名称:briar,代码行数:17,代码来源:BluetoothPlugin.java

示例3: disconnect

import javax.microedition.io.StreamConnection; //导入方法依赖的package包/类
/** 
 * Disconnect from the underlying socket transport.
 * Closes the low level socket connection and the input and 
 * output streams used by the socket.
 * <p>
 * Warning: A subclass that implements connect, should also implement this
 * method without calling this method.
 *
 * @param connection connection return from {@link #connect()}
 * @exception IOException if an I/O error occurs while
 *                  the connection is terminated.
 * @exception IOException is thrown if the connection or 
 *                        associated streams cannot be closed
 */
protected void disconnect(StreamConnection connection)
       throws IOException {
    try {
        if (connection != null) {
            connection.close();
        }
    } finally {
        try {
            if (streamOutput != null) {
                streamOutput.close();
                streamOutput = null;
            }
        } finally {
            if (streamInput != null) {
                streamInput.close();
                streamInput = null;
            }
        }
    }
}
 
开发者ID:mozilla,项目名称:pluotsorbet,代码行数:35,代码来源:Protocol.java

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: tryToClose

import javax.microedition.io.StreamConnection; //导入方法依赖的package包/类
private void tryToClose(StreamConnection s) {
	try {
		if(s != null) s.close();
	} catch(IOException e) {
		if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
	}
}
 
开发者ID:kiggundu,项目名称:briar,代码行数:8,代码来源:BluetoothPlugin.java

示例10: 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


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