This is an automated email from the ASF dual-hosted git repository.

matthiasblaesing pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-netbeans.git

commit 4b82e6adb31e294c74fd2fa99779ce9e27ae6184
Author: Martin Dindoffer <[email protected]>
AuthorDate: Sat Dec 2 21:03:14 2017 +0100

    Move to Files.new* creation of I/O streams during IDE boot
    
    FileOutputStream and FileInputStream complicate GC because they both
    override `#finalize()`. Switching to NIO API creates Stream without
    finalizers and thus relieving GC.
---
 core.netigso/nbproject/project.properties          |  2 +-
 .../src/org/netbeans/core/netigso/Netigso.java     | 12 ++--
 .../core/network/proxy/NbProxySelector.java        | 10 ++--
 .../core/network/proxy/kde/KdeNetworkProxy.java    | 17 ++----
 core.osgi/nbproject/project.properties             |  2 +-
 .../core/osgi/OSGiInstalledFileLocator.java        | 24 +++-----
 core.output2/nbproject/project.properties          |  2 +-
 .../org/netbeans/core/output2/AbstractLines.java   | 45 +++++++-------
 .../src/org/netbeans/core/output2/Controller.java  |  4 +-
 core.startup.base/nbproject/project.properties     |  2 +-
 .../core/startup/layers/ArchiveURLMapper.java      | 17 ++----
 .../startup/layers/NbinstURLStreamHandler.java     |  9 ++-
 .../core/startup/layers/SystemFileSystemTest.java  | 16 ++---
 .../core/startup/logging/MessagesHandler.java      |  9 +--
 .../netbeans/core/startup/logging/NbLogging.java   | 12 ++--
 o.n.bootstrap/src/org/netbeans/JarClassLoader.java | 38 +++++-------
 o.n.bootstrap/src/org/netbeans/Stamps.java         | 68 ++++++++--------------
 o.n.bootstrap/src/org/netbeans/Util.java           | 25 ++++----
 .../src/org/openide/filesystems/JarFileSystem.java | 22 +++----
 .../org/openide/filesystems/LocalFileSystem.java   | 27 +++++----
 20 files changed, 165 insertions(+), 198 deletions(-)

diff --git a/core.netigso/nbproject/project.properties 
b/core.netigso/nbproject/project.properties
index f00a000..d593729 100644
--- a/core.netigso/nbproject/project.properties
+++ b/core.netigso/nbproject/project.properties
@@ -16,7 +16,7 @@
 # under the License.
 
 is.autoload=true
-javac.source=1.6
+javac.source=1.7
 javac.compilerargs=-Xlint -Xlint:-serial
 javadoc.arch=${basedir}/arch.xml
 javadoc.apichanges=${basedir}/apichanges.xml
diff --git a/core.netigso/src/org/netbeans/core/netigso/Netigso.java 
b/core.netigso/src/org/netbeans/core/netigso/Netigso.java
index 3d3ae68..bad7d6b 100644
--- a/core.netigso/src/org/netbeans/core/netigso/Netigso.java
+++ b/core.netigso/src/org/netbeans/core/netigso/Netigso.java
@@ -22,10 +22,11 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.DataOutputStream;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
 import java.security.ProtectionDomain;
 import java.util.Arrays;
 import java.util.Collection;
