Signed-off-by: Pekka Enberg <penb...@kernel.org> --- gnu/java/nio/FileLockImpl.java | 5 +++ java/beans/XMLDecoder.java | 1 + java/beans/XMLEncoder.java | 4 ++- java/io/Closeable.java | 1 + java/io/ObjectInput.java | 3 +- java/io/ObjectOutput.java | 3 +- java/lang/AutoCloseable.java | 50 +++++++++++++++++++++++++++++++++++++ java/nio/channels/FileLock.java | 1 + java/sql/Connection.java | 1 + java/sql/ResultSet.java | 1 + java/sql/Statement.java | 1 + javax/sound/midi/MidiDevice.java | 1 + javax/sound/midi/Receiver.java | 1 + javax/sound/midi/Transmitter.java | 1 + javax/sound/sampled/Line.java | 1 + 15 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 java/lang/AutoCloseable.java
diff --git a/gnu/java/nio/FileLockImpl.java b/gnu/java/nio/FileLockImpl.java index e714ea3..0c6e468 100644 --- a/gnu/java/nio/FileLockImpl.java +++ b/gnu/java/nio/FileLockImpl.java @@ -88,6 +88,11 @@ public final class FileLockImpl extends FileLock return valid; } + public void close() throws Exception + { + release(); + } + /** * Releases the lock if it is still valid. Marks this lock as invalid. */ diff --git a/java/beans/XMLDecoder.java b/java/beans/XMLDecoder.java index 2689639..bafafe4 100644 --- a/java/beans/XMLDecoder.java +++ b/java/beans/XMLDecoder.java @@ -104,6 +104,7 @@ import java.util.NoSuchElementException; * @status updated to 1.5 */ public class XMLDecoder + implements AutoCloseable { private Object owner; diff --git a/java/beans/XMLEncoder.java b/java/beans/XMLEncoder.java index 40cb6db..894e4b8 100644 --- a/java/beans/XMLEncoder.java +++ b/java/beans/XMLEncoder.java @@ -50,7 +50,9 @@ import java.io.OutputStream; * @author Robert Schuster (robertschus...@fsfe.org) * @since 1.4 */ -public class XMLEncoder extends Encoder +public class XMLEncoder + extends Encoder + implements AutoCloseable { Object owner; diff --git a/java/io/Closeable.java b/java/io/Closeable.java index b8523d7..f5f8083 100644 --- a/java/io/Closeable.java +++ b/java/io/Closeable.java @@ -48,6 +48,7 @@ package java.io; * @since 1.5 */ public interface Closeable + extends AutoCloseable { /** diff --git a/java/io/ObjectInput.java b/java/io/ObjectInput.java index f8d51e0..071f67d 100644 --- a/java/io/ObjectInput.java +++ b/java/io/ObjectInput.java @@ -48,7 +48,8 @@ package java.io; * * @see DataInput */ -public interface ObjectInput extends DataInput +public interface ObjectInput + extends DataInput, AutoCloseable { /** * This method returns the number of bytes that can be read without diff --git a/java/io/ObjectOutput.java b/java/io/ObjectOutput.java index 628f8b9..4ec6c6f 100644 --- a/java/io/ObjectOutput.java +++ b/java/io/ObjectOutput.java @@ -48,7 +48,8 @@ package java.io; * * @see DataOutput */ -public interface ObjectOutput extends DataOutput +public interface ObjectOutput + extends DataOutput, AutoCloseable { /** * This method writes the specified byte to the output stream. diff --git a/java/lang/AutoCloseable.java b/java/lang/AutoCloseable.java new file mode 100644 index 0000000..4c1ddaa --- /dev/null +++ b/java/lang/AutoCloseable.java @@ -0,0 +1,50 @@ +/* AutoCloseable.java -- Resource that must be closed after it is no longer + used. + Copyright (C) 2012 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.lang; + +/** + * Resource that must be closed after it is no longer used. + * + * @since 1.7 + */ +public interface AutoCloseable +{ + void close() throws Exception; +} diff --git a/java/nio/channels/FileLock.java b/java/nio/channels/FileLock.java index 78210b3..02b561a 100644 --- a/java/nio/channels/FileLock.java +++ b/java/nio/channels/FileLock.java @@ -45,6 +45,7 @@ import java.io.IOException; * @since 1.4 */ public abstract class FileLock + implements AutoCloseable { private final FileChannel channel; private final long position; diff --git a/java/sql/Connection.java b/java/sql/Connection.java index f375276..b1e7034 100644 --- a/java/sql/Connection.java +++ b/java/sql/Connection.java @@ -46,6 +46,7 @@ import java.util.Map; * @author Aaron M. Renn (ar...@urbanophile.com) */ public interface Connection + extends AutoCloseable { /** * This transaction isolation level indicates that transactions are not diff --git a/java/sql/ResultSet.java b/java/sql/ResultSet.java index 3b49a6a..c487bed 100644 --- a/java/sql/ResultSet.java +++ b/java/sql/ResultSet.java @@ -60,6 +60,7 @@ import java.util.Map; * @author Aaron M. Renn (ar...@urbanophile.com) */ public interface ResultSet + extends AutoCloseable { /** * The rows will be processed in order from first to last. diff --git a/java/sql/Statement.java b/java/sql/Statement.java index 1b57fb3..5f35e7b 100644 --- a/java/sql/Statement.java +++ b/java/sql/Statement.java @@ -44,6 +44,7 @@ package java.sql; * @author Aaron M. Renn (ar...@urbanophile.com) */ public interface Statement + extends AutoCloseable { int CLOSE_CURRENT_RESULT = 1; int KEEP_CURRENT_RESULT = 2; diff --git a/javax/sound/midi/MidiDevice.java b/javax/sound/midi/MidiDevice.java index 7a0ca7f..7ce22ca 100644 --- a/javax/sound/midi/MidiDevice.java +++ b/javax/sound/midi/MidiDevice.java @@ -46,6 +46,7 @@ package javax.sound.midi; * */ public interface MidiDevice + extends AutoCloseable { /** * Get the Info object describing this device. diff --git a/javax/sound/midi/Receiver.java b/javax/sound/midi/Receiver.java index bc660d0..535c9df 100644 --- a/javax/sound/midi/Receiver.java +++ b/javax/sound/midi/Receiver.java @@ -47,6 +47,7 @@ package javax.sound.midi; * */ public interface Receiver + extends AutoCloseable { /** * Send a MIDI message and timestamp. Some receivers don't support diff --git a/javax/sound/midi/Transmitter.java b/javax/sound/midi/Transmitter.java index ab81cc8..2c62795 100644 --- a/javax/sound/midi/Transmitter.java +++ b/javax/sound/midi/Transmitter.java @@ -47,6 +47,7 @@ package javax.sound.midi; * */ public interface Transmitter + extends AutoCloseable { /** * Set the Receiver to which MIDI events will be sent. diff --git a/javax/sound/sampled/Line.java b/javax/sound/sampled/Line.java index 62d284b..75c7a84 100644 --- a/javax/sound/sampled/Line.java +++ b/javax/sound/sampled/Line.java @@ -43,6 +43,7 @@ package javax.sound.sampled; * @since 1.3 */ public interface Line + extends AutoCloseable { /** * An object of this type holds information about a Line. -- 1.7.4.1