Details
-
Improvement
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.0
-
None
-
None
-
All
Description
From the Java 6 SDK, the socket.close() method is responsible for also closing its input and output streams. But if socket.close() throws an IOException before the streams could be closed, the streams will remain open and they will also not be set to null. We need a way to ensure that the input and output streams are also closed. There are various ways to achieve this:
Proposal 1:
Implement a public SocketClient.paranoidDisconnect() method that makes sure the socket, input and output are closed:
public void paranoidDisconnect() {
try
catch (IOException ioe) {
// the first thing that SocketClient.disconnect() does is to close the socket
// but if that fails, we have to manually close the input and output streams
if (this.input != null) {
try
catch (IOException ioe2) {
}
}
if (this.output != null) {
try
catch (IOException ioe3) {
}
}
}
finally
}
Proposal 2:
Expose the socket, input and output stream objects with getter methods at the SocketClient level, handing the responsibility over to the calling application. TelnetClient already exposes the input and output streams with getInputStream() and getOutputStream() methods respectively.
Attachments
Issue Links
- is related to
-
NET-278 FTPClient.disconnect() shouldn't throw IOException
- Closed