summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2013-05-10 14:20:20 -0700
committerElliott Hughes <enh@google.com>2013-05-10 14:20:20 -0700
commit9902f3494c6d983879d8b9cfe6b1f771cfefe703 (patch)
tree416c5d0fd52a7cfbdffe7ca5f5811513478fadbf
parent6a4ab0ab16fe5462389ba61b7331da860a2d32f2 (diff)
downloadlibcore-9902f3494c6d983879d8b9cfe6b1f771cfefe703.zip
libcore-9902f3494c6d983879d8b9cfe6b1f771cfefe703.tar.gz
libcore-9902f3494c6d983879d8b9cfe6b1f771cfefe703.tar.bz2
Finish off AutoCloseable.
Bug: 3484927 Change-Id: Ia0f5ad3db9807459ce6cda05bc2f53564b63b375
-rw-r--r--luni/src/main/java/java/lang/AutoCloseable.java5
-rw-r--r--luni/src/main/java/java/net/DatagramSocket.java3
-rw-r--r--luni/src/main/java/java/net/ServerSocket.java3
-rw-r--r--luni/src/main/java/java/net/Socket.java3
-rw-r--r--luni/src/main/java/java/nio/channels/FileLock.java14
-rw-r--r--luni/src/main/java/java/nio/channels/Selector.java3
-rw-r--r--luni/src/main/java/java/util/Scanner.java2
-rw-r--r--luni/src/main/java/java/util/zip/ZipFile.java3
8 files changed, 21 insertions, 15 deletions
diff --git a/luni/src/main/java/java/lang/AutoCloseable.java b/luni/src/main/java/java/lang/AutoCloseable.java
index b3133a9..df789e0 100644
--- a/luni/src/main/java/java/lang/AutoCloseable.java
+++ b/luni/src/main/java/java/lang/AutoCloseable.java
@@ -31,15 +31,10 @@ package java.lang;
* }</pre>
*
* @since 1.7
- * @hide 1.7
*/
public interface AutoCloseable {
-
/**
* Closes the object and release any system resources it holds.
- *
- * <p>Unless the implementing class specifies otherwise, it is an error to
- * call {@link #close} more than once.
*/
void close() throws Exception;
}
diff --git a/luni/src/main/java/java/net/DatagramSocket.java b/luni/src/main/java/java/net/DatagramSocket.java
index a5e9e01..49f141a 100644
--- a/luni/src/main/java/java/net/DatagramSocket.java
+++ b/luni/src/main/java/java/net/DatagramSocket.java
@@ -17,6 +17,7 @@
package java.net;
+import java.io.Closeable;
import java.io.FileDescriptor;
import java.io.IOException;
import java.nio.channels.DatagramChannel;
@@ -33,7 +34,7 @@ import static libcore.io.OsConstants.*;
* @see DatagramPacket
* @see DatagramSocketImplFactory
*/
-public class DatagramSocket {
+public class DatagramSocket implements Closeable {
DatagramSocketImpl impl;
diff --git a/luni/src/main/java/java/net/ServerSocket.java b/luni/src/main/java/java/net/ServerSocket.java
index ba8d626..399511f 100644
--- a/luni/src/main/java/java/net/ServerSocket.java
+++ b/luni/src/main/java/java/net/ServerSocket.java
@@ -17,6 +17,7 @@
package java.net;
+import java.io.Closeable;
import java.io.IOException;
import java.nio.channels.ServerSocketChannel;
@@ -26,7 +27,7 @@ import java.nio.channels.ServerSocketChannel;
* appropriate reply. The actual tasks that a server socket must accomplish are
* implemented by an internal {@code SocketImpl} instance.
*/
-public class ServerSocket {
+public class ServerSocket implements Closeable {
/**
* The RI specifies that where the caller doesn't give an explicit backlog,
* the default is 50. The OS disagrees, so we need to explicitly call listen(2).
diff --git a/luni/src/main/java/java/net/Socket.java b/luni/src/main/java/java/net/Socket.java
index 0c7e9d4..36fdf28 100644
--- a/luni/src/main/java/java/net/Socket.java
+++ b/luni/src/main/java/java/net/Socket.java
@@ -17,6 +17,7 @@
package java.net;
+import java.io.Closeable;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.InputStream;
@@ -27,7 +28,7 @@ import libcore.io.IoBridge;
/**
* Provides a client-side TCP socket.
*/
-public class Socket {
+public class Socket implements Closeable {
private static SocketImplFactory factory;
final SocketImpl impl;
diff --git a/luni/src/main/java/java/nio/channels/FileLock.java b/luni/src/main/java/java/nio/channels/FileLock.java
index 4cdcc27..360f826 100644
--- a/luni/src/main/java/java/nio/channels/FileLock.java
+++ b/luni/src/main/java/java/nio/channels/FileLock.java
@@ -68,7 +68,7 @@ import java.io.IOException;
* Further care should be exercised when locking files maintained on network
* file systems, since they often have further limitations.
*/
-public abstract class FileLock {
+public abstract class FileLock implements AutoCloseable {
// The underlying file channel.
private final FileChannel channel;
@@ -185,10 +185,16 @@ public abstract class FileLock {
public abstract void release() throws IOException;
/**
- * Returns a string that shows the details of the lock suitable for display
- * to an end user.
+ * Calls {@link #release} for {@code AutoCloseable}.
*
- * @return the display string.
+ * @since 1.7
+ */
+ public final void close() throws IOException {
+ release();
+ }
+
+ /**
+ * Returns a string that shows the details of the lock suitable for debugging.
*/
@Override
public final String toString() {
diff --git a/luni/src/main/java/java/nio/channels/Selector.java b/luni/src/main/java/java/nio/channels/Selector.java
index 1aac14b..6d9b063 100644
--- a/luni/src/main/java/java/nio/channels/Selector.java
+++ b/luni/src/main/java/java/nio/channels/Selector.java
@@ -16,6 +16,7 @@
package java.nio.channels;
+import java.io.Closeable;
import java.io.IOException;
import java.nio.channels.spi.SelectorProvider;
import java.util.Set;
@@ -33,7 +34,7 @@ import java.util.Set;
* selector are checked to see whether they are ready for operation according to
* their {@link SelectionKey interest set}.
*/
-public abstract class Selector {
+public abstract class Selector implements Closeable {
/**
* Returns a selector returned by {@link SelectorProvider#provider}'s
diff --git a/luni/src/main/java/java/util/Scanner.java b/luni/src/main/java/java/util/Scanner.java
index 5f7d0e3..ede99a75b 100644
--- a/luni/src/main/java/java/util/Scanner.java
+++ b/luni/src/main/java/java/util/Scanner.java
@@ -59,7 +59,7 @@ import libcore.io.IoUtils;
* <p>
* The {@code Scanner} class is not thread-safe.
*/
-public final class Scanner implements Iterator<String> {
+public final class Scanner implements Closeable, Iterator<String> {
// Default delimiting pattern.
private static final Pattern DEFAULT_DELIMITER = Pattern
diff --git a/luni/src/main/java/java/util/zip/ZipFile.java b/luni/src/main/java/java/util/zip/ZipFile.java
index 8256db9..97879d5 100644
--- a/luni/src/main/java/java/util/zip/ZipFile.java
+++ b/luni/src/main/java/java/util/zip/ZipFile.java
@@ -19,6 +19,7 @@ package java.util.zip;
import dalvik.system.CloseGuard;
import java.io.BufferedInputStream;
+import java.io.Closeable;
import java.io.EOFException;
import java.io.DataInputStream;
import java.io.File;
@@ -45,7 +46,7 @@ import libcore.io.Streams;
* <p>If you want to create a zip file, use {@link ZipOutputStream}. There is no API for updating
* an existing zip file.
*/
-public class ZipFile implements ZipConstants {
+public class ZipFile implements Closeable, ZipConstants {
/**
* General Purpose Bit Flags, Bit 0.
* If set, indicates that the file is encrypted.