David M. Lloyd | 1 May 2008 17:07
Picon
Favicon

[PATCH 0/3] RFC: Adding Closeable to various JDK classes

This series of patches adds the java.io.Closeable interface to a few 
different core JDK classes.  Some of them are more obvious/better fits than 
others; I've split the patch up into groups based on how "out there" I 
think the idea is. :-)

Anyway please comment on these patches.

- DML

David M. Lloyd | 1 May 2008 17:08
Picon
Favicon

[PATCH 1/3] RFC: Adding Closeable to various JDK classes

Add Closeable to core I/O classes and interfaces.  This one is a no-brainer 
- I hope. ;-)

Included is java.util.zip.ZipFile, since that class has a close method 
which exactly matches the Closeable interface specification.

- DML

--

diff -r 92ea0ac77d2f src/share/classes/java/io/ObjectInput.java
--- a/src/share/classes/java/io/ObjectInput.java	Tue Apr 22 18:58:40 2008 +0200
+++ b/src/share/classes/java/io/ObjectInput.java	Thu May 01 09:58:43 2008 -0500
 <at>  <at>  -36,7 +36,7  <at>  <at>  package java.io;
   *  <at> see java.io.ObjectInputStream
   *  <at> since   JDK1.1
   */
-public interface ObjectInput extends DataInput {
+public interface ObjectInput extends DataInput, Closeable {
      /**
       * Read and return an object. The class that implements this interface
       * defines where the object is "read" from.
diff -r 92ea0ac77d2f src/share/classes/java/io/ObjectOutput.java
--- a/src/share/classes/java/io/ObjectOutput.java	Tue Apr 22 18:58:40 2008 
+0200
+++ b/src/share/classes/java/io/ObjectOutput.java	Thu May 01 09:58:43 2008 
-0500
 <at>  <at>  -36,7 +36,7  <at>  <at>  package java.io;
   *  <at> see java.io.ObjectInputStream
   *  <at> since   JDK1.1
(Continue reading)

David M. Lloyd | 1 May 2008 17:09
Picon
Favicon

[PATCH 2/3] RFC: Adding Closeable to various JDK classes

Add Closeable to two util classes: Scanner, and the JDK logging Handler class.

--

diff -r 92ea0ac77d2f src/share/classes/java/util/Scanner.java
--- a/src/share/classes/java/util/Scanner.java	Tue Apr 22 18:58:40 2008 +0200
+++ b/src/share/classes/java/util/Scanner.java	Thu May 01 09:58:43 2008 -0500
 <at>  <at>  -342,7 +342,7  <at>  <at>  import sun.misc.LRUCache;
   *
   *  <at> since   1.5
   */
-public final class Scanner implements Iterator<String> {
+public final class Scanner implements Iterator<String>, Closeable {

      // Internal buffer used to hold input
      private CharBuffer buf;
diff -r 92ea0ac77d2f src/share/classes/java/util/logging/Handler.java
--- a/src/share/classes/java/util/logging/Handler.java	Tue Apr 22 18:58:40 
2008 +0200
+++ b/src/share/classes/java/util/logging/Handler.java	Thu May 01 09:58:43 
2008 -0500
 <at>  <at>  -27,6 +27,8  <at>  <at>  package java.util.logging;
  package java.util.logging;

  import java.io.UnsupportedEncodingException;
+import java.io.Closeable;
+
  /**
   * A <tt>Handler</tt> object takes log messages from a <tt>Logger</tt> and
   * exports them.  It might for example, write them to a console
(Continue reading)

David M. Lloyd | 1 May 2008 17:09
Picon
Favicon

[PATCH 3/3] RFC: Adding Closeable to various JDK classes

Add Closeable to MIDI and sound channel classes.  Though the close() method 
on these classes don't throw an exception, they still could implement this 
interface.

- DML

--

diff -r 92ea0ac77d2f src/share/classes/javax/sound/midi/MidiDevice.java
--- a/src/share/classes/javax/sound/midi/MidiDevice.java	Tue Apr 22 
18:58:40 2008 +0200
+++ b/src/share/classes/javax/sound/midi/MidiDevice.java	Thu May 01 
09:58:43 2008 -0500
 <at>  <at>  -26,6 +26,7  <at>  <at>  package javax.sound.midi;
  package javax.sound.midi;

  import java.util.List;
+import java.io.Closeable;

   /**
   * <code>MidiDevice</code> is the base interface for all MIDI devices.
 <at>  <at>  -107,7 +108,7  <at>  <at>  import java.util.List;
   *  <at> author Florian Bomers
   */

-public interface MidiDevice {
+public interface MidiDevice extends Closeable {

      /**
diff -r 92ea0ac77d2f src/share/classes/javax/sound/midi/Receiver.java
(Continue reading)

Neal Gafter | 1 May 2008 17:29

Re: [PATCH 0/3] RFC: Adding Closeable to various JDK classes

Seems like a desirable specification change.  All we need now is a
process for changing the Java SE specification.

On Thu, May 1, 2008 at 8:07 AM, David M. Lloyd <david.lloyd@...> wrote:
> This series of patches adds the java.io.Closeable interface to a few
> different core JDK classes.  Some of them are more obvious/better fits than
> others; I've split the patch up into groups based on how "out there" I think
> the idea is. :-)
>
>  Anyway please comment on these patches.
>
>  - DML
>

bradford.wetmore | 2 May 2008 23:40
Picon

hg: jdk7/tl/jdk: 19 new changesets

Changeset: ad75c4b21d63
Author:    weijun
Date:      2008-04-10 19:58 +0800
URL:       http://hg.openjdk.java.net/jdk7/tl/jdk/rev/ad75c4b21d63

6675606: javax.security.auth.login.Configuration does not recognize path with spaces
Reviewed-by: chegar, xuelei

! src/share/classes/com/sun/security/auth/login/ConfigFile.java
+ test/javax/security/auth/login/Configuration/ConfigFileWithBlank.java

Changeset: c0eb84957bea
Author:    xuelei
Date:      2008-04-11 03:33 -0400
URL:       http://hg.openjdk.java.net/jdk7/tl/jdk/rev/c0eb84957bea

6546639: (spec)javax.net.ssl.SSLContext.getInstance(null) throws undocumented NPE
Summary: add NullPointerException description to those methods.
Reviewed-by: weijun

! src/share/classes/javax/net/ssl/SSLContext.java

Changeset: da9fa1fa9b95
Author:    xuelei
Date:      2008-04-11 03:43 -0400
URL:       http://hg.openjdk.java.net/jdk7/tl/jdk/rev/da9fa1fa9b95

6546671: (spec)javax.net.ssl.TrustManagerFactory.getInstance() throws undocumented NP
5053895: (spec) Unspecified IllegalStateException in TrustManagerFactory
Summary: add NullPointerException/IllegalStateException description
(Continue reading)

Paulo Levi | 3 May 2008 15:40
Picon

Re: core-libs-dev Digest, Vol 13, Issue 1

Is it possible to make the java.sql interface Connection, Statement and ResultSet descend from closeable?

Paulo Levi | 3 May 2008 16:46
Picon

A new system property?

I always thought that System.getProperty("user.dir") was sufficient to
locate the directory of the "program", meaning that if i wanted to
write something to the directory where the jar file is i would just
need to get it.

Not so, that property gets the location where the java command was
invoked, and thus is completly useless for that that.
I'd like to propose two new properties: program.home and program.directory.

I can mangle it right now parsing the classpath like so:
String s = System.getProperty(java.class.path).split(File.pathSeparator)[0];
int i = s.getLastIndexOf(File.separator);
s = s.subString(0, i);

Still - annoying.

Thorbjørn Ravn Andersen | 3 May 2008 18:30
Picon

Re: A new system property?

Paulo Levi skrev  den 03-05-2008 16:46:
> I always thought that System.getProperty("user.dir") was sufficient to
> locate the directory of the "program", meaning that if i wanted to
> write something to the directory where the jar file is i would just
> need to get it.
>
> Not so, that property gets the location where the java command was
> invoked, and thus is completly useless for that that.
> I'd like to propose two new properties: program.home and program.directory.
>
> I can mangle it right now parsing the classpath like so
>   
It gives you the current directory of the user.

You should not depend on external variables, as it is not used if you 
use executable jars etc.

Try looking at 
MyClass.class.getProtectionDomain().getCodeSource().getLocation() (not 
compiled, just derived from javadoc) to get an URL you can work with.

David M. Lloyd | 5 May 2008 14:54
Picon
Favicon

Re: core-libs-dev Digest, Vol 13, Issue 1

On 05/03/2008 08:40 AM, Paulo Levi wrote:
> Is it possible to make the java.sql interface Connection, Statement and
> ResultSet descend from closeable?

Not that I'm aware of, since SQLException doesn't extend IOException.  That 
said, it might be nice to have a java.sql.Closeable for some future JDBC...

I guess once you have that, you could do a java.lang.Closeable with a close 
method that throws Exception, and derive both java.io.Closeable and 
java.sql.Closeable from that. :-)

Though I'm not 100% certain what impact inserting an interface above 
java.io.Closeable in the heirarchy would have on backwards compatibility.

- DML


Gmane