You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by ma...@apache.org on 2018/11/11 14:46:14 UTC

[incubator-netbeans] 02/03: [NETBEANS-1658] Revert "Move to Files.new* creation of I/O streams during IDE boot"

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 80ad48bbf215618dfe8a7f48b29e5965cd1b2a05
Author: Matthias Bläsing <mb...@doppel-helix.eu>
AuthorDate: Thu Nov 1 22:35:58 2018 +0100

    [NETBEANS-1658] Revert "Move to Files.new* creation of I/O streams during IDE boot"
    
    This reverts commit 4b82e6adb31e294c74fd2fa99779ce9e27ae6184
---
 platform/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 ++++--
 platform/core.osgi/nbproject/project.properties    |  2 +-
 .../core/osgi/OSGiInstalledFileLocator.java        | 24 +++++---
 platform/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 ++--
 .../src/org/netbeans/JarClassLoader.java           | 38 +++++++-----
 .../o.n.bootstrap/src/org/netbeans/Stamps.java     | 68 ++++++++++++++--------
 platform/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, 198 insertions(+), 165 deletions(-)

diff --git a/platform/core.netigso/nbproject/project.properties b/platform/core.netigso/nbproject/project.properties
index d593729..f00a000 100644
--- a/platform/core.netigso/nbproject/project.properties
+++ b/platform/core.netigso/nbproject/project.properties
@@ -16,7 +16,7 @@
 # under the License.
 
 is.autoload=true
-javac.source=1.7
+javac.source=1.6
 javac.compilerargs=-Xlint -Xlint:-serial
 javadoc.arch=${basedir}/arch.xml
 javadoc.apichanges=${basedir}/apichanges.xml
