8066577: Cleanup and make better use of the stream API in the jrtfs code
Reviewed-by: alanb, psandoz, redestad
This commit is contained in:
parent
af8dc755fd
commit
bc903b0547
jdk/src/java.base/share/classes/jdk/internal/jrtfs
@ -47,8 +47,8 @@ final class JrtDirectoryStream implements DirectoryStream<Path> {
|
||||
|
||||
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 @@ final class JrtDirectoryStream implements DirectoryStream<Path> {
|
||||
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();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -119,9 +119,7 @@ class JrtFileSystem extends FileSystem {
|
||||
|
||||
@Override
|
||||
public Iterable<Path> getRootDirectories() {
|
||||
ArrayList<Path> dirs = new ArrayList<>();
|
||||
dirs.add(getRootPath());
|
||||
return dirs;
|
||||
return Collections.singleton(getRootPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -159,9 +157,7 @@ class JrtFileSystem extends FileSystem {
|
||||
|
||||
@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
|
||||
|
Loading…
x
Reference in New Issue
Block a user