src/windows/classes/sun/nio/fs/WindowsDirectoryStream.java
Print this page
*** 122,151 ****
private class WindowsDirectoryIterator implements Iterator<Path> {
private boolean atEof;
private String first;
private Path nextEntry;
WindowsDirectoryIterator(String first) {
atEof = false;
this.first = first;
}
! // applies filter and also ignores "." and ".."
private Path acceptEntry(String s, BasicFileAttributes attrs) {
! if (s.equals(".") || s.equals(".."))
! return null;
if (dir.needsSlashWhenResolving()) {
! StringBuilder sb = new StringBuilder(dir.toString());
! sb.append('\\');
! sb.append(s);
! s = sb.toString();
! } else {
! s = dir + s;
}
Path entry = WindowsPath
! .createFromNormalizedPath(dir.getFileSystem(), s, attrs);
try {
if (filter.accept(entry))
return entry;
} catch (IOException ioe) {
throw new DirectoryIteratorException(ioe);
--- 122,169 ----
private class WindowsDirectoryIterator implements Iterator<Path> {
private boolean atEof;
private String first;
private Path nextEntry;
+ private StringBuilder prefix;
+ private WindowsFileSystem fileSystem;
+ private int prefixLength;
WindowsDirectoryIterator(String first) {
atEof = false;
this.first = first;
}
! // ignores "." and ".."
! private boolean ignore(String fileName) {
! return (fileName.equals(".") || fileName.equals(".."));
! }
! // applies filter
private Path acceptEntry(String s, BasicFileAttributes attrs) {
! if (prefix == null) {
! prefix = new StringBuilder(dir.toString());
if (dir.needsSlashWhenResolving()) {
! prefix.append('\\');
}
+ fileSystem = dir.getFileSystem();
+ prefixLength = prefix.length();
+ }
+ prefix.append(s);
+ String fullName = prefix.toString();
+ prefix.setLength(prefixLength);
+ // System.out.println("***");
+
+ // if (dir.needsSlashWhenResolving()) {
+ // StringBuilder sb = new StringBuilder(dir.toString());
+ // sb.append('\\');
+ // sb.append(s);
+ // s = sb.toString();
+ // } else {
+ // s = dir + s;
+ // }
Path entry = WindowsPath
! .createFromNormalizedPath(dir, fullName, s, attrs);
try {
if (filter.accept(entry))
return entry;
} catch (IOException ioe) {
throw new DirectoryIteratorException(ioe);
*** 155,165 ****
--- 173,187 ----
// reads next directory entry
private Path readNextEntry() {
// handle first element returned by search
if (first != null) {
+ if (ignore(first)) {
+ nextEntry = null;
+ } else {
nextEntry = acceptEntry(first, null);
+ }
first = null;
if (nextEntry != null)
return nextEntry;
}
*** 182,191 ****
--- 204,216 ----
if (name == null) {
atEof = true;
return null;
}
+ if (ignore(name)) {
+ continue;
+ }
// grab the attributes from the WIN32_FIND_DATA structure
// (needs to be done while holding closeLock because close
// will release the buffer)
attrs = WindowsFileAttributes
.fromFindData(findDataBuffer.address());