changeset 910:babf86a1ac92

7006126: (fs) Updates to file system API (1/2011) Reviewed-by: jjg
author alanb
date Fri, 28 Jan 2011 09:25:20 +0000
parents 92ab09ed59fd
children df3394337b04
files src/share/classes/com/sun/tools/javac/nio/JavacPathFileManager.java src/share/classes/com/sun/tools/javac/nio/PathFileObject.java test/tools/javac/nio/compileTest/CompileTest.java
diffstat 3 files changed, 21 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/sun/tools/javac/nio/JavacPathFileManager.java	Fri Jan 28 00:09:38 2011 -0800
+++ b/src/share/classes/com/sun/tools/javac/nio/JavacPathFileManager.java	Fri Jan 28 09:25:20 2011 +0000
@@ -39,7 +39,6 @@
 import java.nio.file.FileVisitResult;
 import java.nio.file.Path;
 import java.nio.file.SimpleFileVisitor;
-import java.nio.file.attribute.Attributes;
 import java.nio.file.attribute.BasicFileAttributes;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -223,9 +222,7 @@
         Path path = pathIter.next();
         if (pathIter.hasNext())
             throw new IllegalArgumentException("path too long for directory");
-        if (!path.exists())
-            throw new FileNotFoundException(path + ": does not exist");
-        else if (!isDirectory(path))
+        if (!isDirectory(path))
             throw new IOException(path + ": not a directory");
     }
 
