Java Code Examples for javax.microedition.io.StreamConnection#close()
The following examples show how to use
javax.microedition.io.StreamConnection#close() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Protocol.java From pluotsorbet with GNU General Public License v2.0 | 6 votes |
/** * 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; } } } }
Example 2
Source File: TestSSLStreamConnection.java From pluotsorbet with GNU General Public License v2.0 | 6 votes |
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(); } }
Example 3
Source File: TestSSLStreamConnection.java From pluotsorbet with GNU General Public License v2.0 | 6 votes |
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(); } }
Example 4
Source File: TestSSLStreamConnection.java From pluotsorbet with GNU General Public License v2.0 | 6 votes |
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(); } } }
Example 5
Source File: TestSSLStreamConnection.java From pluotsorbet with GNU General Public License v2.0 | 6 votes |
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(); } }
Example 6
Source File: TestSSLStreamConnection.java From pluotsorbet with GNU General Public License v2.0 | 6 votes |
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(); } }