Fri, 28 Jan 2011 09:25:20 +0000
7006126: (fs) Updates to file system API (1/2011)
Reviewed-by: jjg
1.1 --- a/src/share/classes/com/sun/tools/javac/nio/JavacPathFileManager.java Fri Jan 28 00:09:38 2011 -0800 1.2 +++ b/src/share/classes/com/sun/tools/javac/nio/JavacPathFileManager.java Fri Jan 28 09:25:20 2011 +0000 1.3 @@ -39,7 +39,6 @@ 1.4 import java.nio.file.FileVisitResult; 1.5 import java.nio.file.Path; 1.6 import java.nio.file.SimpleFileVisitor; 1.7 -import java.nio.file.attribute.Attributes; 1.8 import java.nio.file.attribute.BasicFileAttributes; 1.9 import java.util.ArrayList; 1.10 import java.util.Arrays; 1.11 @@ -223,9 +222,7 @@ 1.12 Path path = pathIter.next(); 1.13 if (pathIter.hasNext()) 1.14 throw new IllegalArgumentException("path too long for directory"); 1.15 - if (!path.exists()) 1.16 - throw new FileNotFoundException(path + ": does not exist"); 1.17 - else if (!isDirectory(path)) 1.18 + if (!isDirectory(path)) 1.19 throw new IOException(path + ": not a directory"); 1.20 } 1.21 1.22 @@ -326,7 +323,7 @@ 1.23 private void list(Path path, String packageName, final Set<Kind> kinds, 1.24 boolean recurse, final ListBuffer<JavaFileObject> results) 1.25 throws IOException { 1.26 - if (!path.exists()) 1.27 + if (!Files.exists(path)) 1.28 return; 1.29 1.30 final Path pathDir; 1.31 @@ -341,7 +338,7 @@ 1.32 String sep = path.getFileSystem().getSeparator(); 1.33 Path packageDir = packageName.isEmpty() ? pathDir 1.34 : pathDir.resolve(packageName.replace(".", sep)); 1.35 - if (!packageDir.exists()) 1.36 + if (!Files.exists(packageDir)) 1.37 return; 1.38 1.39 /* Alternate impl of list, superceded by use of Files.walkFileTree */ 1.40 @@ -353,7 +350,7 @@ 1.41 // DirectoryStream<Path> ds = dir.newDirectoryStream(); 1.42 // try { 1.43 // for (Path p: ds) { 1.44 -// String name = p.getName().toString(); 1.45 +// String name = p.getFileName().toString(); 1.46 // if (isDirectory(p)) { 1.47 // if (recurse && SourceVersion.isIdentifier(name)) { 1.48 // queue.add(p); 1.49 @@ -376,7 +373,7 @@ 1.50 new SimpleFileVisitor<Path>() { 1.51 @Override 1.52 public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) { 1.53 - Path name = dir.getName(); 1.54 + Path name = dir.getFileName(); 1.55 if (name == null || SourceVersion.isIdentifier(name.toString())) // JSR 292? 1.56 return FileVisitResult.CONTINUE; 1.57 else 1.58 @@ -385,7 +382,7 @@ 1.59 1.60 @Override 1.61 public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { 1.62 - if (attrs.isRegularFile() && kinds.contains(getKind(file.getName().toString()))) { 1.63 + if (attrs.isRegularFile() && kinds.contains(getKind(file.getFileName().toString()))) { 1.64 JavaFileObject fe = 1.65 PathFileObject.createDirectoryPathFileObject( 1.66 JavacPathFileManager.this, file, pathDir); 1.67 @@ -431,13 +428,13 @@ 1.68 for (Path p: getLocation(location)) { 1.69 if (isDirectory(p)) { 1.70 Path f = resolve(p, relativePath); 1.71 - if (f.exists()) 1.72 + if (Files.exists(f)) 1.73 return PathFileObject.createDirectoryPathFileObject(this, f, p); 1.74 } else { 1.75 FileSystem fs = getFileSystem(p); 1.76 if (fs != null) { 1.77 Path file = getPath(fs, relativePath); 1.78 - if (file.exists()) 1.79 + if (Files.exists(file)) 1.80 return PathFileObject.createJarPathFileObject(this, file); 1.81 } 1.82 } 1.83 @@ -504,7 +501,7 @@ 1.84 private FileSystem getFileSystem(Path p) throws IOException { 1.85 FileSystem fs = fileSystems.get(p); 1.86 if (fs == null) { 1.87 - fs = FileSystems.newFileSystem(p, Collections.<String,Void>emptyMap(), null); 1.88 + fs = FileSystems.newFileSystem(p, null); 1.89 fileSystems.put(p, fs); 1.90 } 1.91 return fs; 1.92 @@ -530,7 +527,7 @@ 1.93 } 1.94 1.95 private static boolean isDirectory(Path path) throws IOException { 1.96 - BasicFileAttributes attrs = Attributes.readBasicFileAttributes(path); 1.97 + BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class); 1.98 return attrs.isDirectory(); 1.99 } 1.100
2.1 --- a/src/share/classes/com/sun/tools/javac/nio/PathFileObject.java Fri Jan 28 00:09:38 2011 -0800 2.2 +++ b/src/share/classes/com/sun/tools/javac/nio/PathFileObject.java Fri Jan 28 09:25:20 2011 +0000 2.3 @@ -38,7 +38,6 @@ 2.4 import java.nio.charset.CharsetDecoder; 2.5 import java.nio.file.Files; 2.6 import java.nio.file.Path; 2.7 -import java.nio.file.attribute.Attributes; 2.8 import java.nio.file.attribute.BasicFileAttributes; 2.9 import javax.lang.model.element.Modifier; 2.10 import javax.lang.model.element.NestingKind; 2.11 @@ -153,7 +152,7 @@ 2.12 2.13 @Override 2.14 public Kind getKind() { 2.15 - return BaseFileManager.getKind(path.getName().toString()); 2.16 + return BaseFileManager.getKind(path.getFileName().toString()); 2.17 } 2.18 2.19 @Override 2.20 @@ -164,14 +163,14 @@ 2.21 return false; 2.22 } 2.23 String sn = simpleName + kind.extension; 2.24 - String pn = path.getName().toString(); 2.25 + String pn = path.getFileName().toString(); 2.26 if (pn.equals(sn)) { 2.27 return true; 2.28 } 2.29 if (pn.equalsIgnoreCase(sn)) { 2.30 try { 2.31 // allow for Windows 2.32 - return path.toRealPath(false).getName().toString().equals(sn); 2.33 + return path.toRealPath(false).getFileName().toString().equals(sn); 2.34 } catch (IOException e) { 2.35 } 2.36 } 2.37 @@ -200,13 +199,13 @@ 2.38 2.39 @Override 2.40 public InputStream openInputStream() throws IOException { 2.41 - return path.newInputStream(); 2.42 + return Files.newInputStream(path); 2.43 } 2.44 2.45 @Override 2.46 public OutputStream openOutputStream() throws IOException { 2.47 ensureParentDirectoriesExist(); 2.48 - return path.newOutputStream(); 2.49 + return Files.newOutputStream(path); 2.50 } 2.51 2.52 @Override 2.53 @@ -242,14 +241,13 @@ 2.54 @Override 2.55 public Writer openWriter() throws IOException { 2.56 ensureParentDirectoriesExist(); 2.57 - return new OutputStreamWriter(path.newOutputStream(), fileManager.getEncodingName()); 2.58 + return new OutputStreamWriter(Files.newOutputStream(path), fileManager.getEncodingName()); 2.59 } 2.60 2.61 @Override 2.62 public long getLastModified() { 2.63 try { 2.64 - BasicFileAttributes attrs = Attributes.readBasicFileAttributes(path); 2.65 - return attrs.lastModifiedTime().toMillis(); 2.66 + return Files.getLastModifiedTime(path).toMillis(); 2.67 } catch (IOException e) { 2.68 return -1; 2.69 } 2.70 @@ -258,7 +256,7 @@ 2.71 @Override 2.72 public boolean delete() { 2.73 try { 2.74 - path.delete(); 2.75 + Files.delete(path); 2.76 return true; 2.77 } catch (IOException e) { 2.78 return false; 2.79 @@ -267,7 +265,7 @@ 2.80 2.81 public boolean isSameFile(PathFileObject other) { 2.82 try { 2.83 - return path.isSameFile(other.path); 2.84 + return Files.isSameFile(path, other.path); 2.85 } catch (IOException e) { 2.86 return false; 2.87 } 2.88 @@ -296,8 +294,7 @@ 2.89 2.90 private long size() { 2.91 try { 2.92 - BasicFileAttributes attrs = Attributes.readBasicFileAttributes(path); 2.93 - return attrs.size(); 2.94 + return Files.size(path); 2.95 } catch (IOException e) { 2.96 return -1; 2.97 }
3.1 --- a/test/tools/javac/nio/compileTest/CompileTest.java Fri Jan 28 00:09:38 2011 -0800 3.2 +++ b/test/tools/javac/nio/compileTest/CompileTest.java Fri Jan 28 09:25:20 2011 +0000 3.3 @@ -84,8 +84,7 @@ 3.4 System.err.println("Test " + count + " " + Arrays.asList(opts) + " " + className); 3.5 Path testSrcDir = Paths.get(System.getProperty("test.src")); 3.6 Path testClassesDir = Paths.get(System.getProperty("test.classes")); 3.7 - Path classes = Paths.get("classes." + count); 3.8 - classes.createDirectory(); 3.9 + Path classes = Files.createDirectory(Paths.get("classes." + count)); 3.10 3.11 Context ctx = new Context(); 3.12 PathFileManager fm = new JavacPathFileManager(ctx, true, null);