34 import java.util.NoSuchElementException;
35 import java.io.IOException;
36
37 final class JrtDirectoryStream implements DirectoryStream<Path> {
38 private final JrtFileSystem jrtfs;
39 private final byte[] path;
40 // prefix to be used for children of this directory
41 // so that child path are reported relatively (if needed)
42 private final String childPrefix;
43 private final DirectoryStream.Filter<? super Path> filter;
44 private volatile boolean isClosed;
45 private volatile Iterator<Path> itr;
46
47 JrtDirectoryStream(JrtPath jrtPath,
48 DirectoryStream.Filter<? super java.nio.file.Path> filter)
49 throws IOException
50 {
51 this.jrtfs = jrtPath.getFileSystem();
52 this.path = jrtPath.getResolvedPath();
53 // sanity check
54 if (!jrtfs.isDirectory(path))
55 throw new NotDirectoryException(jrtPath.toString());
56
57 // absolute path and does not have funky chars in front like /./java.base
58 if (jrtPath.isAbsolute() && (path.length == jrtPath.getPathLength())) {
59 childPrefix = null;
60 } else {
61 // cases where directory content needs to modified with prefix
62 // like ./java.base, /./java.base, java.base and so on.
63 String dirName = jrtPath.toString();
64 int idx = dirName.indexOf(JrtFileSystem.getString(path).substring(1));
65 childPrefix = dirName.substring(0, idx);
66 }
67 this.filter = filter;
68 }
69
70 @Override
71 public synchronized Iterator<Path> iterator() {
72 if (isClosed)
73 throw new ClosedDirectoryStreamException();
74 if (itr != null)
|
34 import java.util.NoSuchElementException;
35 import java.io.IOException;
36
37 final class JrtDirectoryStream implements DirectoryStream<Path> {
38 private final JrtFileSystem jrtfs;
39 private final byte[] path;
40 // prefix to be used for children of this directory
41 // so that child path are reported relatively (if needed)
42 private final String childPrefix;
43 private final DirectoryStream.Filter<? super Path> filter;
44 private volatile boolean isClosed;
45 private volatile Iterator<Path> itr;
46
47 JrtDirectoryStream(JrtPath jrtPath,
48 DirectoryStream.Filter<? super java.nio.file.Path> filter)
49 throws IOException
50 {
51 this.jrtfs = jrtPath.getFileSystem();
52 this.path = jrtPath.getResolvedPath();
53 // sanity check
54 if (!jrtfs.isDirectory(path, true))
55 throw new NotDirectoryException(jrtPath.toString());
56
57 // absolute path and does not have funky chars in front like /./java.base
58 if (jrtPath.isAbsolute() && (path.length == jrtPath.getPathLength())) {
59 childPrefix = null;
60 } else {
61 // cases where directory content needs to modified with prefix
62 // like ./java.base, /./java.base, java.base and so on.
63 String dirName = jrtPath.toString();
64 int idx = dirName.indexOf(JrtFileSystem.getString(path).substring(1));
65 childPrefix = dirName.substring(0, idx);
66 }
67 this.filter = filter;
68 }
69
70 @Override
71 public synchronized Iterator<Path> iterator() {
72 if (isClosed)
73 throw new ClosedDirectoryStreamException();
74 if (itr != null)
|