@@ -326,7 +323,7 @@
     private void list(Path path, String packageName, final Set<Kind> kinds,
             boolean recurse, final ListBuffer<JavaFileObject> results)
             throws IOException {
-        if (!path.exists())
+        if (!Files.exists(path))
             return;
 
         final Path pathDir;
@@ -341,7 +338,7 @@
         String sep = path.getFileSystem().getSeparator();
         Path packageDir = packageName.isEmpty() ? pathDir
                 : pathDir.resolve(packageName.replace(".", sep));
-        if (!packageDir.exists())
+        if (!Files.exists(packageDir))
             return;
 
 /* Alternate impl of list, superceded by use of Files.walkFileTree */
@@ -353,7 +350,7 @@
 //            DirectoryStream<Path> ds = dir.newDirectoryStream();
 //            try {
 //                for (Path p: ds) {
-//                    String name = p.getName().toString();
+//                    String name = p.getFileName().toString();
 //                    if (isDirectory(p)) {
 //                        if (recurse && SourceVersion.isIdentifier(name)) {
 //                            queue.add(p);
@@ -376,7 +373,7 @@
                 new SimpleFileVisitor<Path>() {
             @Override
             public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
-                Path name = dir.getName();
+                Path name = dir.getFileName();
                 if (name == null || SourceVersion.isIdentifier(name.toString())) // JSR 292?
                     return FileVisitResult.CONTINUE;
                 else
@@ -385,7 +382,7 @@
 
             @Override
             public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
-                if (attrs.isRegularFile() && kinds.contains(getKind(file.getName().toString()))) {
+                if (attrs.isRegularFile() && kinds.contains(getKind(file.getFileName().toString()))) {
                     JavaFileObject fe =
                         PathFileObject.createDirectoryPathFileObject(
                             JavacPathFileManager.this, file, pathDir);
@@ -431,13 +428,13 @@
         for (Path p: getLocation(location)) {
             if (isDirectory(p)) {
                 Path f = resolve(p, relativePath);
-                if (f.exists())
+                if (Files.exists(f))
                     return PathFileObject.createDirectoryPathFileObject(this, f, p);
             } else {
                 FileSystem fs = getFileSystem(p);
                 if (fs != null) {
                     Path file = getPath(fs, relativePath);
-                    if (file.exists())
+                    if (Files.exists(file))
                         return PathFileObject.createJarPathFileObject(this, file);
                 }
             }
@@ -504,7 +501,7 @@
     private FileSystem getFileSystem(Path p) throws IOException {
         FileSystem fs = fileSystems.get(p);
         if (fs == null) {
-            fs = FileSystems.newFileSystem(p, Collections.<String,Void>emptyMap(), null);
+            fs = FileSystems.newFileSystem(p, null);
             fileSystems.put(p, fs);
         }
         return fs;
@@ -530,7 +527,7 @@
     }
 
     private static boolean isDirectory(Path path) throws IOException {
-        BasicFileAttributes attrs = Attributes.readBasicFileAttributes(path);
+        BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class);
         return attrs.isDirectory();
     }
 
--- a/src/share/classes/com/sun/tools/javac/nio/PathFileObject.java	Fri Jan 28 00:09:38 2011 -0800
+++ b/src/share/classes/com/sun/tools/javac/nio/PathFileObject.java	Fri Jan 28 09:25:20 2011 +0000
@@ -38,7 +38,6 @@
 import java.nio.charset.CharsetDecoder;
 import java.nio.file.Files;
 import java.nio.file.Path;
-import java.nio.file.attribute.Attributes;
 import java.nio.file.attribute.BasicFileAttributes;
 import javax.lang.model.element.Modifier;
 import javax.lang.model.element.NestingKind;
@@ -153,7 +152,7 @@
 
     @Override
     public Kind getKind() {
-        return BaseFileManager.getKind(path.getName().toString());
+        return BaseFileManager.getKind(path.getFileName().toString());
     }
 
     @Override
@@ -164,14 +163,14 @@
             return false;
         }
         String sn = simpleName + kind.extension;
-        String pn = path.getName().toString();
+        String pn = path.getFileName().toString();
         if (pn.equals(sn)) {
             return true;
         }
         if (pn.equalsIgnoreCase(sn)) {
             try {
                 // allow for Windows
-                return path.toRealPath(false).getName().toString().equals(sn);
+                return path.toRealPath(false).getFileName().toString().equals(sn);
             } catch (IOException e) {
             }
         }
@@ -200,13 +199,13 @@
 
     @Override
     public InputStream openInputStream() throws IOException {
-        return path.newInputStream();
+        return Files.newInputStream(path);
     }
 
     @Override
     public OutputStream openOutputStream() throws IOException {
         ensureParentDirectoriesExist();
-        return path.newOutputStream();
+        return Files.newOutputStream(path);
     }
 
     @Override
@@ -242,14 +241,13 @@
     @Override
     public Writer openWriter() throws IOException {
         ensureParentDirectoriesExist();
-        return new OutputStreamWriter(path.newOutputStream(), fileManager.getEncodingName());
+        return new OutputStreamWriter(Files.newOutputStream(path), fileManager.getEncodingName());
     }
 
     @Override
     public long getLastModified() {
         try {
-            BasicFileAttributes attrs = Attributes.readBasicFileAttributes(path);
-            return attrs.lastModifiedTime().toMillis();
+            return Files.getLastModifiedTime(path).toMillis();
         } catch (IOException e) {
             return -1;
         }
@@ -258,7 +256,7 @@
     @Override
     public boolean delete() {
         try {
-            path.delete();
+            Files.delete(path);
             return true;
         } catch (IOException e) {
             return false;
@@ -267,7 +265,7 @@
 
     public boolean isSameFile(PathFileObject other) {
         try {
-            return path.isSameFile(other.path);
+            return Files.isSameFile(path, other.path);
         } catch (IOException e) {
             return false;
         }
@@ -296,8 +294,7 @@
 
     private long size() {
         try {
-            BasicFileAttributes attrs = Attributes.readBasicFileAttributes(path);
-            return attrs.size();
+            return Files.size(path);
         } catch (IOException e) {
             return -1;
         }
--- a/test/tools/javac/nio/compileTest/CompileTest.java	Fri Jan 28 00:09:38 2011 -0800
+++ b/test/tools/javac/nio/compileTest/CompileTest.java	Fri Jan 28 09:25:20 2011 +0000
@@ -84,8 +84,7 @@
         System.err.println("Test " + count + " " + Arrays.asList(opts) + " " + className);
         Path testSrcDir = Paths.get(System.getProperty("test.src"));
         Path testClassesDir = Paths.get(System.getProperty("test.classes"));
-        Path classes = Paths.get("classes." + count);
-        classes.createDirectory();
+        Path classes = Files.createDirectory(Paths.get("classes." + count));
 
         Context ctx = new Context();
         PathFileManager fm = new JavacPathFileManager(ctx, true, null);