@@ -36,7 +37,6 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
-import java.util.StringTokenizer;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
@@ -453,9 +453,11 @@ implements Cloneable, Stamps.Updater {
             } else if (symbolicName != null) { // NOI18N
                 if (original != null) {
                     LOG.log(Level.FINE, "Updating bundle {0}", 
original.getLocation());
-                    FileInputStream is = new FileInputStream(m.getJarFile());
-                    original.update(is);
-                    is.close();
+                    try (InputStream is = 
Files.newInputStream(m.getJarFile().toPath())) {
+                        original.update(is);
+                    } catch (InvalidPathException ex) {
+                        throw new IOException(ex);
+                    }
                     b = original;
                 } else {
                     BundleContext bc = framework.getBundleContext();
diff --git 
a/core.network/src/org/netbeans/core/network/proxy/NbProxySelector.java 
b/core.network/src/org/netbeans/core/network/proxy/NbProxySelector.java
index 394c39a..440ff50 100644
--- a/core.network/src/org/netbeans/core/network/proxy/NbProxySelector.java
+++ b/core.network/src/org/netbeans/core/network/proxy/NbProxySelector.java
@@ -21,10 +21,11 @@ package org.netbeans.core.network.proxy;
 
 import java.io.BufferedInputStream;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.*;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.*;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -421,10 +422,9 @@ public final class NbProxySelector extends ProxySelector {
                 }
 
                 fname = netProperties.getCanonicalPath();
-                InputStream in = new FileInputStream(fname);
-                BufferedInputStream bin = new BufferedInputStream(in);
-                props.load(bin);
-                bin.close();
+                try (InputStream bin = new 
BufferedInputStream(Files.newInputStream(Paths.get(fname)))) {
+                    props.load(bin);
+                }
 
                 String val = props.getProperty(propertyKey);
                 val = System.getProperty(propertyKey, val);
diff --git 
a/core.network/src/org/netbeans/core/network/proxy/kde/KdeNetworkProxy.java 
b/core.network/src/org/netbeans/core/network/proxy/kde/KdeNetworkProxy.java
index 553d1e5..505fb9a 100644
--- a/core.network/src/org/netbeans/core/network/proxy/kde/KdeNetworkProxy.java
+++ b/core.network/src/org/netbeans/core/network/proxy/kde/KdeNetworkProxy.java
@@ -19,12 +19,11 @@
 package org.netbeans.core.network.proxy.kde;
 
 import java.io.BufferedReader;
-import java.io.DataInputStream;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.io.InputStreamReader;
+import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.logging.Level;
@@ -133,10 +132,7 @@ public class KdeNetworkProxy implements 
NetworkProxyResolver {
         Map<String, String> map = new HashMap<String, String>();
 
         if (kioslavercFile.exists()) {
-            try {
-                FileInputStream fis = new FileInputStream(kioslavercFile);
-                DataInputStream dis = new DataInputStream(fis);
-                BufferedReader br = new BufferedReader(new 
InputStreamReader(dis));
+            try (BufferedReader br = 
Files.newBufferedReader(kioslavercFile.toPath())) {
                 String line;
                 boolean inGroup = false;
                 while ((line = br.readLine()) != null) {
@@ -153,11 +149,8 @@ public class KdeNetworkProxy implements 
NetworkProxyResolver {
                         inGroup = true;
                     }
                 }
-                dis.close();
-            } catch (FileNotFoundException fnfe) {
-                LOGGER.log(Level.SEVERE, "Cannot read file: ", fnfe);
-            } catch (IOException ioe) {
-                LOGGER.log(Level.SEVERE, "Cannot read file: ", ioe);
+            } catch (IOException | InvalidPathException ex) {
+                LOGGER.log(Level.SEVERE, "Cannot read file: ", ex);
             }
         } else {
             LOGGER.log(Level.WARNING, "KDE system proxy resolver: The 
kioslaverc file not found ({0})", KIOSLAVERC_PATH);
diff --git a/core.osgi/nbproject/project.properties 
b/core.osgi/nbproject/project.properties
index 0624d2c..0fd506d 100644
--- a/core.osgi/nbproject/project.properties
+++ b/core.osgi/nbproject/project.properties
@@ -15,7 +15,7 @@
 # specific language governing permissions and limitations
 # under the License.
 is.autoload=true
-javac.source=1.6
+javac.source=1.7
 javac.compilerargs=-Xlint -Xlint:-serial
 cp.extra=\
     ${nb_all}/libs.osgi/external/osgi.core-5.0.0.jar:\
diff --git a/core.osgi/src/org/netbeans/core/osgi/OSGiInstalledFileLocator.java 
b/core.osgi/src/org/netbeans/core/osgi/OSGiInstalledFileLocator.java
index f25b1e1..bfc9a96 100644
--- a/core.osgi/src/org/netbeans/core/osgi/OSGiInstalledFileLocator.java
+++ b/core.osgi/src/org/netbeans/core/osgi/OSGiInstalledFileLocator.java
@@ -20,12 +20,13 @@
 package org.netbeans.core.osgi;
 
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.URI;
 import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.Iterator;
@@ -122,27 +123,20 @@ class OSGiInstalledFileLocator extends 
InstalledFileLocator {
                         if (!dir.isDirectory() && !dir.mkdirs()) {
                             throw new IOException("Could not make " + dir);
                         }
-                        InputStream is = resource.openStream();
-                        try {
-                            OutputStream os = new FileOutputStream(f2);
-                            try {
-                                byte[] buf = new byte[4096];
-                                int read;
-                                while ((read = is.read(buf)) != -1) {
-                                    os.write(buf, 0, read);
-                                }
-                            } finally {
-                                os.close();
+                        try (InputStream is = resource.openStream();
+                                OutputStream os = 
Files.newOutputStream(f2.toPath())) {
+                            byte[] buf = new byte[4096];
+                            int read;
+                            while ((read = is.read(buf)) != -1) {
+                                os.write(buf, 0, read);
                             }
-                        } finally {
-                            is.close();
                         }
                         if (execFiles.contains(name)) {
                             f2.setExecutable(true);
                         }
                     }
                     return f;
-                } catch (IOException x) {
+                } catch (IOException | InvalidPathException x) {
                     Exceptions.printStackTrace(x);
                 }
             }
diff --git a/core.output2/nbproject/project.properties 
b/core.output2/nbproject/project.properties
index 25c2885..5db5e5d 100644
--- a/core.output2/nbproject/project.properties
+++ b/core.output2/nbproject/project.properties
@@ -17,7 +17,7 @@
 
 is.autoload=true
 javac.compilerargs=-Xlint -Xlint:-serial
-javac.source=1.6
+javac.source=1.7
 javadoc.arch=${basedir}/arch.xml
 
 test.config.stableBTD.includes=**/*Test.class
diff --git a/core.output2/src/org/netbeans/core/output2/AbstractLines.java 
b/core.output2/src/org/netbeans/core/output2/AbstractLines.java
index 44b2d4c..2189ff5 100644
--- a/core.output2/src/org/netbeans/core/output2/AbstractLines.java
+++ b/core.output2/src/org/netbeans/core/output2/AbstractLines.java
@@ -22,13 +22,15 @@ package org.netbeans.core.output2;
 import java.awt.Color;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.nio.CharBuffer;
 import java.nio.channels.FileChannel;
 import java.nio.charset.Charset;
 import java.nio.charset.CharsetEncoder;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -869,7 +871,6 @@ abstract class AbstractLines implements Lines, Runnable, 
ActionListener {
         if (storage == null) {
             throw new IOException ("Data has already been disposed"); //NOI18N
         }
-        FileOutputStream fos = new FileOutputStream(path);
         try {
             String encoding = System.getProperty ("file.encoding"); //NOI18N
             if (encoding == null) {
@@ -878,30 +879,30 @@ abstract class AbstractLines implements Lines, Runnable, 
ActionListener {
             Charset charset = Charset.forName (encoding); //NOI18N
             CharsetEncoder encoder = charset.newEncoder ();
             String ls = System.getProperty("line.separator");
-            FileChannel ch = fos.getChannel();
-            ByteBuffer lsbb = encoder.encode(CharBuffer.wrap(ls));
-            for (int i = 0; i < getLineCount(); i++) {
-                int lineStart = getCharLineStart(i);
-                int lineLength = length(i);
-                BufferResource<CharBuffer> br = getCharBuffer(lineStart,
-                        lineLength);
-                try {
-                    CharBuffer cb = br.getBuffer();
-                    ByteBuffer bb = encoder.encode(cb);
-                    ch.write(bb);
-                    if (i != getLineCount() - 1) {
-                        lsbb.rewind();
-                        ch.write(lsbb);
-                    }
-                } finally {
-                    if (br != null) {
-                        br.releaseBuffer();
+            Path filePath = Paths.get(path);
+            try (FileChannel ch = FileChannel.open(filePath, 
StandardOpenOption.WRITE, StandardOpenOption.CREATE)) {
+                ByteBuffer lsbb = encoder.encode(CharBuffer.wrap(ls));
+                for (int i = 0; i < getLineCount(); i++) {
+                    int lineStart = getCharLineStart(i);
+                    int lineLength = length(i);
+                    BufferResource<CharBuffer> br = getCharBuffer(lineStart,
+                            lineLength);
+                    try {
+                        CharBuffer cb = br.getBuffer();
+                        ByteBuffer bb = encoder.encode(cb);
+                        ch.write(bb);
+                        if (i != getLineCount() - 1) {
+                            lsbb.rewind();
+                            ch.write(lsbb);
+                        }
+                    } finally {
+                        if (br != null) {
+                            br.releaseBuffer();
+                        }
                     }
                 }
             }
-            ch.close();
         } finally {
-            fos.close();
             FileUtil.refreshFor(new java.io.File(path));
         }
     }
diff --git a/core.output2/src/org/netbeans/core/output2/Controller.java 
b/core.output2/src/org/netbeans/core/output2/Controller.java
index 56982b9..806fae9 100644
--- a/core.output2/src/org/netbeans/core/output2/Controller.java
+++ b/core.output2/src/org/netbeans/core/output2/Controller.java
@@ -23,10 +23,10 @@ import java.awt.Container;
 import java.awt.Font;
 import java.io.CharConversionException;
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.lang.ref.WeakReference;
+import java.nio.file.Files;
 import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
@@ -525,7 +525,7 @@ public class Controller {
                         f.delete();
                     }
                     f.createNewFile();
-                    logStream = new FileOutputStream(f);
+                    logStream = Files.newOutputStream(f.toPath());
                 } catch (Exception e) {
                     e.printStackTrace();
                     logStream = System.err;
diff --git a/core.startup.base/nbproject/project.properties 
b/core.startup.base/nbproject/project.properties
index 2bda232..6cea6af 100644
--- a/core.startup.base/nbproject/project.properties
+++ b/core.startup.base/nbproject/project.properties
@@ -14,7 +14,7 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
-javac.source=1.6
+javac.source=1.7
 javac.compilerargs=-Xlint -Xlint:-serial
 spec.version.base=1.63.0
 module.jar.dir=core
diff --git 
a/core.startup.base/src/org/netbeans/core/startup/layers/ArchiveURLMapper.java 
b/core.startup.base/src/org/netbeans/core/startup/layers/ArchiveURLMapper.java
index 0fbceb5..bc308ce 100644
--- 
a/core.startup.base/src/org/netbeans/core/startup/layers/ArchiveURLMapper.java
+++ 
b/core.startup.base/src/org/netbeans/core/startup/layers/ArchiveURLMapper.java
@@ -20,7 +20,6 @@
 package org.netbeans.core.startup.layers;
 
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -30,6 +29,8 @@ import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLDecoder;
+import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
@@ -241,16 +242,10 @@ public class ArchiveURLMapper extends URLMapper {
                     copy = copy.getCanonicalFile();
                     copy.deleteOnExit();
                 }
-                InputStream is = fo.getInputStream();
-                try {
-                    OutputStream os = new FileOutputStream(copy);
-                    try {
-                        FileUtil.copy(is, os);
-                    } finally {
-                        os.close();
-                    }
-                } finally {
-                    is.close();
+                try (InputStream is = fo.getInputStream(); OutputStream os = 
Files.newOutputStream(copy.toPath())) {
+                    FileUtil.copy(is, os);
+                } catch (InvalidPathException ex) {
+                    throw new IOException(ex);
                 }
                 copiedJARs.put(archiveFileURI, copy);
             }
diff --git 
a/core.startup.base/src/org/netbeans/core/startup/layers/NbinstURLStreamHandler.java
 
b/core.startup.base/src/org/netbeans/core/startup/layers/NbinstURLStreamHandler.java
index a697cbf..db3899b 100644
--- 
a/core.startup.base/src/org/netbeans/core/startup/layers/NbinstURLStreamHandler.java
+++ 
b/core.startup.base/src/org/netbeans/core/startup/layers/NbinstURLStreamHandler.java
@@ -20,7 +20,6 @@
 package org.netbeans.core.startup.layers;
 
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
@@ -29,6 +28,8 @@ import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLStreamHandler;
 import java.net.UnknownServiceException;
+import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
 import org.openide.filesystems.FileObject;
 import org.openide.filesystems.FileUtil;
 import org.openide.util.Exceptions;
@@ -140,7 +141,11 @@ public class NbinstURLStreamHandler extends 
URLStreamHandler {
         public InputStream getInputStream() throws IOException {
             this.connect();
             if (iStream == null) {
-                iStream = new FileInputStream(f);
+                try {
+                    iStream = Files.newInputStream(f.toPath());
+                } catch (InvalidPathException ex) {
+                    throw new IOException(ex);
+                }
             }
             return iStream;
         }
diff --git 
a/core.startup.base/test/unit/src/org/netbeans/core/startup/layers/SystemFileSystemTest.java
 
b/core.startup.base/test/unit/src/org/netbeans/core/startup/layers/SystemFileSystemTest.java
index e5b6f1f..0274f3b 100644
--- 
a/core.startup.base/test/unit/src/org/netbeans/core/startup/layers/SystemFileSystemTest.java
+++ 
b/core.startup.base/test/unit/src/org/netbeans/core/startup/layers/SystemFileSystemTest.java
@@ -34,7 +34,6 @@ import org.netbeans.ModuleManager;
 import org.netbeans.core.startup.Main;
 import org.netbeans.core.startup.MainLookup;
 import org.netbeans.SetupHid;
-import org.netbeans.core.startup.layers.SystemFileSystem;
 import org.openide.filesystems.FileAttributeEvent;
 import org.openide.filesystems.FileChangeListener;
 import org.openide.filesystems.FileEvent;
@@ -236,17 +235,18 @@ implements 
InstanceContent.Convertor<FileSystem,FileSystem>, FileChangeListener
     }
     
     private static void write(FileObject fo, String txt) throws IOException {
-        OutputStream os = fo.getOutputStream();
-        os.write(txt.getBytes());
-        os.close();
+        try (OutputStream os = fo.getOutputStream()) {
+            os.write(txt.getBytes());
+        }
     }
     
     private static String read(FileObject fo) throws IOException {
         byte[] arr = new byte[(int)fo.getSize()];
-        InputStream is = fo.getInputStream();
-        int len = is.read(arr);
-        assertEquals("Not enough read", arr.length, len);
-        return new String(arr);
+        try (InputStream is = fo.getInputStream()) {
+            int len = is.read(arr);
+            assertEquals("Not enough read", arr.length, len);
+            return new String(arr);
+        }
     }
 
     public FileSystem convert(FileSystem obj) {
diff --git 
a/core.startup/src/org/netbeans/core/startup/logging/MessagesHandler.java 
b/core.startup/src/org/netbeans/core/startup/logging/MessagesHandler.java
index 6cc31e7..5f59e9a 100644
--- a/core.startup/src/org/netbeans/core/startup/logging/MessagesHandler.java
+++ b/core.startup/src/org/netbeans/core/startup/logging/MessagesHandler.java
@@ -19,8 +19,9 @@
 package org.netbeans.core.startup.logging;
 
 import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
 import java.util.Arrays;
 import java.util.Objects;
 import java.util.logging.Level;
@@ -84,8 +85,8 @@ final class MessagesHandler extends StreamHandler {
     
     private void initStream() {
         try {
-            setOutputStream(new FileOutputStream(files[0], false));
-        } catch (FileNotFoundException ex) {
+            setOutputStream(Files.newOutputStream(files[0].toPath()));
+        } catch (IOException | InvalidPathException ex) {
             setOutputStream(System.err);
         }
     }
diff --git a/core.startup/src/org/netbeans/core/startup/logging/NbLogging.java 
b/core.startup/src/org/netbeans/core/startup/logging/NbLogging.java
index 198a900..3a50fe3 100644
--- a/core.startup/src/org/netbeans/core/startup/logging/NbLogging.java
+++ b/core.startup/src/org/netbeans/core/startup/logging/NbLogging.java
@@ -18,10 +18,14 @@
  */
 package org.netbeans.core.startup.logging;
 
+import static java.nio.file.StandardOpenOption.APPEND;
+import static java.nio.file.StandardOpenOption.CREATE;
+
 import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
+import java.io.IOException;
 import java.io.PrintStream;
+import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
 import java.util.logging.Handler;
 import java.util.regex.Pattern;
 import java.util.regex.PatternSyntaxException;
@@ -43,8 +47,8 @@ public final class NbLogging {
             try {
                 File debugLog = new File(System.getProperty("java.io.tmpdir"), 
"TopLogging.log"); // NOI18N
                 System.err.println("Logging sent to: " + debugLog); // NOI18N
-                _D = new PrintStream(new FileOutputStream(debugLog), true);
-            } catch (FileNotFoundException x) {
+                _D = new PrintStream(Files.newOutputStream(debugLog.toPath(), 
CREATE, APPEND));
+            } catch (IOException | InvalidPathException x) {
                 x.printStackTrace();
             }
         }
diff --git a/o.n.bootstrap/src/org/netbeans/JarClassLoader.java 
b/o.n.bootstrap/src/org/netbeans/JarClassLoader.java
index 5268c7c..b1cdcc8 100644
--- a/o.n.bootstrap/src/org/netbeans/JarClassLoader.java
+++ b/o.n.bootstrap/src/org/netbeans/JarClassLoader.java
@@ -21,9 +21,7 @@ package org.netbeans;
 
 import java.io.ByteArrayInputStream;
 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;
@@ -38,6 +36,8 @@ import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLStreamHandler;
+import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
 import java.security.CodeSource;
 import java.security.PermissionCollection;
 import java.security.Policy;
@@ -701,22 +701,17 @@ public class JarClassLoader extends ProxyClassLoader {
             File temp = File.createTempFile(prefix, suffix);
             temp.deleteOnExit();
 
-            InputStream is = new FileInputStream(orig);
-            try {
-                OutputStream os = new FileOutputStream(temp);
-                try {
-                    byte[] buf = new byte[4096];
-                    int j;
-                    while ((j = is.read(buf)) != -1) {
-                        os.write(buf, 0, j);
-                    }
-                } finally {
-                    os.close();
+            try (InputStream is = Files.newInputStream(orig.toPath());
+                    OutputStream os = Files.newOutputStream(temp.toPath())) {
+                byte[] buf = new byte[4096];
+                int j;
+                while ((j = is.read(buf)) != -1) {
+                    os.write(buf, 0, j);
                 }
-            } finally {
-                is.close();
+            } catch (InvalidPathException ex) {
+                throw new IOException(ex);
             }
- 
+
             doCloseJar();
             file = temp;
             dead = true;
@@ -864,9 +859,9 @@ public class JarClassLoader extends ProxyClassLoader {
             File maniF = new File(new File(dir, "META-INF"), "MANIFEST.MF");
             mf = new Manifest();
             if (maniF.canRead()) {
-                try (InputStream istm = new FileInputStream(maniF)) {
+                try (InputStream istm = Files.newInputStream(maniF.toPath())) {
                     mf.read(istm);
-                } catch (IOException ex) {
+                } catch (IOException | InvalidPathException ex) {
                     Exceptions.printStackTrace(ex);
                 }
             }
@@ -888,15 +883,14 @@ public class JarClassLoader extends ProxyClassLoader {
             
             int len = (int)clsFile.length();
             byte[] data = new byte[len];
-            InputStream is = new FileInputStream(clsFile);
-            try {
+            try (InputStream is = Files.newInputStream(clsFile.toPath())) {
                 int count = 0;
                 while (count < len) {
                     count += is.read(data, count, len - count);
                 }
                 return data;
-            } finally {
-                is.close();
+            } catch (InvalidPathException ex) {
+                throw new IOException(ex);
             }
         }
         
diff --git a/o.n.bootstrap/src/org/netbeans/Stamps.java 
b/o.n.bootstrap/src/org/netbeans/Stamps.java
index 7777f1d..e41c908 100644
--- a/o.n.bootstrap/src/org/netbeans/Stamps.java
+++ b/o.n.bootstrap/src/org/netbeans/Stamps.java
@@ -26,9 +26,6 @@ import java.io.DataInputStream;
 import java.io.DataOutput;
 import java.io.DataOutputStream;
 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;
@@ -36,6 +33,10 @@ import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
 import java.nio.MappedByteBuffer;
 import java.nio.channels.FileChannel;
+import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
+import java.nio.file.NoSuchFileException;
+import java.nio.file.StandardOpenOption;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -185,8 +186,7 @@ public final class Stamps {
             return null;
         }
         
-        try {
-            FileChannel fc = new FileInputStream(cacheFile).getChannel();
+        try (FileChannel fc = FileChannel.open(cacheFile.toPath(), 
StandardOpenOption.READ)){
             ByteBuffer master;
             if (mmap) {
                 master = fc.map(FileChannel.MapMode.READ_ONLY, 0, len[0]);
@@ -201,10 +201,8 @@ public final class Stamps {
                 master.flip();
             }
 
-            fc.close();
-            
             return master;
-        } catch (IOException ex) {
+        } catch (IOException | InvalidPathException ex) {
             LOG.log(Level.WARNING, "Cannot read cache " + cacheFile, ex); // 
NOI18N
             return null;
         }
@@ -429,31 +427,25 @@ public final class Stamps {
         try {
             byte[] expected = content.getBytes("UTF-8"); // NOI18N
             byte[] read = new byte[expected.length];
-            FileInputStream is = null;
             boolean areCachesOK;
             boolean writeFile;
             long lastMod;
-            try {
-                is = new FileInputStream(file);
+            try (InputStream is = Files.newInputStream(file.toPath())) {
                 int len = is.read(read);
                 areCachesOK = len == read.length && is.available() == 0 && 
Arrays.equals(expected, read);
                 writeFile = !areCachesOK;
                 lastMod = file.lastModified();
-            } catch (FileNotFoundException notFoundEx) {
+            } catch (NoSuchFileException notFoundEx) {
                 // ok, running for the first time, no need to invalidate the 
cache
                 areCachesOK = true;
                 writeFile = true;
                 lastMod = result.get();
-            } finally {
-                if (is != null) {
-                    is.close();
-                }
             }
             if (writeFile) {
                 file.getParentFile().mkdirs();
-                FileOutputStream os = new FileOutputStream(file);
-                os.write(expected);
-                os.close();
+                try (OutputStream os = Files.newOutputStream(file.toPath())) {
+                    os.write(expected);
+                }
                 if (areCachesOK) {
                     file.setLastModified(lastMod);
                 }
@@ -463,7 +455,7 @@ public final class Stamps {
                 }
             }
             return areCachesOK;
-        } catch (IOException ex) {
+        } catch (IOException | InvalidPathException ex) {
             ex.printStackTrace();
             return false;
         }
@@ -552,7 +544,6 @@ public final class Stamps {
             return;
         }
         ZipInputStream zip = null;
-        FileOutputStream os = null;
         try {
             byte[] arr = new byte[4096];
             LOG.log(Level.FINE, "Found populate.zip about to extract it into 
{0}", cache);
@@ -567,18 +558,18 @@ public final class Stamps {
                 }
                 File f = new File(cache, en.getName().replace('/', 
File.separatorChar));
                 f.getParentFile().mkdirs();
-                os = new FileOutputStream(f);
-                for (;;) {
-                    int len = zip.read(arr);
-                    if (len == -1) {
-                        break;
+                try (OutputStream os = Files.newOutputStream(f.toPath())) {
+                    for (;;) {
+                        int len = zip.read(arr);
+                        if (len == -1) {
+                            break;
+                        }
+                        os.write(arr, 0, len);
                     }
-                    os.write(arr, 0, len);
                 }
-                os.close();
             }
             zip.close();
-        } catch (IOException ex) {
+        } catch (IOException | InvalidPathException ex) {
             LOG.log(Level.INFO, "Failed to populate {0}", cache);
         }
     }
@@ -591,22 +582,12 @@ public final class Stamps {
         final String clustersCache = "all-clusters.dat"; // NOI18N
         File f = fileImpl(clustersCache, null, -1); // no timestamp check
         if (f != null) {
-            DataInputStream dis = null;
-            try {
-                dis = new DataInputStream(new FileInputStream(f));
+            try (DataInputStream dis = new 
DataInputStream(Files.newInputStream(f.toPath()))) {
                 if (Clusters.compareDirs(dis)) {
                     return false;
                 }
-            } catch (IOException ex) {
+            } catch (IOException | InvalidPathException ex) {
                 return clustersChanged = true;
-            } finally {
-                if (dis != null) {
-                    try {
-                        dis.close();
-                    } catch (IOException ex) {
-                        LOG.log(Level.INFO, null, ex);
-                    }
-                }
             }
         } else {
             // missing cluster file signals caches are OK, for 
@@ -700,7 +681,8 @@ public final class Stamps {
                 cacheFile.getParentFile().mkdirs();
 
                 LOG.log(Level.FINE, "Storing cache {0}", cacheFile);
-                os = new FileOutputStream(cacheFile, append); //append new 
entries only
+                //append new entries only
+                os = Files.newOutputStream(cacheFile.toPath(), 
StandardOpenOption.CREATE, StandardOpenOption.APPEND);
                 DataOutputStream dos = new DataOutputStream(new 
BufferedOutputStream(this, 1024 * 1024));
                 
                 this.delay = delay;
@@ -708,7 +690,7 @@ public final class Stamps {
                 updater.flushCaches(dos);
                 dos.close();
                 LOG.log(Level.FINE, "Done Storing cache {0}", cacheFile);
-            } catch (IOException ex) {
+            } catch (IOException | InvalidPathException ex) {
                 LOG.log(Level.WARNING, "Error saving cache {0}", cacheFile);
                 LOG.log(Level.INFO, ex.getMessage(), ex); // NOI18N
                 delete = true;
diff --git a/o.n.bootstrap/src/org/netbeans/Util.java 
b/o.n.bootstrap/src/org/netbeans/Util.java
index 1647aef..e2b03a7 100644
--- a/o.n.bootstrap/src/org/netbeans/Util.java
+++ b/o.n.bootstrap/src/org/netbeans/Util.java
@@ -20,6 +20,8 @@
 package org.netbeans;
 
 import java.io.*;
+import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
 import java.util.*;
 import java.util.ArrayList;
 import java.util.logging.Level;
@@ -59,20 +61,15 @@ public final class Util {
         String suffix = "-test.jar"; // NOI18N
         File physicalModuleFile = File.createTempFile(prefix, suffix);
         physicalModuleFile.deleteOnExit();
-        InputStream is = new FileInputStream(moduleFile);
-        try {
-            OutputStream os = new FileOutputStream(physicalModuleFile);
-            try {
-                byte[] buf = new byte[4096];
-                int i;
-                while ((i = is.read(buf)) != -1) {
-                    os.write(buf, 0, i);
-                }
-            } finally {
-                os.close();
-            }
-        } finally {
-            is.close();
+        try (InputStream is = Files.newInputStream(moduleFile.toPath());
+                OutputStream os = 
Files.newOutputStream(physicalModuleFile.toPath())) {
+            byte[] buf = new byte[4096];
+            int i;
+            while ((i = is.read(buf)) != -1) {
+                os.write(buf, 0, i);
+            }
+        } catch (InvalidPathException ex) {
+            throw new IOException(ex);
         }
         err.fine("Made " + physicalModuleFile);
         return physicalModuleFile;
diff --git a/openide.filesystems/src/org/openide/filesystems/JarFileSystem.java 
b/openide.filesystems/src/org/openide/filesystems/JarFileSystem.java
index 45fcead..df16819 100644
--- a/openide.filesystems/src/org/openide/filesystems/JarFileSystem.java
+++ b/openide.filesystems/src/org/openide/filesystems/JarFileSystem.java
@@ -23,9 +23,7 @@ import java.beans.PropertyVetoException;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 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.ObjectInputStream;
@@ -35,6 +33,8 @@ import java.lang.management.ManagementFactory;
 import java.lang.ref.Reference;
 import java.lang.ref.SoftReference;
 import java.lang.ref.WeakReference;
+import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
@@ -503,24 +503,16 @@ public class JarFileSystem extends AbstractFileSystem {
         if (createContent || forceRecreate) {
             // JDK 1.3 contains bug #4336753
             //is = j.getInputStream (je);
-            InputStream is = getInputStream4336753(jf, je);
-
-            try {
-                OutputStream os = new FileOutputStream(f);
-
-                try {
-                    FileUtil.copy(is, os);
-                } finally {
-                    os.close();
-                }
-            } finally {
-                is.close();
+            try (InputStream is = getInputStream4336753(jf, je); OutputStream 
os = Files.newOutputStream(f.toPath())) {
+                FileUtil.copy(is, os);
+            } catch (InvalidPathException ex) {
+                throw new IOException(ex);
             }
         }
 
         f.deleteOnExit();
 
-        return new FileInputStream(f);
+        return Files.newInputStream(f.toPath());
     }
 
     private static String temporaryName(String filePath, String entryPath) {
diff --git 
a/openide.filesystems/src/org/openide/filesystems/LocalFileSystem.java 
b/openide.filesystems/src/org/openide/filesystems/LocalFileSystem.java
index b41e618..7266cbf 100644
--- a/openide.filesystems/src/org/openide/filesystems/LocalFileSystem.java
+++ b/openide.filesystems/src/org/openide/filesystems/LocalFileSystem.java
@@ -33,6 +33,7 @@ import java.io.ObjectInputValidation;
 import java.io.OutputStream;
 import java.io.SyncFailedException;
 import java.nio.file.Files;
+import java.nio.file.InvalidPathException;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Random;
@@ -401,13 +402,16 @@ public class LocalFileSystem extends AbstractFileSystem {
         File file = null;
 
         try {
-            fis = new BufferedInputStream(new FileInputStream(file = 
getFile(name)));
-        } catch (FileNotFoundException exc) {
+            file = getFile(name);
+            fis = new BufferedInputStream(Files.newInputStream(file.toPath()));
+        } catch (IOException | InvalidPathException exc) {
+            FileNotFoundException fnfException = new 
FileNotFoundException(exc.getMessage());
             if ((file == null) || !file.exists()) {
-                ExternalUtil.annotate(exc, 
NbBundle.getMessage(LocalFileSystem.class, "EXC_FileOutsideModified", 
getFile(name)));
+                ExternalUtil.annotate(fnfException,
+                        NbBundle.getMessage(LocalFileSystem.class, 
"EXC_FileOutsideModified", getFile(name)));
             }
 
-            throw exc;
+            throw fnfException;
         }
 
         return fis;
@@ -418,14 +422,17 @@ public class LocalFileSystem extends AbstractFileSystem {
         if (!f.exists()) {
             f.getParentFile().mkdirs();
         }
-        OutputStream retVal = new BufferedOutputStream(new 
FileOutputStream(f));
+        try {
+            OutputStream retVal = new 
BufferedOutputStream(Files.newOutputStream(f.toPath()));
 
-        // workaround for #42624
-        if (BaseUtilities.isMac()) {
-            retVal = getOutputStreamForMac42624(retVal, name);
+            // workaround for #42624
+            if (BaseUtilities.isMac()) {
+                retVal = getOutputStreamForMac42624(retVal, name);
+            }
+            return retVal;
+        } catch (InvalidPathException ex) {
+            throw new IOException(ex);
         }
-
-        return retVal;
     }
 
     private OutputStream getOutputStreamForMac42624(final OutputStream 
originalStream, final String name) {

-- 
To stop receiving notification emails like this one, please contact
"[email protected]" <[email protected]>.

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to