diff --git a/openide.filesystems/apichanges.xml b/openide.filesystems/apichanges.xml --- a/openide.filesystems/apichanges.xml +++ b/openide.filesystems/apichanges.xml @@ -49,6 +49,22 @@ Filesystems API + + + FileLock implements AutoCloseable + + + + + +

+ As JDK 1.7 is required, the FileLock + can implement AutoCloseable to work well in try-with-resources constructs. +

+
+ + +
FileSystem.Status API removed diff --git a/openide.filesystems/manifest.mf b/openide.filesystems/manifest.mf --- a/openide.filesystems/manifest.mf +++ b/openide.filesystems/manifest.mf @@ -2,6 +2,6 @@ OpenIDE-Module: org.openide.filesystems OpenIDE-Module-Localizing-Bundle: org/openide/filesystems/Bundle.properties OpenIDE-Module-Layer: org/openide/filesystems/resources/layer.xml -OpenIDE-Module-Specification-Version: 9.1 +OpenIDE-Module-Specification-Version: 9.2 diff --git a/openide.filesystems/src/org/openide/filesystems/FileLock.java b/openide.filesystems/src/org/openide/filesystems/FileLock.java --- a/openide.filesystems/src/org/openide/filesystems/FileLock.java +++ b/openide.filesystems/src/org/openide/filesystems/FileLock.java @@ -55,14 +55,17 @@ * Normally this is sufficient protection. If you really need an atomic read, you may * simply lock the file, perform the read, and unlock it when done. The file will still * be protected against writes, although the read operation did not request a lock. -* +*

+* The {@code FileLock} implements {@link AutoCloseable}, so it can be created within +* try-with-resources resource clause and the lock will be released at the end of the try block. +* * @see FileObject -* +* @since 9.2 implements {@code AutoCloseable} interface. * @author Petr Hamernik, Jaroslav Tulach, Ian Formanek * @version 0.16, Jun 5, 1997 * */ -public class FileLock { // XXX JDK 7: implements AutoCloseable +public class FileLock implements AutoCloseable { // ========================= NONE file lock ===================================== /** Constant that can be used in filesystems that do not support locking. @@ -109,6 +112,14 @@ locked = false; } + /** + * Releases the lock. Equivalent to {@link #releaseLock} call. + */ + @Override + public final void close() { + releaseLock(); + } + // End of the original part // ============================================================================