ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject [1/2] ant git commit: reduce GC pressure by replacing File(In|Out)putStream
Date Wed, 12 Apr 2017 04:55:00 GMT
Repository: ant
Updated Branches:
  refs/heads/master 00d140c1b -> af74d1f6b


http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java
index da84f24..63caf50 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/ejb/WebsphereDeploymentTool.java
@@ -18,9 +18,9 @@
 package org.apache.tools.ant.taskdefs.optional.ejb;
 
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.file.Files;
 import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.Iterator;
@@ -775,7 +775,7 @@ public class WebsphereDeploymentTool extends GenericDeploymentTool {
                         newwasJarFile.delete();
                     }
 
-                    newJarStream = new JarOutputStream(new FileOutputStream(newwasJarFile));
+                    newJarStream = new JarOutputStream(Files.newOutputStream(newwasJarFile.toPath()));
                     newJarStream.setLevel(0);
 
                     //Copy files from old websphere jar

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibManifestTask.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibManifestTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibManifestTask.java
index 401dcfb..a5105e2 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibManifestTask.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/extension/JarLibManifestTask.java
@@ -18,8 +18,9 @@
 package org.apache.tools.ant.taskdefs.optional.extension;
 
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.jar.Attributes;
@@ -214,9 +215,9 @@ public final class JarLibManifestTask extends Task {
      * @throws IOException if error writing file
      */
     private void writeManifest(final Manifest manifest) throws IOException {
-        FileOutputStream output = null;
+        OutputStream output = null;
         try {
-            output = new FileOutputStream(destFile);
+            output = Files.newOutputStream(destFile.toPath());
             manifest.write(output);
             output.flush();
         } finally {

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java b/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java
index 82731fe..685468a 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/i18n/Translate.java
@@ -20,11 +20,12 @@ package org.apache.tools.ant.taskdefs.optional.i18n;
 import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.io.OutputStream;
 import java.io.OutputStreamWriter;
+import java.nio.file.Files;
 import java.util.Hashtable;
 import java.util.Locale;
 import java.util.Vector;
@@ -407,9 +408,9 @@ public class Translate extends MatchingTask {
     private void processBundle(final String bundleFile, final int i,
                                final boolean checkLoaded) throws BuildException {
         final File propsFile = getProject().resolveFile(bundleFile + ".properties");
-        FileInputStream ins = null;
+        InputStream ins = null;
         try {
-            ins = new FileInputStream(propsFile);
+            ins = Files.newInputStream(propsFile.toPath());
             loaded = true;
             bundleLastModified[i] = propsFile.lastModified();
             log("Using " + propsFile, Project.MSG_DEBUG);
@@ -429,7 +430,7 @@ public class Translate extends MatchingTask {
      * Load resourceMap with key value pairs.  Values of existing keys
      * are not overwritten.  Bundle's encoding scheme is used.
      */
-    private void loadResourceMap(FileInputStream ins) throws BuildException {
+    private void loadResourceMap(InputStream ins) throws BuildException {
         try {
             BufferedReader in = null;
             InputStreamReader isr = new InputStreamReader(ins, bundleEncoding);
@@ -551,9 +552,9 @@ public class Translate extends MatchingTask {
         BufferedWriter out = null;
         BufferedReader in = null;
         try {
-            FileOutputStream fos = new FileOutputStream(dest);
+            OutputStream fos = Files.newOutputStream(dest.toPath());
             out = new BufferedWriter(new OutputStreamWriter(fos, destEncoding));
-            FileInputStream fis = new FileInputStream(src);
+            InputStream fis = Files.newInputStream(src.toPath());
             in = new BufferedReader(new InputStreamReader(fis, srcEncoding));
             String line;
             LineTokenizer lineTokenizer = new LineTokenizer();

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/taskdefs/optional/image/Image.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/image/Image.java b/src/main/org/apache/tools/ant/taskdefs/optional/image/Image.java
index 9b3766e..5cef009 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/image/Image.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/image/Image.java
@@ -18,8 +18,9 @@
 package org.apache.tools.ant.taskdefs.optional.image;
 
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.file.Files;
 import java.util.Locale;
 import java.util.Vector;
 
@@ -316,9 +317,9 @@ public class Image extends MatchingTask {
                 newFile.delete();
             }
 
-            FileOutputStream stream = null;
+            OutputStream stream = null;
             try {
-                stream = new FileOutputStream(newFile);
+                stream = Files.newOutputStream(newFile.toPath());
 
                 JAI.create("encode", image, stream,
                            str_encoding.toUpperCase(Locale.ENGLISH),

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/taskdefs/optional/jlink/jlink.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/jlink/jlink.java b/src/main/org/apache/tools/ant/taskdefs/optional/jlink/jlink.java
index 5d45cfc..4f3cff9 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/jlink/jlink.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/jlink/jlink.java
@@ -24,10 +24,10 @@ package org.apache.tools.ant.taskdefs.optional.jlink;
 
 import java.io.BufferedInputStream;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.Enumeration;
 import java.util.Vector;
 import java.util.zip.CRC32;
@@ -145,7 +145,7 @@ public class jlink {
      * @throws Exception on error.
      */
     public void link() throws Exception { //NOSONAR
-        ZipOutputStream output = new ZipOutputStream(new FileOutputStream(outfile));
+        ZipOutputStream output = new ZipOutputStream(Files.newOutputStream(Paths.get(outfile)));
 
         if (compression) {
             output.setMethod(ZipOutputStream.DEFLATED);
@@ -303,7 +303,7 @@ public class jlink {
             // see if the file is in fact a .class file, and determine its actual name.
             InputStream input = null;
             try {
-                input = new FileInputStream(file);
+                input = Files.newInputStream(file.toPath());
                 String className = ClassNameReader.getClassName(input);
 
                 if (className != null) {
@@ -337,7 +337,7 @@ public class jlink {
         if (!compress) {
             entry.setCrc(calcChecksum(file));
         }
-        FileInputStream input = new FileInputStream(file);
+        InputStream input = Files.newInputStream(file.toPath());
 
         addToOutputStream(output, input, entry);
     }
@@ -422,7 +422,7 @@ public class jlink {
      * is not compressed.
      */
     private long calcChecksum(File f) throws IOException {
-        BufferedInputStream in = new BufferedInputStream(new FileInputStream(f));
+        BufferedInputStream in = new BufferedInputStream(Files.newInputStream(f.toPath()));
 
         return calcChecksum(in);
     }

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java
index ca47074..026412f 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/AggregateTransformer.java
@@ -18,11 +18,11 @@
 package org.apache.tools.ant.taskdefs.optional.junit;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.nio.file.Files;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Vector;
@@ -176,7 +176,7 @@ public class AggregateTransformer {
     protected void setXmlfile(File xmlfile) throws BuildException {
         try {
             DocumentBuilder builder = privateDBFactory.newDocumentBuilder();
-            try (InputStream in = new FileInputStream(xmlfile)) {
+            try (InputStream in = Files.newInputStream(xmlfile.toPath())) {
                 Document doc = builder.parse(in);
                 setXmlDocument(doc);
             }

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java
index f9fbcb0..6587b1d 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/FormatterElement.java
@@ -20,12 +20,12 @@ package org.apache.tools.ant.taskdefs.optional.junit;
 
 import java.io.BufferedOutputStream;
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.lang.reflect.Field;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.nio.file.Files;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
@@ -378,7 +378,7 @@ public class FormatterElement {
         public void write(int b) throws IOException {
             synchronized (this) {
                 if (outputStream == null) {
-                    outputStream = new BufferedOutputStream(new FileOutputStream(file));
+                    outputStream = new BufferedOutputStream(Files.newOutputStream(file.toPath()));
                 }
             }
             outputStream.write(b);

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
index 6a69d23..dcb2a98 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java
@@ -21,7 +21,6 @@ package org.apache.tools.ant.taskdefs.optional.junit;
 import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
@@ -29,6 +28,7 @@ import java.io.OutputStream;
 import java.io.PrintStream;
 import java.lang.reflect.Constructor;
 import java.net.URL;
+import java.nio.file.Files;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.ArrayList;
@@ -1243,7 +1243,7 @@ public class JUnitTask extends Task {
             props.put(key, p.get(key));
         }
         try {
-            final FileOutputStream outstream = new FileOutputStream(propsFile);
+            final OutputStream outstream = Files.newOutputStream(propsFile.toPath());
             props.store(outstream, "Ant JUnitTask generated properties file");
             outstream.close();
         } catch (final java.io.IOException e) {
@@ -1953,7 +1953,7 @@ public class JUnitTask extends Task {
                         final File outFile = getOutput(fe, test);
                         if (outFile != null) {
                             try {
-                                out = new FileOutputStream(outFile);
+                                out = Files.newOutputStream(outFile.toPath());
                             } catch (final IOException e) {
                                 // ignore
                             }

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
index c7d39e0..ea7524d 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunner.java
@@ -22,15 +22,17 @@ import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.PrintStream;
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.Properties;
@@ -940,8 +942,8 @@ public class JUnitTestRunner implements TestListener, JUnitTaskMirror.JUnitTestR
                     System.exit(ERRORS);
                 }
             } else if (args[i].startsWith(Constants.PROPSFILE)) {
-                final FileInputStream in = new FileInputStream(args[i]
-                                                         .substring(Constants.PROPSFILE.length()));
+                final InputStream in = Files.newInputStream(Paths.get(args[i]
+                                                     .substring(Constants.PROPSFILE.length())));
                 props.load(in);
                 in.close();
             } else if (args[i].startsWith(Constants.SHOWOUTPUT)) {

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java
index 97e2647..92e3553 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregator.java
@@ -19,11 +19,11 @@ package org.apache.tools.ant.taskdefs.optional.junit;
 
 import java.io.BufferedOutputStream;
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
+import java.nio.file.Files;
 import java.util.Enumeration;
 import java.util.Vector;
 
@@ -213,7 +213,7 @@ public class XMLResultAggregator extends Task implements XMLConstants {
      * @throws IOException thrown if there is an error while writing the content.
      */
     protected void writeDOMTree(Document doc, File file) throws IOException {
-        try (OutputStream os = new FileOutputStream(file);
+        try (OutputStream os = Files.newOutputStream(file.toPath());
              PrintWriter wri = new PrintWriter(new OutputStreamWriter(new BufferedOutputStream(os), "UTF8"))) {
             wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
             (new DOMElementWriter()).write(doc.getDocumentElement(), wri, 0, "  ");

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/taskdefs/optional/native2ascii/BuiltinNative2Ascii.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/native2ascii/BuiltinNative2Ascii.java b/src/main/org/apache/tools/ant/taskdefs/optional/native2ascii/BuiltinNative2Ascii.java
index 36e46c3..244b8c1 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/native2ascii/BuiltinNative2Ascii.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/native2ascii/BuiltinNative2Ascii.java
@@ -20,14 +20,13 @@ package org.apache.tools.ant.taskdefs.optional.native2ascii;
 import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.OutputStreamWriter;
 import java.io.Writer;
+import java.nio.file.Files;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.taskdefs.optional.Native2Ascii;
@@ -61,7 +60,7 @@ public class BuiltinNative2Ascii implements Native2AsciiAdapter {
                                      boolean reverse) throws IOException {
         if (!reverse && encoding != null) {
             return new BufferedReader(new InputStreamReader(
-                new FileInputStream(srcFile), encoding));
+                Files.newInputStream(srcFile.toPath()), encoding));
         }
         return new BufferedReader(new FileReader(srcFile));
     }
@@ -73,7 +72,7 @@ public class BuiltinNative2Ascii implements Native2AsciiAdapter {
         }
         if (encoding != null) {
             return new BufferedWriter(
-                new OutputStreamWriter(new FileOutputStream(destFile),
+                new OutputStreamWriter(Files.newOutputStream(destFile.toPath()),
                                        encoding));
         }
         return new BufferedWriter(new FileWriter(destFile));

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java b/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
index b783706..a9d079c 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
@@ -21,12 +21,11 @@ import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
 import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.nio.file.Files;
 import java.text.SimpleDateFormat;
 import java.util.Collection;
 import java.util.Date;
@@ -1957,7 +1956,7 @@ public class FTP extends Task implements FTPTaskConfig {
             // create a local temporary file
             FILE_UTILS.createNewFile(tempFile);
             long localTimeStamp = tempFile.lastModified();
-            BufferedInputStream instream = new BufferedInputStream(new FileInputStream(tempFile));
+            BufferedInputStream instream = new BufferedInputStream(Files.newInputStream(tempFile.toPath()));
             ftp.storeFile(tempFile.getName(), instream);
             instream.close();
             boolean success = FTPReply.isPositiveCompletion(ftp.getReplyCode());
@@ -2148,7 +2147,7 @@ public class FTP extends Task implements FTPTaskConfig {
                 log("transferring " + file.getAbsolutePath());
             }
 
-            instream = new BufferedInputStream(new FileInputStream(file));
+            instream = new BufferedInputStream(Files.newInputStream(file.toPath()));
 
             createParents(ftp, filename);
 
@@ -2278,7 +2277,7 @@ public class FTP extends Task implements FTPTaskConfig {
             if (!pdir.exists()) {
                 pdir.mkdirs();
             }
-            outstream = new BufferedOutputStream(new FileOutputStream(file));
+            outstream = new BufferedOutputStream(Files.newOutputStream(file.toPath()));
             ftp.retrieveFile(resolveFile(filename), outstream);
 
             if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/taskdefs/optional/net/FTPTaskMirrorImpl.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/net/FTPTaskMirrorImpl.java b/src/main/org/apache/tools/ant/taskdefs/optional/net/FTPTaskMirrorImpl.java
index 6cb79c8..35f01b3 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/net/FTPTaskMirrorImpl.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/net/FTPTaskMirrorImpl.java
@@ -21,12 +21,11 @@ import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
 import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.nio.file.Files;
 import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.Enumeration;
@@ -1346,7 +1345,7 @@ public class FTPTaskMirrorImpl implements FTPTaskMirror {
             // create a local temporary file
             FILE_UTILS.createNewFile(tempFile);
             long localTimeStamp = tempFile.lastModified();
-            BufferedInputStream instream = new BufferedInputStream(new FileInputStream(tempFile));
+            BufferedInputStream instream = new BufferedInputStream(Files.newInputStream(tempFile.toPath()));
             ftp.storeFile(tempFile.getName(), instream);
             instream.close();
             boolean success = FTPReply.isPositiveCompletion(ftp.getReplyCode());
@@ -1535,7 +1534,7 @@ public class FTPTaskMirrorImpl implements FTPTaskMirror {
                 task.log("transferring " + file.getAbsolutePath());
             }
 
-            instream = new BufferedInputStream(new FileInputStream(file));
+            instream = new BufferedInputStream(Files.newInputStream(file.toPath()));
 
             createParents(ftp, filename);
 
@@ -1666,7 +1665,7 @@ public class FTPTaskMirrorImpl implements FTPTaskMirror {
             if (!pdir.exists()) {
                 pdir.mkdirs();
             }
-            outstream = new BufferedOutputStream(new FileOutputStream(file));
+            outstream = new BufferedOutputStream(Files.newOutputStream(file.toPath()));
             ftp.retrieveFile(resolveFile(filename), outstream);
 
             if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) {

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java b/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java
index dd6016a..7bcfef9 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java
@@ -21,10 +21,11 @@ import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.File;
 import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.file.Files;
 import java.text.MessageFormat;
 import java.text.ParseException;
 import java.util.Enumeration;
@@ -198,7 +199,7 @@ public class Pvcs extends org.apache.tools.ant.Task {
         try {
             Random rand = new Random(System.currentTimeMillis());
             tmp = new File("pvcs_ant_" + rand.nextLong() + ".log");
-            FileOutputStream fos = new FileOutputStream(tmp);
+            OutputStream fos = Files.newOutputStream(tmp.toPath());
             tmp2 = new File("pvcs_ant_" + rand.nextLong() + ".log");
             log(commandLine.describeCommand(), Project.MSG_VERBOSE);
             try {

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java
index 7d49709..3942003 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java
@@ -22,13 +22,13 @@ import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.StringReader;
+import java.nio.file.Files;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
@@ -360,7 +360,7 @@ public class SSHExec extends SSHBase {
         InputStream istream = null;
         if (inputFile != null) {
             try {
-                istream = new FileInputStream(inputFile);
+                istream = Files.newInputStream(inputFile.toPath());
             } catch (final IOException e) {
                 // because we checked the existence before, this one
                 // shouldn't happen What if the file exists, but there

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessage.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessage.java b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessage.java
index b6b9b01..8775c11 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessage.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpFromMessage.java
@@ -21,10 +21,10 @@ package org.apache.tools.ant.taskdefs.optional.ssh;
 import java.io.ByteArrayOutputStream;
 import java.io.EOFException;
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.nio.file.Files;
 
 import org.apache.tools.ant.util.FileUtils;
 
@@ -262,7 +262,7 @@ public class ScpFromMessage extends AbstractSshMessage {
         sendAck(out);
 
         // read a content of lfile
-        final FileOutputStream fos = new FileOutputStream(localFile);
+        final OutputStream fos = Files.newOutputStream(localFile.toPath());
         int length;
         long totalLength = 0;
         final long startTime = System.currentTimeMillis();

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessage.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessage.java b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessage.java
index 7b0a0f2..214dd4e 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessage.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/ssh/ScpToMessage.java
@@ -19,10 +19,10 @@
 package org.apache.tools.ant.taskdefs.optional.ssh;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.nio.file.Files;
 import java.util.Iterator;
 import java.util.List;
 
@@ -363,7 +363,7 @@ public class ScpToMessage extends AbstractSshMessage {
         waitForAck(in);
 
         // send a content of lfile
-        final FileInputStream fis = new FileInputStream(localFile);
+        final InputStream fis = Files.newInputStream(localFile.toPath());
         final byte[] buf = new byte[BUFFER_SIZE];
         final long startTime = System.currentTimeMillis();
         long totalLength = 0;

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java b/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java
index e83c0b6..a45b74f 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/unix/Symlink.java
@@ -32,12 +32,12 @@ package org.apache.tools.ant.taskdefs.optional.unix;
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.io.PrintStream;
+import java.nio.file.Files;
 import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Iterator;
@@ -437,7 +437,7 @@ public class Symlink extends DispatchTask {
         BufferedOutputStream bos = null;
         try {
             bos = new BufferedOutputStream(
-                new FileOutputStream(new File(dir, linkFileName)));
+                Files.newOutputStream(new File(dir, linkFileName).toPath()));
             properties.store(bos, "Symlinks from " + dir);
         } catch (IOException ioe) {
             throw new BuildException(ioe, getLocation());
@@ -567,7 +567,7 @@ public class Symlink extends DispatchTask {
                 Properties lnks = new Properties();
                 InputStream is = null;
                 try {
-                    is = new BufferedInputStream(new FileInputStream(inc));
+                    is = new BufferedInputStream(Files.newInputStream(inc.toPath()));
                     lnks.load(is);
                     pf = pf.getCanonicalFile();
                 } catch (FileNotFoundException fnfe) {

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/taskdefs/optional/xz/Unxz.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/xz/Unxz.java b/src/main/org/apache/tools/ant/taskdefs/optional/xz/Unxz.java
index a98ae6d..f55fb7c 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/xz/Unxz.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/xz/Unxz.java
@@ -18,9 +18,10 @@
 
 package org.apache.tools.ant.taskdefs.optional.xz;
 
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.taskdefs.Unpack;
@@ -57,11 +58,11 @@ public class Unxz extends Unpack {
             log("Expanding " + srcResource.getName() + " to "
                         + dest.getAbsolutePath());
 
-            FileOutputStream out = null;
+            OutputStream out = null;
             XZInputStream zIn = null;
             InputStream fis = null;
             try {
-                out = new FileOutputStream(dest);
+                out = Files.newOutputStream(dest.toPath());
                 fis = srcResource.getInputStream();
                 zIn = new XZInputStream(fis);
                 byte[] buffer = new byte[BUFFER_SIZE];

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/taskdefs/optional/xz/Xz.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/xz/Xz.java b/src/main/org/apache/tools/ant/taskdefs/optional/xz/Xz.java
index d88f910..7603192 100644
--- a/src/main/org/apache/tools/ant/taskdefs/optional/xz/Xz.java
+++ b/src/main/org/apache/tools/ant/taskdefs/optional/xz/Xz.java
@@ -19,8 +19,8 @@
 package org.apache.tools.ant.taskdefs.optional.xz;
 
 import java.io.BufferedOutputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
+import java.nio.file.Files;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.util.FileUtils;
@@ -44,7 +44,7 @@ public class Xz extends Pack {
     protected void pack() {
         XZOutputStream zOut = null;
         try {
-            zOut = new XZOutputStream(new FileOutputStream(zipFile),
+            zOut = new XZOutputStream(Files.newOutputStream(zipFile.toPath()),
                                       new LZMA2Options());
             zipResource(getSrcResource(), zOut);
         } catch (IOException ioe) {

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/types/FilterSet.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/FilterSet.java b/src/main/org/apache/tools/ant/types/FilterSet.java
index 2c1f2e7..4ff3181 100644
--- a/src/main/org/apache/tools/ant/types/FilterSet.java
+++ b/src/main/org/apache/tools/ant/types/FilterSet.java
@@ -18,7 +18,8 @@
 package org.apache.tools.ant.types;
 
 import java.io.File;
-import java.io.FileInputStream;
+import java.io.InputStream;
+import java.nio.file.Files;
 import java.util.Enumeration;
 import java.util.Hashtable;
 import java.util.Map;
@@ -367,10 +368,10 @@ public class FilterSet extends DataType implements Cloneable {
         }
         if (filtersFile.isFile()) {
            log("Reading filters from " + filtersFile, Project.MSG_VERBOSE);
-           FileInputStream in = null;
+           InputStream in = null;
            try {
               Properties props = new Properties();
-              in = new FileInputStream(filtersFile);
+              in = Files.newInputStream(filtersFile.toPath());
               props.load(in);
 
               Enumeration<?> e = props.propertyNames();

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/types/XMLCatalog.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/XMLCatalog.java b/src/main/org/apache/tools/ant/types/XMLCatalog.java
index 2edd5a1..9281d5d 100644
--- a/src/main/org/apache/tools/ant/types/XMLCatalog.java
+++ b/src/main/org/apache/tools/ant/types/XMLCatalog.java
@@ -19,13 +19,13 @@
 package org.apache.tools.ant.types;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.reflect.Method;
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
+import java.nio.file.Files;
 import java.util.Stack;
 import java.util.Vector;
 
@@ -677,7 +677,7 @@ public class XMLCatalog extends DataType
                 File resFile = new File(fileName);
                 if (resFile.exists() && resFile.canRead()) {
                     try {
-                        source = new InputSource(new FileInputStream(resFile));
+                        source = new InputSource(Files.newInputStream(resFile.toPath()));
                         String sysid = JAXPUtils.getSystemId(resFile);
                         source.setSystemId(sysid);
                         log("catalog entry matched a readable file: '"

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/types/resources/FileResource.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resources/FileResource.java b/src/main/org/apache/tools/ant/types/resources/FileResource.java
index e967907..d427888 100644
--- a/src/main/org/apache/tools/ant/types/resources/FileResource.java
+++ b/src/main/org/apache/tools/ant/types/resources/FileResource.java
@@ -18,11 +18,10 @@
 package org.apache.tools.ant.types.resources;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.nio.file.Files;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
@@ -216,7 +215,7 @@ public class FileResource extends Resource implements Touchable, FileProvider,
     public InputStream getInputStream() throws IOException {
         return isReference()
             ? ((Resource) getCheckedRef()).getInputStream()
-            : new FileInputStream(getNotNullFile());
+            : Files.newInputStream(getNotNullFile().toPath());
     }
 
     /**
@@ -256,7 +255,7 @@ public class FileResource extends Resource implements Touchable, FileProvider,
                 p.mkdirs();
             }
         }
-        return append ? new FileOutputStream(f.getAbsolutePath(), true) : new FileOutputStream(f);
+        return FileUtils.newOutputStream(f.toPath(), append);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/types/selectors/modifiedselector/ChecksumAlgorithm.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/selectors/modifiedselector/ChecksumAlgorithm.java b/src/main/org/apache/tools/ant/types/selectors/modifiedselector/ChecksumAlgorithm.java
index 210d5dc..26c6945 100644
--- a/src/main/org/apache/tools/ant/types/selectors/modifiedselector/ChecksumAlgorithm.java
+++ b/src/main/org/apache/tools/ant/types/selectors/modifiedselector/ChecksumAlgorithm.java
@@ -20,7 +20,8 @@ package org.apache.tools.ant.types.selectors.modifiedselector;
 
 import java.io.BufferedInputStream;
 import java.io.File;
-import java.io.FileInputStream;
+import java.io.InputStream;
+import java.nio.file.Files;
 import java.security.NoSuchAlgorithmException;
 import java.util.Locale;
 import java.util.zip.Adler32;
@@ -121,7 +122,7 @@ public class ChecksumAlgorithm implements Algorithm {
         try {
             if (file.canRead()) {
                  checksum.reset();
-                 FileInputStream fis = new FileInputStream(file);
+                 InputStream fis = Files.newInputStream(file.toPath());
                  CheckedInputStream check = new CheckedInputStream(fis, checksum);
                  BufferedInputStream in = new BufferedInputStream(check);
                  while (in.read() != -1) {

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/types/selectors/modifiedselector/DigestAlgorithm.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/selectors/modifiedselector/DigestAlgorithm.java b/src/main/org/apache/tools/ant/types/selectors/modifiedselector/DigestAlgorithm.java
index 085b4fe..9624145 100644
--- a/src/main/org/apache/tools/ant/types/selectors/modifiedselector/DigestAlgorithm.java
+++ b/src/main/org/apache/tools/ant/types/selectors/modifiedselector/DigestAlgorithm.java
@@ -20,7 +20,8 @@ package org.apache.tools.ant.types.selectors.modifiedselector;
 
 
 import java.io.File;
-import java.io.FileInputStream;
+import java.io.InputStream;
+import java.nio.file.Files;
 import java.security.DigestInputStream;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
@@ -158,12 +159,12 @@ public class DigestAlgorithm implements Algorithm {
             if (!file.canRead()) {
                 return null;
             }
-            FileInputStream fis = null;
+            InputStream fis = null;
 
             byte[] buf = new byte[readBufferSize];
             try {
                 messageDigest.reset();
-                fis = new FileInputStream(file);
+                fis = Files.newInputStream(file.toPath());
                 DigestInputStream dis = new DigestInputStream(fis,
                                                               messageDigest);
                 while (dis.read(buf, 0, readBufferSize) != -1) {

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/types/selectors/modifiedselector/PropertiesfileCache.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/selectors/modifiedselector/PropertiesfileCache.java b/src/main/org/apache/tools/ant/types/selectors/modifiedselector/PropertiesfileCache.java
index e8cf3fe..2a16d1f 100644
--- a/src/main/org/apache/tools/ant/types/selectors/modifiedselector/PropertiesfileCache.java
+++ b/src/main/org/apache/tools/ant/types/selectors/modifiedselector/PropertiesfileCache.java
@@ -22,8 +22,9 @@ package org.apache.tools.ant.types.selectors.modifiedselector;
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
 import java.util.Enumeration;
 import java.util.Iterator;
 import java.util.Properties;
@@ -133,7 +134,7 @@ public class PropertiesfileCache implements Cache {
         if ((cachefile != null) && cachefile.isFile() && cachefile.canRead()) {
             try {
                 BufferedInputStream bis = new BufferedInputStream(
-                    new FileInputStream(cachefile));
+                    Files.newInputStream(cachefile.toPath()));
                 cache.load(bis);
                 bis.close();
             } catch (Exception e) {
@@ -159,7 +160,7 @@ public class PropertiesfileCache implements Cache {
         if ((cachefile != null) && cache.propertyNames().hasMoreElements()) {
             try {
                 BufferedOutputStream bos = new BufferedOutputStream(
-                      new FileOutputStream(cachefile));
+                      Files.newOutputStream(cachefile.toPath()));
                 cache.store(bos, null);
                 bos.flush();
                 bos.close();

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/util/ConcatFileInputStream.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/ConcatFileInputStream.java b/src/main/org/apache/tools/ant/util/ConcatFileInputStream.java
index 22dcb7f..ff0111e 100644
--- a/src/main/org/apache/tools/ant/util/ConcatFileInputStream.java
+++ b/src/main/org/apache/tools/ant/util/ConcatFileInputStream.java
@@ -20,9 +20,9 @@ package org.apache.tools.ant.util;
 
 import java.io.BufferedInputStream;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.file.Files;
 
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.ProjectComponent;
@@ -119,7 +119,7 @@ public class ConcatFileInputStream extends InputStream {
             log("Opening " + file[index], Project.MSG_VERBOSE);
             try {
                 currentStream = new BufferedInputStream(
-                    new FileInputStream(file[index]));
+                    Files.newInputStream(file[index].toPath()));
             } catch (IOException eyeOhEx) {
                 log("Failed to open " + file[index], Project.MSG_ERR);
                 throw eyeOhEx;

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/util/FileUtils.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/FileUtils.java b/src/main/org/apache/tools/ant/util/FileUtils.java
index 0c314b2..11ae06b 100644
--- a/src/main/org/apache/tools/ant/util/FileUtils.java
+++ b/src/main/org/apache/tools/ant/util/FileUtils.java
@@ -31,6 +31,9 @@ import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.nio.channels.Channel;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardOpenOption;
 import java.text.DecimalFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -1707,4 +1710,20 @@ public class FileUtils {
             close(is);
         }
     }
+
+    /**
+     * Opens a new OutputStream for the given Path.
+     * @param path the path of the file
+     * @param whether to append to or a replace an existing file
+     * @return a stream ready to write to the file
+     * @since Ant 1.10.2
+     */
+    public static OutputStream newOutputStream(Path path, boolean append) throws IOException {
+        if (append) {
+            return Files.newOutputStream(path, StandardOpenOption.CREATE, StandardOpenOption.APPEND,
+                StandardOpenOption.WRITE);
+        } else {
+            return Files.newOutputStream(path);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java b/src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java
index eceb9a0..853bec2 100644
--- a/src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java
+++ b/src/main/org/apache/tools/ant/util/LayoutPreservingProperties.java
@@ -20,7 +20,6 @@ package org.apache.tools.ant.util;
 import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -28,6 +27,7 @@ import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.PrintStream;
 import java.io.PushbackReader;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
@@ -250,7 +250,7 @@ public class LayoutPreservingProperties extends Properties {
      * @param dest the file to write to
      */
     public void saveAs(final File dest) throws IOException {
-        final FileOutputStream fos = new FileOutputStream(dest);
+        final OutputStream fos = Files.newOutputStream(dest.toPath());
         store(fos, null);
         fos.close();
     }

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/util/LazyFileOutputStream.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/LazyFileOutputStream.java b/src/main/org/apache/tools/ant/util/LazyFileOutputStream.java
index 7e5bf78..781d0c7 100644
--- a/src/main/org/apache/tools/ant/util/LazyFileOutputStream.java
+++ b/src/main/org/apache/tools/ant/util/LazyFileOutputStream.java
@@ -18,9 +18,9 @@
 package org.apache.tools.ant.util;
 
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
+import org.apache.tools.ant.util.FileUtils;
 
 /**
  * Class that delays opening the output file until the first bytes
@@ -31,7 +31,7 @@ import java.io.OutputStream;
  */
 public class LazyFileOutputStream extends OutputStream {
 
-    private FileOutputStream fos;
+    private OutputStream fos;
     private File file;
     private boolean append;
     private boolean alwaysCreate;
@@ -155,7 +155,7 @@ public class LazyFileOutputStream extends OutputStream {
         }
 
         if (!opened) {
-            fos = new FileOutputStream(file.getAbsolutePath(), append);
+            fos = FileUtils.newOutputStream(file.toPath(), append);
             opened = true;
         }
     }

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/util/ResourceUtils.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/ResourceUtils.java b/src/main/org/apache/tools/ant/util/ResourceUtils.java
index 518ed5a..c4532a7 100644
--- a/src/main/org/apache/tools/ant/util/ResourceUtils.java
+++ b/src/main/org/apache/tools/ant/util/ResourceUtils.java
@@ -21,8 +21,6 @@ import java.io.BufferedInputStream;
 import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -30,6 +28,7 @@ import java.io.OutputStream;
 import java.io.OutputStreamWriter;
 import java.io.Reader;
 import java.nio.channels.FileChannel;
+import java.nio.file.StandardOpenOption;
 import java.util.Arrays;
 import java.util.Vector;
 
@@ -777,17 +776,13 @@ public class ResourceUtils {
                                   + " for " + destFile);
         }
 
-        FileInputStream in = null;
-        FileOutputStream out = null;
         FileChannel srcChannel = null;
         FileChannel destChannel = null;
 
         try {
-            in = new FileInputStream(sourceFile);
-            out = new FileOutputStream(destFile);
-
-            srcChannel = in.getChannel();
-            destChannel = out.getChannel();
+            srcChannel = FileChannel.open(sourceFile.toPath(), StandardOpenOption.READ);
+            destChannel = FileChannel.open(destFile.toPath(), StandardOpenOption.CREATE,
+                StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE);
 
             long position = 0;
             final long count = srcChannel.size();
@@ -799,8 +794,6 @@ public class ResourceUtils {
         } finally {
             FileUtils.close(srcChannel);
             FileUtils.close(destChannel);
-            FileUtils.close(out);
-            FileUtils.close(in);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java b/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
index f2b6017..4765268 100644
--- a/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
+++ b/src/main/org/apache/tools/ant/util/ScriptRunnerBase.java
@@ -19,13 +19,12 @@ package org.apache.tools.ant.util;
 
 import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Reader;
 import java.nio.charset.Charset;
+import java.nio.file.Files;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -233,8 +232,8 @@ public abstract class ScriptRunnerBase {
 
         InputStream in = null;
         try {
-            in = new FileInputStream(file);
-        } catch (FileNotFoundException e) {
+            in = Files.newInputStream(file.toPath());
+        } catch (IOException e) {
             //this can only happen if the file got deleted a short moment ago
             throw new BuildException("file " + filename + " not found.");
         }

http://git-wip-us.apache.org/repos/asf/ant/blob/af74d1f6/src/main/org/apache/tools/zip/ZipOutputStream.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/zip/ZipOutputStream.java b/src/main/org/apache/tools/zip/ZipOutputStream.java
index 228ce61..23f4eac 100644
--- a/src/main/org/apache/tools/zip/ZipOutputStream.java
+++ b/src/main/org/apache/tools/zip/ZipOutputStream.java
@@ -31,12 +31,12 @@ import static org.apache.tools.zip.ZipShort.putShort;
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.FilterOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.io.RandomAccessFile;
 import java.nio.ByteBuffer;
+import java.nio.file.Files;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.HashMap;
@@ -355,7 +355,7 @@ public class ZipOutputStream extends FilterOutputStream {
                 }
                 _raf = null;
             }
-            out = new FileOutputStream(file);
+            out = Files.newOutputStream(file.toPath());
         }
         raf = _raf;
     }


Mime
View raw message