src/windows/classes/sun/nio/fs/WindowsPath.java
Print this page
*** 96,105 ****
--- 96,125 ----
}
/**
* 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)
{
try {
*** 113,122 ****
--- 133,143 ----
} else {
return new WindowsPathWithAttributes(fs,
result.type(),
result.root(),
result.path(),
+ null,null,
attrs);
}
} catch (InvalidPathException x) {
throw new AssertionError(x.getMessage());
}
*** 129,170 ****
String path)
{
return createFromNormalizedPath(fs, path, null);
}
/**
* Special implementation with attached/cached attributes (used to quicken
* file tree traveral)
*/
private static class WindowsPathWithAttributes
extends WindowsPath implements BasicFileAttributesHolder
{
! final WeakReference<BasicFileAttributes> ref;
WindowsPathWithAttributes(WindowsFileSystem fs,
WindowsPathType type,
String root,
String path,
BasicFileAttributes attrs)
{
super(fs, type, root, path);
! ref = new WeakReference<BasicFileAttributes>(attrs);
}
@Override
public BasicFileAttributes get() {
! return ref.get();
}
@Override
public void invalidate() {
! ref.clear();
}
// no need to override equals/hashCode.
}
// use this message when throwing exceptions
String getPathForExceptionMessage() {
return path;
}
--- 150,216 ----
String path)
{
return createFromNormalizedPath(fs, path, null);
}
+
/**
* Special implementation with attached/cached attributes (used to quicken
* file tree traveral)
*/
private static class WindowsPathWithAttributes
extends WindowsPath implements BasicFileAttributesHolder
{
! 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 =attrs;
! this.fileName = fileName;
! this.parent = parent;
}
@Override
public BasicFileAttributes get() {
! return ref;
}
@Override
public void invalidate() {
! // 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
String getPathForExceptionMessage() {
return path;
}
*** 315,330 ****
if (len == 0)
return this;
// represents root component only
if (root.length() == len)
return null;
! int off = path.lastIndexOf('\\');
if (off < root.length())
off = root.length();
else
off++;
! return new WindowsPath(getFileSystem(), WindowsPathType.RELATIVE, "", path.substring(off));
}
@Override
public WindowsPath getParent() {
// represents root component only
--- 361,376 ----
if (len == 0)
return this;
// represents root component only
if (root.length() == len)
return null;
! int off = path.lastIndexOf('\\', len);
if (off < root.length())
off = root.length();
else
off++;
! return new WindowsPath(getFileSystem(), WindowsPathType.RELATIVE, "", path.substring(off, len));
}
@Override
public WindowsPath getParent() {
// represents root component only
*** 835,844 ****
--- 881,891 ----
checkRead();
String rp = WindowsLinkSupport.getRealPath(this, Util.followLinks(options));
return createFromNormalizedPath(getFileSystem(), rp);
}
+
@Override
public WatchKey register(WatchService watcher,
WatchEvent.Kind<?>[] events,
WatchEvent.Modifier... modifiers)
throws IOException