diff --git a/platform/core.netigso/src/org/netbeans/core/netigso/Netigso.java b/platform/core.netigso/src/org/netbeans/core/netigso/Netigso.java
index 6efa82c..daab74e 100644
--- a/platform/core.netigso/src/org/netbeans/core/netigso/Netigso.java
+++ b/platform/core.netigso/src/org/netbeans/core/netigso/Netigso.java
@@ -22,11 +22,10 @@ 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;
@@ -37,6 +36,7 @@ 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;
@@ -468,11 +468,9 @@ implements Cloneable, Stamps.Updater {
             } else if (symbolicName != null) { // NOI18N
                 if (original != null) {
                     LOG.log(Level.FINE, "Updating bundle {0}", original.getLocation());
-                    try (InputStream is = Files.newInputStream(m.getJarFile().toPath())) {
-                        original.update(is);
-                    } catch (InvalidPathException ex) {
-                        throw new IOException(ex);
-                    }
+                    FileInputStream is = new FileInputStream(m.getJarFile());
+                    original.update(is);
+                    is.close();
                     b = original;
                 } else {
                     BundleContext bc = framework.getBundleContext();
diff --git a/platform/core.network/src/org/netbeans/core/network/proxy/NbProxySelector.java b/platform/core.network/src/org/netbeans/core/network/proxy/NbProxySelector.java
index 440ff50..394c39a 100644
--- a/platform/core.network/src/org/netbeans/core/network/proxy/NbProxySelector.java
+++ b/platform/core.network/src/org/netbeans/core/network/proxy/NbProxySelector.java
@@ -21,11 +21,10 @@ 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;
@@ -422,9 +421,10 @@ public final class NbProxySelector extends ProxySelector {
                 }
 
                 fname = netProperties.getCanonicalPath();
-                try (InputStream bin = new BufferedInputStream(Files.newInputStream(Paths.get(fname)))) {
-                    props.load(bin);
-                }
+                InputStream in = new FileInputStream(fname);
+                BufferedInputStream bin = new BufferedInputStream(in);
+                props.load(bin);
+                bin.close();
 
                 String val = props.getProperty(propertyKey);
                 val = System.getProperty(propertyKey, val);
diff --git a/platform/core.network/src/org/netbeans/core/network/proxy/kde/KdeNetworkProxy.java b/platform/core.network/src/org/netbeans/core/network/proxy/kde/KdeNetworkProxy.java
index 505fb9a..553d1e5 100644
--- a/platform/core.network/src/org/netbeans/core/network/proxy/kde/KdeNetworkProxy.java
+++ b/platform/core.network/src/org/netbeans/core/network/proxy/kde/KdeNetworkProxy.java
@@ -19,11 +19,12 @@
 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.nio.file.Files;
-import java.nio.file.InvalidPathException;
+import java.io.InputStreamReader;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.logging.Level;
@@ -132,7 +133,10 @@ public class KdeNetworkProxy implements NetworkProxyResolver {
         Map<String, String> map = new HashMap<String, String>();
 
         if (kioslavercFile.exists()) {
-            try (BufferedReader br = Files.newBufferedReader(kioslavercFile.toPath())) {
+            try {
+                FileInputStream fis = new FileInputStream(kioslavercFile);
+                DataInputStream dis = new DataInputStream(fis);
+                BufferedReader br = new BufferedReader(new InputStreamReader(dis));
                 String line;
                 boolean inGroup = false;
                 while ((line = br.readLine()) != null) {
@@ -149,8 +153,11 @@ public class KdeNetworkProxy implements NetworkProxyResolver {
                         inGroup = true;
                     }
                 }
-            } catch (IOException | InvalidPathException ex) {
-                LOGGER.log(Level.SEVERE, "Cannot read file: ", ex);
+                dis.close();
+            } catch (FileNotFoundException fnfe) {
+                LOGGER.log(Level.SEVERE, "Cannot read file: ", fnfe);
+            } catch (IOException ioe) {
+                LOGGER.log(Level.SEVERE, "Cannot read file: ", ioe);
             }
         } else {
             LOGGER.log(Level.WARNING, "KDE system proxy resolver: The kioslaverc file not found ({0})", KIOSLAVERC_PATH);
diff --git a/platform/core.osgi/nbproject/project.properties b/platform/core.osgi/nbproject/project.properties
index f036ef8..f204641 100644
--- a/platform/core.osgi/nbproject/project.properties
+++ b/platform/core.osgi/nbproject/project.properties
@@ -15,7 +15,7 @@
 # specific language governing permissions and limitations
 # under the License.
 is.autoload=true
-javac.source=1.7
+javac.source=1.6
 javac.compilerargs=-Xlint -Xlint:-serial
 cp.extra=\
     ${nb_all}/platform/libs.osgi/external/osgi.core-5.0.0.jar:\
diff --git a/platform/core.osgi/src/org/netbeans/core/osgi/OSGiInstalledFileLocator.java b/platform/core.osgi/src/org/netbeans/core/osgi/OSGiInstalledFileLocator.java
index bfc9a96..f25b1e1 100644
--- a/platform/core.osgi/src/org/netbeans/core/osgi/OSGiInstalledFileLocator.java
+++ b/platform/core.osgi/src/org/netbeans/core/osgi/OSGiInstalledFileLocator.java
@@ -20,13 +20,12 @@
 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;
@@ -123,20 +122,27 @@ class OSGiInstalledFileLocator extends InstalledFileLocator {
                         if (!dir.isDirectory() && !dir.mkdirs()) {
                             throw new IOException("Could not make " + dir);
                         }
-                        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);
+                        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();
                             }
+                        } finally {
+                            is.close();
                         }
                         if (execFiles.contains(name)) {
                             f2.setExecutable(true);
                         }
                     }
                     return f;
-                } catch (IOException | InvalidPathException x) {
+                } catch (IOException x) {
                     Exceptions.printStackTrace(x);
                 }
             }
diff --git a/platform/core.output2/nbproject/project.properties b/platform/core.output2/nbproject/project.properties
index 5db5e5d..25c2885 100644
--- a/platform/core.output2/nbproject/project.properties
+++ b/platform/core.output2/nbproject/project.properties
@@ -17,7 +17,7 @@
 
 is.autoload=true
 javac.compilerargs=-Xlint -Xlint:-serial
