--- old/src/share/classes/java/nio/file/Files.java Sat Oct 22 15:11:31 2011 +++ new/src/share/classes/java/nio/file/Files.java Sat Oct 22 15:11:29 2011 @@ -25,6 +25,7 @@ package java.nio.file; +import java.nio.file.DirectoryStream.Filter; import java.nio.file.attribute.*; import java.nio.file.spi.FileSystemProvider; import java.nio.file.spi.FileTypeDetector; @@ -397,12 +398,7 @@ public static DirectoryStream newDirectoryStream(Path dir) throws IOException { - return provider(dir).newDirectoryStream(dir, new DirectoryStream.Filter() { - @Override - public boolean accept(Path entry) { - return true; - } - }); + return provider(dir).newDirectoryStream(dir, ACCEPT_ALL); } /** @@ -2067,7 +2063,7 @@ * * @return {@code true} if the file is a symbolic link; {@code false} if * the file does not exist, is not a symbolic link, or it cannot - * be determined if the file is a symbolic link or not. + * be determined if the file is symbolic link or not. * * @throws SecurityException * In the case of the default provider, and a security manager is @@ -2106,7 +2102,7 @@ * * @return {@code true} if the file is a directory; {@code false} if * the file does not exist, is not a directory, or it cannot - * be determined if the file is a directory or not. + * be determined if the file is directory or not. * * @throws SecurityException * In the case of the default provider, and a security manager is @@ -3117,4 +3113,13 @@ } return path; } + + private final static Filter ACCEPT_ALL = new AcceptAllFilter(); + private static class AcceptAllFilter implements Filter { + + @Override + public boolean accept(Object entry) { + return true; + } + } } --- old/src/windows/classes/sun/nio/fs/WindowsDirectoryStream.java Sat Oct 22 15:11:35 2011 +++ new/src/windows/classes/sun/nio/fs/WindowsDirectoryStream.java Sat Oct 22 15:11:34 2011 @@ -124,6 +124,9 @@ private boolean atEof; private String first; private Path nextEntry; + private StringBuilder prefix; + private WindowsFileSystem fileSystem; + private int prefixLength; WindowsDirectoryIterator(String first) { atEof = false; @@ -130,20 +133,35 @@ this.first = first; } - // applies filter and also ignores "." and ".." + // ignores "." and ".." + private boolean ignore(String fileName) { + return (fileName.equals(".") || fileName.equals("..")); + } + // applies filter 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; + 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.getFileSystem(), s, attrs); + .createFromNormalizedPath(dir, fullName, s, attrs); try { if (filter.accept(entry)) return entry; @@ -157,7 +175,11 @@ private Path readNextEntry() { // handle first element returned by search if (first != null) { - nextEntry = acceptEntry(first, null); + if (ignore(first)) { + nextEntry = null; + } else { + nextEntry = acceptEntry(first, null); + } first = null; if (nextEntry != null) return nextEntry; @@ -184,6 +206,9 @@ 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) --- old/src/windows/classes/sun/nio/fs/WindowsPath.java Sat Oct 22 15:11:38 2011 +++ new/src/windows/classes/sun/nio/fs/WindowsPath.java Sat Oct 22 15:11:37 2011 @@ -98,6 +98,26 @@ /** * Creates a Path from a given path that is known to be normalized. */ + static WindowsPath createFromNormalizedPath( + WindowsPath parent, String fullPathName, String lastPathName, + BasicFileAttributes attrs) + { + if (attrs == null) { + return new WindowsPath(parent.getFileSystem(), + parent.type, + parent.root, + fullPathName); + } else { + return new WindowsPathWithAttributes(parent.getFileSystem(), + parent.type, + parent.root, + fullPathName,lastPathName,parent, + attrs); + } + } + /** + * Creates a Path from a given path that is known to be normalized. + */ static WindowsPath createFromNormalizedPath(WindowsFileSystem fs, String path, BasicFileAttributes attrs) @@ -115,6 +135,7 @@ result.type(), result.root(), result.path(), + null,null, attrs); } } catch (InvalidPathException x) { @@ -131,6 +152,7 @@ return createFromNormalizedPath(fs, path, null); } + /** * Special implementation with attached/cached attributes (used to quicken * file tree traveral) @@ -138,29 +160,53 @@ private static class WindowsPathWithAttributes extends WindowsPath implements BasicFileAttributesHolder { - final WeakReference ref; + final BasicFileAttributes ref; + private final String fileName; + private final WindowsPath parent; WindowsPathWithAttributes(WindowsFileSystem fs, WindowsPathType type, String root, String path, + String fileName, + WindowsPath parent, BasicFileAttributes attrs) { super(fs, type, root, path); - ref = new WeakReference(attrs); + ref =attrs; + this.fileName = fileName; + this.parent = parent; } @Override public BasicFileAttributes get() { - return ref.get(); + return ref; } @Override public void invalidate() { - ref.clear(); +// ref.clear(); } + // no need to override equals/hashCode. + + @Override + public Path getFileName() { + if (fileName != null) { + return new WindowsPath(getFileSystem(), WindowsPathType.RELATIVE, "", fileName); + } + return super.getFileName(); + } + + @Override + public WindowsPath getParent() { + if (parent != null) { + return parent; + } + return super.getParent(); + } + } // use this message when throwing exceptions @@ -317,12 +363,12 @@ // represents root component only if (root.length() == len) return null; - int off = path.lastIndexOf('\\'); + int off = path.lastIndexOf('\\', len); if (off < root.length()) off = root.length(); else off++; - return new WindowsPath(getFileSystem(), WindowsPathType.RELATIVE, "", path.substring(off)); + return new WindowsPath(getFileSystem(), WindowsPathType.RELATIVE, "", path.substring(off, len)); } @Override @@ -837,6 +883,7 @@ return createFromNormalizedPath(getFileSystem(), rp); } + @Override public WatchKey register(WatchService watcher, WatchEvent.Kind[] events, --- old/src/windows/classes/sun/nio/fs/WindowsPathParser.java Sat Oct 22 15:11:40 2011 +++ new/src/windows/classes/sun/nio/fs/WindowsPathParser.java Sat Oct 22 15:11:40 2011 @@ -120,12 +120,17 @@ off = next; } else { if (isLetter(c0) && c1 == ':') { - root = input.substring(0, 2); - if (len > 2 && isSlash(input.charAt(2))) { + char c2 = input.charAt(2); + if (len > 2 && isSlash(c2)) { + if (c2 == '\\') { + root = input.substring(0, 3); + } else { + root = input.substring(0, 2)+'\\'; + } off = 3; - root += "\\"; type = WindowsPathType.ABSOLUTE; } else { + root = input.substring(0, 2); off = 2; type = WindowsPathType.DRIVE_RELATIVE; }