JDK-5021772 : Provide a uniform interface for the close method on all io related objects
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.4.2
  • Priority: P5
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_9
  • CPU: x86
  • Submitted: 2004-03-27
  • Updated: 2004-03-29
  • Resolved: 2004-03-29
Related Reports
Duplicate :  
Description

Name: jl125535			Date: 03/26/2004


A DESCRIPTION OF THE REQUEST :
Please provide an interface that will allow me to deal with closing io related objects uniformly.

e.g.

package java.io;

public interface IOClose {
   public void close() throws IOException;
};

And make the following classes implement the interface.

java.io.Writer
java.io.Reader
java.io.InputStream

java.net.Socket
java.net.ServerSocket
java.net.DatagramSocket

java.nio.Channel

//---------------------------------------

And while you're at it, please do something similar for the classes in java.sql.

e.g.

package java.sql;

public interface SQLClose {
   public void close() throws SQLException;
};

and have all of the interfaces with a close method (nearly all of them) extend the interface.

Thank you.

JUSTIFICATION :
I would like to be able to write a uniform method and call it in my finally blocks.  Currently I have to embed multiple try/catch blocks inside my finally blocks to make sure that all io related resources are closed.  Or I have to have multiple methods for each object, and it's absolutely senseless.

Adding this interface and having the suggested classes implement it would be an additive change.  Aside from implementing the additional interface there would be no other changes to the classes mentioned above.
(Incident Review ID: 234221) 
======================================================================

Comments
EVALUATION The Closeable interface was added to the I/O classes and Channel in Tiger as part of the work for java.util.Scanner. ###@###.### 2004-03-29
29-03-2004