public void close ( ) { boolean performClose = false ; ; synchronized ( this ) { if ( ! closing && state == CHANNEL_OPEN ) { performClose = closing = true ; } } if ( performClose ) { synchronized ( listeners ) { for ( Enumeration < ChannelEventListener > e = listeners . elements ( ) ; e . hasMoreElements ( ) ; ) { ( e . nextElement ( ) ) . channelClosing ( this ) ; } } try { // Close the ChannelOutputStream out . close ( ! isLocalEOF ) ; // Send our close message ByteArrayWriter msg = new ByteArrayWriter ( 5 ) ; msg . write ( SSH_MSG_CHANNEL_CLOSE ) ; msg . writeInt ( remoteid ) ; try { if ( Log . isDebugEnabled ( ) ) { Log . debug ( this , "Sending SSH_MSG_CHANNEL_CLOSE id=" + channelid + " rid=" + remoteid ) ; } connection . sendMessage ( msg . toByteArray ( ) , true ) ; } catch ( SshException ex1 ) { if ( Log . isDebugEnabled ( ) ) { Log . debug ( this , "Exception attempting to send SSH_MSG_CHANNEL_CLOSE id=" + channelid + " rid=" + remoteid , ex1 ) ; } } finally { msg . close ( ) ; } this . state = CHANNEL_CLOSED ; } catch ( EOFException eof ) { // Ignore this is the message store informing of close/eof } catch ( SshIOException ex ) { if ( Log . isDebugEnabled ( ) ) { Log . debug ( this , "SSH Exception during close reason=" + ex . getRealException ( ) . getReason ( ) + " id=" + channelid + " rid=" + remoteid , ex . getRealException ( ) ) ; } // IO Error during close so the connection has dropped connection . transport . disconnect ( TransportProtocol . CONNECTION_LOST , "IOException during channel close: " + ex . getMessage ( ) ) ; } catch ( IOException ex ) { if ( Log . isDebugEnabled ( ) ) { Log . debug ( this , "Exception during close id=" + channelid + " rid=" + remoteid , ex ) ; } // IO Error during close so the connection has dropped connection . transport . disconnect ( TransportProtocol . CONNECTION_LOST , "IOException during channel close: " + ex . getMessage ( ) ) ; } finally { checkCloseStatus ( ms . isClosed ( ) ) ; } } }
Closes the channel . No data may be sent or receieved after this method completes .