-javac.source=1.7
+javac.source=1.6
 javadoc.arch=${basedir}/arch.xml
 
 test.config.stableBTD.includes=**/*Test.class
diff --git a/platform/core.output2/src/org/netbeans/core/output2/AbstractLines.java b/platform/core.output2/src/org/netbeans/core/output2/AbstractLines.java
index 2189ff5..44b2d4c 100644
--- a/platform/core.output2/src/org/netbeans/core/output2/AbstractLines.java
+++ b/platform/core.output2/src/org/netbeans/core/output2/AbstractLines.java
@@ -22,15 +22,13 @@ 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;
@@ -871,6 +869,7 @@ 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) {
@@ -879,30 +878,30 @@ abstract class AbstractLines implements Lines, Runnable, ActionListener {
             Charset charset = Charset.forName (encoding); //NOI18N
             CharsetEncoder encoder = charset.newEncoder ();
             String ls = System.getProperty("line.separator");
-            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();
-                        }
+            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();
                     }
                 }
             }
+            ch.close();
         } finally {
+            fos.close();
             FileUtil.refreshFor(new java.io.File(path));
         }
     }
diff --git a/platform/core.output2/src/org/netbeans/core/output2/Controller.java b/platform/core.output2/src/org/netbeans/core/output2/Controller.java
index 806fae9..56982b9 100644
--- a/platform/core.output2/src/org/netbeans/core/output2/Controller.java
+++ b/platform/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 = Files.newOutputStream(f.toPath());
+                    logStream = new FileOutputStream(f);
                 } catch (Exception e) {
                     e.printStackTrace();
                     logStream = System.err;
diff --git a/platform/core.startup.base/nbproject/project.properties b/platform/core.startup.base/nbproject/project.properties
index 39c6644..5d1a256 100644
--- a/platform/core.startup.base/nbproject/project.properties
+++ b/platform/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.7
+javac.source=1.6
 javac.compilerargs=-Xlint -Xlint:-serial
 spec.version.base=1.66.0
 module.jar.dir=core
diff --git a/platform/core.startup.base/src/org/netbeans/core/startup/layers/ArchiveURLMapper.java b/platform/core.startup.base/src/org/netbeans/core/startup/layers/ArchiveURLMapper.java
index bc308ce..0fbceb5 100644
--- a/platform/core.startup.base/src/org/netbeans/core/startup/layers/ArchiveURLMapper.java
+++ b/platform/core.startup.base/src/org/netbeans/core/startup/layers/ArchiveURLMapper.java
@@ -20,6 +20,7 @@
 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;
@@ -29,8 +30,6 @@ 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;
@@ -242,10 +241,16 @@ public class ArchiveURLMapper extends URLMapper {
                     copy = copy.getCanonicalFile();
                     copy.deleteOnExit();
                 }
-                try (InputStream is = fo.getInputStream(); OutputStream os = Files.newOutputStream(copy.toPath())) {
-                    FileUtil.copy(is, os);
-                } catch (InvalidPathException ex) {
-                    throw new IOException(ex);
+                InputStream is = fo.getInputStream();
+                try {
+                    OutputStream os = new FileOutputStream(copy);
+                    try {
+                        FileUtil.copy(is, os);
+                    } finally {
+                        os.close();
+                    }
+                } finally {
+                    is.close();
                 }
                 copiedJARs.put(archiveFileURI, copy);
             }
diff --git a/platform/core.startup.base/src/org/netbeans/core/startup/layers/NbinstURLStreamHandler.java b/platform/core.startup.base/src/org/netbeans/core/startup/layers/NbinstURLStreamHandler.java
index db3899b..a697cbf 100644
--- a/platform/core.startup.base/src/org/netbeans/core/startup/layers/NbinstURLStreamHandler.java
+++ b/platform/core.startup.base/src/org/netbeans/core/startup/layers/NbinstURLStreamHandler.java
@@ -20,6 +20,7 @@
 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;
@@ -28,8 +29,6 @@ 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;
@@ -141,11 +140,7 @@ public class NbinstURLStreamHandler extends URLStreamHandler {
         public InputStream getInputStream() throws IOException {
             this.connect();
             if (iStream == null) {
-                try {
-                    iStream = Files.newInputStream(f.toPath());
-                } catch (InvalidPathException ex) {
-                    throw new IOException(ex);
-                }
+                iStream = new FileInputStream(f);
             }
             return iStream;
         }
diff --git a/platform/core.startup.base/test/unit/src/org/netbeans/core/startup/layers/SystemFileSystemTest.java b/platform/core.startup.base/test/unit/src/org/netbeans/core/startup/layers/SystemFileSystemTest.java
index 0274f3b..e5b6f1f 100644
--- a/platform/core.startup.base/test/unit/src/org/netbeans/core/startup/layers/SystemFileSystemTest.java
+++ b/platform/core.startup.base/test/unit/src/org/netbeans/core/startup/layers/SystemFileSystemTest.java
@@ -34,6 +34,7 @@ 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;
@@ -235,18 +236,17 @@ implements InstanceContent.Convertor<FileSystem,FileSystem>, FileChangeListener
     }
     
     private static void write(FileObject fo, String txt) throws IOException {
-        try (OutputStream os = fo.getOutputStream()) {
-            os.write(txt.getBytes());
-        }
+        OutputStream os = fo.getOutputStream();
+        os.write(txt.getBytes());
+        os.close();
     }
     
     private static String read(FileObject fo) throws IOException {
         byte[] arr = new byte[(int)fo.getSize()];
-        try (InputStream is = fo.getInputStream()) {
-            int len = is.read(arr);
-            assertEquals("Not enough read", arr.length, len);
-            return new String(arr);
-        }
+        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/platform/core.startup/src/org/netbeans/core/startup/logging/MessagesHandler.java b/platform/core.startup/src/org/netbeans/core/startup/logging/MessagesHandler.java
index 5f59e9a..6cc31e7 100644
--- a/platform/core.startup/src/org/netbeans/core/startup/logging/MessagesHandler.java
+++ b/platform/core.startup/src/org/netbeans/core/startup/logging/MessagesHandler.java
@@ -19,9 +19,8 @@
 package org.netbeans.core.startup.logging;
 
 import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.InvalidPathException;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
 import java.util.Arrays;
 import java.util.Objects;
 import java.util.logging.Level;
@@ -85,8 +84,8 @@ final class MessagesHandler extends StreamHandler {
     
     private void initStream() {
         try {
-            setOutputStream(Files.newOutputStream(files[0].toPath()));
-        } catch (IOException | InvalidPathException ex) {
+            setOutputStream(new FileOutputStream(files[0], false));
+        } catch (FileNotFoundException ex) {
             setOutputStream(System.err);
         }
     }
diff --git a/platform/core.startup/src/org/netbeans/core/startup/logging/NbLogging.java b/platform/core.startup/src/org/netbeans/core/startup/logging/NbLogging.java
index 3a50fe3..198a900 100644
--- a/platform/core.startup/src/org/netbeans/core/startup/logging/NbLogging.java
+++ b/platform/core.startup/src/org/netbeans/core/startup/logging/NbLogging.java
@@ -18,14 +18,10 @@
  */
 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.IOException;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
 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;
