changeset 3481:527e819dbc95

8145472: replace remaining java.io.File with java.nio.file.Path Reviewed-by: vromero
author jjg
date Tue, 23 Feb 2016 16:38:04 -0800
parents f04e97a97930
children 21d9e172e9f6
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java src/jdk.compiler/share/classes/com/sun/tools/javac/main/CommandLine.java src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java src/jdk.compiler/share/classes/com/sun/tools/javac/main/OptionHelper.java
diffstat 5 files changed, 37 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java	Tue Feb 23 16:25:01 2016 -0800
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java	Tue Feb 23 16:38:04 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -44,9 +44,11 @@
 import com.sun.tools.javac.comp.Resolve.InapplicableMethodException;
 import com.sun.tools.javac.comp.Resolve.VerboseResolutionMode;
 
-import java.io.File;
-import java.io.FileWriter;
 import java.io.IOException;
+import java.io.Writer;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -353,9 +355,9 @@
                         rsContext.attrMode(),
                         rsContext.step,
                         round);
-                File dotFile = new File(dependenciesFolder, filename);
-                try (FileWriter fw = new FileWriter(dotFile)) {
-                    fw.append(graph);
+                Path dotFile = Paths.get(dependenciesFolder, filename);
+                try (Writer w = Files.newBufferedWriter(dotFile)) {
+                    w.append(graph);
                 }
                 round++;
             }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java	Tue Feb 23 16:25:01 2016 -0800
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Arguments.java	Tue Feb 23 16:38:04 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,9 +25,10 @@
 
 package com.sun.tools.javac.main;
 
-import java.io.File;
 import java.io.IOException;
+import java.nio.file.Files;
 import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
@@ -73,7 +74,7 @@
 
     private String ownName;
     private Set<String> classNames;
-    private Set<File> files;
+    private Set<Path> files;
     private Map<Option, String> deferredFileManagerOptions;
     private Set<JavaFileObject> fileObjects;
     private final Options options;
@@ -153,8 +154,8 @@
         }
 
         @Override
-        public void addFile(File f) {
-            files.add(f);
+        public void addFile(Path p) {
+            files.add(p);
         }
 
         @Override
@@ -252,7 +253,7 @@
             } else {
                 fileObjects = new LinkedHashSet<>();
                 JavacFileManager jfm = (JavacFileManager) getFileManager();
-                for (JavaFileObject fo: jfm.getJavaFileObjectsFromFiles(files))
+                for (JavaFileObject fo: jfm.getJavaFileObjectsFromPaths(files))
                     fileObjects.add(fo);
             }
         }
@@ -583,8 +584,8 @@
         if (value == null) {
             return true;
         }
-        File file = new File(value);
-        if (file.exists() && !file.isDirectory()) {
+        Path file = Paths.get(value);
+        if (Files.exists(file) && !Files.isDirectory(file)) {
             error("err.file.not.directory", value);
             return false;
         }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/CommandLine.java	Tue Feb 23 16:25:01 2016 -0800
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/CommandLine.java	Tue Feb 23 16:38:04 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,9 +27,10 @@
 
 import java.io.IOException;
 import java.io.Reader;
-import java.io.FileReader;
-import java.io.BufferedReader;
 import java.io.StreamTokenizer;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
 import com.sun.tools.javac.util.ListBuffer;
 
 /**
@@ -73,7 +74,7 @@
     private static void loadCmdFile(String name, ListBuffer<String> args)
         throws IOException
     {
-        try (Reader r = new BufferedReader(new FileReader(name))) {
+        try (Reader r = Files.newBufferedReader(Paths.get(name))) {
             StreamTokenizer st = new StreamTokenizer(r);
             st.resetSyntax();
             st.wordChars(' ', 255);
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java	Tue Feb 23 16:25:01 2016 -0800
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/Option.java	Tue Feb 23 16:38:04 2016 -0800
@@ -25,9 +25,11 @@
 
 package com.sun.tools.javac.main;
 
-import java.io.File;
 import java.io.FileWriter;
 import java.io.PrintWriter;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.Collections;
 import java.util.EnumSet;
 import java.util.LinkedHashMap;
@@ -531,16 +533,16 @@
         @Override
         public boolean process(OptionHelper helper, String option) {
             if (option.endsWith(".java") ) {
-                File f = new File(option);
-                if (!f.exists()) {
-                    helper.error("err.file.not.found", f);
+                Path p = Paths.get(option);
+                if (!Files.exists(p)) {
+                    helper.error("err.file.not.found", p);
                     return true;
                 }
-                if (!f.isFile()) {
-                    helper.error("err.file.not.file", f);
+                if (!Files.isRegularFile(p)) {
+                    helper.error("err.file.not.file", p);
                     return true;
                 }
-                helper.addFile(f);
+                helper.addFile(p);
             } else {
                 helper.addClassName(option);
             }
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/OptionHelper.java	Tue Feb 23 16:25:01 2016 -0800
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/OptionHelper.java	Tue Feb 23 16:38:04 2016 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,9 +25,10 @@
 
 package com.sun.tools.javac.main;
 
+import java.nio.file.Path;
+
 import com.sun.tools.javac.util.Log;
 import com.sun.tools.javac.util.Log.PrefixKind;
-import java.io.File;
 
 /**
  * Helper object to be used by {@link Option#process}, providing access to
@@ -63,7 +64,7 @@
     abstract void error(String key, Object... args);
 
     /** Record a file to be compiled. */
-    abstract void addFile(File f);
+    abstract void addFile(Path p);
 
     /** Record the name of a class for annotation processing. */
     abstract void addClassName(String s);
@@ -112,8 +113,8 @@
         }
 
         @Override
-        public void addFile(File f) {
-            throw new IllegalArgumentException(f.getPath());
+        public void addFile(Path p) {
+            throw new IllegalArgumentException(p.toString());
         }
 
         @Override