8066577: Cleanup and make better use of the stream API in the jrtfs code
Reviewed-by: alanb, psandoz, redestad
--- a/jdk/src/java.base/share/classes/jdk/internal/jrtfs/JrtDirectoryStream.java Mon Aug 29 20:55:06 2016 +0300
+++ b/jdk/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/jdk/src/java.base/share/classes/jdk/internal/jrtfs/JrtFileSystem.java Mon Aug 29 20:55:06 2016 +0300
+++ b/jdk/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