@@ -47,8 +43,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(Files.newOutputStream(debugLog.toPath(), CREATE, APPEND));
-            } catch (IOException | InvalidPathException x) {
+                _D = new PrintStream(new FileOutputStream(debugLog), true);
+            } catch (FileNotFoundException x) {
                 x.printStackTrace();
             }
         }
diff --git a/platform/o.n.bootstrap/src/org/netbeans/JarClassLoader.java b/platform/o.n.bootstrap/src/org/netbeans/JarClassLoader.java
index b1cdcc8..5268c7c 100644
--- a/platform/o.n.bootstrap/src/org/netbeans/JarClassLoader.java
+++ b/platform/o.n.bootstrap/src/org/netbeans/JarClassLoader.java
@@ -21,7 +21,9 @@ 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;
@@ -36,8 +38,6 @@ 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,17 +701,22 @@ public class JarClassLoader extends ProxyClassLoader {
             File temp = File.createTempFile(prefix, suffix);
             temp.deleteOnExit();
 
-            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);
+            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();
                 }
-            } catch (InvalidPathException ex) {
-                throw new IOException(ex);
+            } finally {
+                is.close();
             }
-
+ 
             doCloseJar();
             file = temp;
             dead = true;
@@ -859,9 +864,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 = Files.newInputStream(maniF.toPath())) {
+                try (InputStream istm = new FileInputStream(maniF)) {
                     mf.read(istm);
-                } catch (IOException | InvalidPathException ex) {
+                } catch (IOException ex) {
                     Exceptions.printStackTrace(ex);
                 }
             }
