changeset 15503:803adcd526d7 jdk-9+134

8066577: Cleanup and make better use of the stream API in the jrtfs code Reviewed-by: alanb, psandoz, redestad
author sherman
date Mon, 29 Aug 2016 11:39:12 -0700
parents c5a832e62e0f
children ffd7ba8f2bf8 5e0ff917eab1
files src/java.base/share/classes/jdk/internal/jrtfs/JrtDirectoryStream.java src/java.base/share/classes/jdk/internal/jrtfs/JrtFileSystem.java
diffstat 2 files changed, 16 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/jdk/internal/jrtfs/JrtDirectoryStream.java	Mon Aug 29 20:55:06 2016 +0300
+++ b/src/java.base/share/classes/jdk/internal/jrtfs/JrtDirectoryStream.java	Mon Aug 29 11:39:12 2016 -0700
@@ -47,8 +47,8 @@
 
     private final JrtPath dir;
     private final DirectoryStream.Filter<? super Path> filter;
-    private volatile boolean isClosed;
-    private volatile Iterator<Path> itr;
+    private boolean isClosed;
+    private Iterator<Path> itr;
 
     JrtDirectoryStream(JrtPath dir,
             DirectoryStream.Filter<? super java.nio.file.Path> filter)
@@ -73,24 +73,22 @@
             throw new IllegalStateException(e);
         }
         return new Iterator<Path>() {
-            private Path next;
             @Override
-            public synchronized boolean hasNext() {
-                if (isClosed)
-                    return false;
-                return itr.hasNext();
+            public boolean hasNext() {
+                synchronized (JrtDirectoryStream.this) {
+                    if (isClosed)
+                        return false;
+                    return itr.hasNext();
+                }
             }
 
             @Override
-            public synchronized Path next() {
-                if (isClosed)
-                    throw new NoSuchElementException();
-                return itr.next();
-            }
-
-            @Override
-            public void remove() {
-                throw new UnsupportedOperationException();
+            public Path next() {
+                synchronized (JrtDirectoryStream.this) {
+                    if (isClosed)
+                        throw new NoSuchElementException();
+                    return itr.next();
+                }
             }
         };
     }
--- a/src/java.base/share/classes/jdk/internal/jrtfs/JrtFileSystem.java	Mon Aug 29 20:55:06 2016 +0300
+++ b/src/java.base/share/classes/jdk/internal/jrtfs/JrtFileSystem.java	Mon Aug 29 11:39:12 2016 -0700
@@ -119,9 +119,7 @@
 
     @Override
     public Iterable<Path> getRootDirectories() {
-        ArrayList<Path> dirs = new ArrayList<>();
-        dirs.add(getRootPath());
-        return dirs;
+        return Collections.singleton(getRootPath());
     }
 
     @Override
@@ -159,9 +157,7 @@
 
     @Override
     public final Iterable<FileStore> getFileStores() {
-        ArrayList<FileStore> list = new ArrayList<>(1);
-        list.add(getFileStore(getRootPath()));
-        return list;
+        return Collections.singleton(getFileStore(getRootPath()));
     }
 
     private static final Set<String> supportedFileAttributeViews