@@ -883,14 +888,15 @@ public class JarClassLoader extends ProxyClassLoader {
             
             int len = (int)clsFile.length();
             byte[] data = new byte[len];
-            try (InputStream is = Files.newInputStream(clsFile.toPath())) {
+            InputStream is = new FileInputStream(clsFile);
+            try {
                 int count = 0;
                 while (count < len) {
                     count += is.read(data, count, len - count);
                 }
                 return data;
-            } catch (InvalidPathException ex) {
-                throw new IOException(ex);
+            } finally {
+                is.close();
             }
         }
         
diff --git a/platform/o.n.bootstrap/src/org/netbeans/Stamps.java b/platform/o.n.bootstrap/src/org/netbeans/Stamps.java
index e41c908..7777f1d 100644
--- a/platform/o.n.bootstrap/src/org/netbeans/Stamps.java
+++ b/platform/o.n.bootstrap/src/org/netbeans/Stamps.java
@@ -26,6 +26,9 @@ 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;
@@ -33,10 +36,6 @@ 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;
@@ -186,7 +185,8 @@ public final class Stamps {
             return null;
         }
         
-        try (FileChannel fc = FileChannel.open(cacheFile.toPath(), StandardOpenOption.READ)){
+        try {
+            FileChannel fc = new FileInputStream(cacheFile).getChannel();
             ByteBuffer master;
             if (mmap) {
                 master = fc.map(FileChannel.MapMode.READ_ONLY, 0, len[0]);
@@ -201,8 +201,10 @@ public final class Stamps {
                 master.flip();
             }
 
+            fc.close();
+            
             return master;
-        } catch (IOException | InvalidPathException ex) {
+        } catch (IOException ex) {
             LOG.log(Level.WARNING, "Cannot read cache " + cacheFile, ex); // NOI18N
             return null;
         }
@@ -427,25 +429,31 @@ 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 (InputStream is = Files.newInputStream(file.toPath())) {
+            try {
+                is = new FileInputStream(file);
                 int len = is.read(read);
                 areCachesOK = len == read.length && is.available() == 0 && Arrays.equals(expected, read);
                 writeFile = !areCachesOK;
                 lastMod = file.lastModified();
-            } catch (NoSuchFileException notFoundEx) {
+            } catch (FileNotFoundException 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();
-                try (OutputStream os = Files.newOutputStream(file.toPath())) {
-                    os.write(expected);
-                }
+                FileOutputStream os = new FileOutputStream(file);
+                os.write(expected);
+                os.close();
                 if (areCachesOK) {
                     file.setLastModified(lastMod);
                 }
@@ -455,7 +463,7 @@ public final class Stamps {
                 }
             }
             return areCachesOK;
-        } catch (IOException | InvalidPathException ex) {
+        } catch (IOException ex) {
             ex.printStackTrace();
             return false;
         }
@@ -544,6 +552,7 @@ 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);
@@ -558,18 +567,18 @@ public final class Stamps {
                 }
                 File f = new File(cache, en.getName().replace('/', File.separatorChar));
                 f.getParentFile().mkdirs();
-                try (OutputStream os = Files.newOutputStream(f.toPath())) {
-                    for (;;) {
-                        int len = zip.read(arr);
-                        if (len == -1) {
-                            break;
-                        }
-                        os.write(arr, 0, len);
+                os = new FileOutputStream(f);
+                for (;;) {
+                    int len = zip.read(arr);
+                    if (len == -1) {
+                        break;
                     }
+                    os.write(arr, 0, len);
                 }
+                os.close();
             }
             zip.close();
-        } catch (IOException | InvalidPathException ex) {
+        } catch (IOException ex) {
             LOG.log(Level.INFO, "Failed to populate {0}", cache);
         }
     }
@@ -582,12 +591,22 @@ public final class Stamps {
         final String clustersCache = "all-clusters.dat"; // NOI18N
         File f = fileImpl(clustersCache, null, -1); // no timestamp check
         if (f != null) {
-            try (DataInputStream dis = new DataInputStream(Files.newInputStream(f.toPath()))) {
+            DataInputStream dis = null;
+            try {
+                dis = new DataInputStream(new FileInputStream(f));
                 if (Clusters.compareDirs(dis)) {
                     return false;
                 }
-            } catch (IOException | InvalidPathException ex) {
+            } catch (IOException 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 
@@ -681,8 +700,7 @@ public final class Stamps {
                 cacheFile.getParentFile().mkdirs();
 
                 LOG.log(Level.FINE, "Storing cache {0}", cacheFile);
-                //append new entries only
-                os = Files.newOutputStream(cacheFile.toPath(), StandardOpenOption.CREATE, StandardOpenOption.APPEND);
+                os = new FileOutputStream(cacheFile, append); //append new entries only
                 DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(this, 1024 * 1024));
                 
                 this.delay = delay;
@@ -690,7 +708,7 @@ public final class Stamps {
                 updater.flushCaches(dos);
                 dos.close();
                 LOG.log(Level.FINE, "Done Storing cache {0}", cacheFile);
-            } catch (IOException | InvalidPathException ex) {
+            } catch (IOException ex) {
                 LOG.log(Level.WARNING, "Error saving cache {0}", cacheFile);
                 LOG.log(Level.INFO, ex.getMessage(), ex); // NOI18N
                 delete = true;
diff --git a/platform/o.n.bootstrap/src/org/netbeans/Util.java b/platform/o.n.bootstrap/src/org/netbeans/Util.java
index cfa3e7e..46845fe 100644
--- a/platform/o.n.bootstrap/src/org/netbeans/Util.java
+++ b/platform/o.n.bootstrap/src/org/netbeans/Util.java
@@ -20,8 +20,6 @@
 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;
@@ -61,15 +59,20 @@ public final class Util {
         String suffix = "-test.jar"; // NOI18N
         File physicalModuleFile = File.createTempFile(prefix, suffix);
         physicalModuleFile.deleteOnExit();
-        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);
+        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();
         }
         err.fine("Made " + physicalModuleFile);
         return physicalModuleFile;
diff --git a/platform/openide.filesystems/src/org/openide/filesystems/JarFileSystem.java b/platform/openide.filesystems/src/org/openide/filesystems/JarFileSystem.java
index df16819..45fcead 100644
--- a/platform/openide.filesystems/src/org/openide/filesystems/JarFileSystem.java
+++ b/platform/openide.filesystems/src/org/openide/filesystems/JarFileSystem.java
@@ -23,7 +23,9 @@ 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;
@@ -33,8 +35,6 @@ 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,16 +503,24 @@ public class JarFileSystem extends AbstractFileSystem {
         if (createContent || forceRecreate) {
             // JDK 1.3 contains bug #4336753
             //is = j.getInputStream (je);
-            try (InputStream is = getInputStream4336753(jf, je); OutputStream os = Files.newOutputStream(f.toPath())) {
-                FileUtil.copy(is, os);
-            } catch (InvalidPathException ex) {
-                throw new IOException(ex);
+            InputStream is = getInputStream4336753(jf, je);
+
+            try {
+                OutputStream os = new FileOutputStream(f);
+
+                try {
+                    FileUtil.copy(is, os);
+                } finally {
+                    os.close();
+                }
+            } finally {
+                is.close();
             }
         }
 
         f.deleteOnExit();
 
-        return Files.newInputStream(f.toPath());
+        return new FileInputStream(f);
     }
 
     private static String temporaryName(String filePath, String entryPath) {
diff --git a/platform/openide.filesystems/src/org/openide/filesystems/LocalFileSystem.java b/platform/openide.filesystems/src/org/openide/filesystems/LocalFileSystem.java
index 7266cbf..b41e618 100644
--- a/platform/openide.filesystems/src/org/openide/filesystems/LocalFileSystem.java
+++ b/platform/openide.filesystems/src/org/openide/filesystems/LocalFileSystem.java
@@ -33,7 +33,6 @@ 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;
@@ -402,16 +401,13 @@ public class LocalFileSystem extends AbstractFileSystem {
         File file = null;
 
         try {
-            file = getFile(name);
-            fis = new BufferedInputStream(Files.newInputStream(file.toPath()));
-        } catch (IOException | InvalidPathException exc) {
-            FileNotFoundException fnfException = new FileNotFoundException(exc.getMessage());
+            fis = new BufferedInputStream(new FileInputStream(file = getFile(name)));
+        } catch (FileNotFoundException exc) {
             if ((file == null) || !file.exists()) {
-                ExternalUtil.annotate(fnfException,
-                        NbBundle.getMessage(LocalFileSystem.class, "EXC_FileOutsideModified", getFile(name)));
+                ExternalUtil.annotate(exc, NbBundle.getMessage(LocalFileSystem.class, "EXC_FileOutsideModified", getFile(name)));
             }
 
-            throw fnfException;
+            throw exc;
         }
 
         return fis;
@@ -422,17 +418,14 @@ public class LocalFileSystem extends AbstractFileSystem {
         if (!f.exists()) {
             f.getParentFile().mkdirs();
         }
-        try {
-            OutputStream retVal = new BufferedOutputStream(Files.newOutputStream(f.toPath()));
+        OutputStream retVal = new BufferedOutputStream(new FileOutputStream(f));
 
-            // workaround for #42624
-            if (BaseUtilities.isMac()) {
-                retVal = getOutputStreamForMac42624(retVal, name);
-            }
-            return retVal;
-        } catch (InvalidPathException ex) {
-            throw new IOException(ex);
+        // workaround for #42624
+        if (BaseUtilities.isMac()) {
+            retVal = getOutputStreamForMac42624(retVal, name);
         }
+
+        return retVal;
     }
 
     private OutputStream getOutputStreamForMac42624(final OutputStream originalStream, final String name) {


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

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