You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@netbeans.apache.org by GitBox <gi...@apache.org> on 2017/12/10 18:34:28 UTC

[GitHub] mdindoffer closed pull request #295: Drop usage of FileInput/OutputStreams - modules a* -> c*

mdindoffer closed pull request #295: Drop usage of FileInput/OutputStreams - modules a* -> c*
URL: https://github.com/apache/incubator-netbeans/pull/295
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/api.search/src/org/netbeans/modules/search/matcher/AsciiMultiLineMappedMatcher.java b/api.search/src/org/netbeans/modules/search/matcher/AsciiMultiLineMappedMatcher.java
index 73c5df85f..0147f9e0d 100644
--- a/api.search/src/org/netbeans/modules/search/matcher/AsciiMultiLineMappedMatcher.java
+++ b/api.search/src/org/netbeans/modules/search/matcher/AsciiMultiLineMappedMatcher.java
@@ -19,12 +19,11 @@
 package org.netbeans.modules.search.matcher;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.nio.MappedByteBuffer;
 import java.nio.channels.FileChannel;
 import java.nio.charset.Charset;
+import java.nio.file.StandardOpenOption;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.regex.Matcher;
@@ -59,43 +58,30 @@ public AsciiMultiLineMappedMatcher(SearchPattern searchPattern) {
     }
 
     @Override
-    protected Def checkMeasuredInternal(FileObject fo,
-            SearchListener listener) {
-
+    protected Def checkMeasuredInternal(FileObject fo, SearchListener listener) {
         MappedByteBuffer bb = null;
-        FileChannel fc = null;
         try {
-
             listener.fileContentMatchingStarted(fo.getPath());
             File file = FileUtil.toFile(fo);
 
-            // Open the file and then get a channel from the stream
-            FileInputStream fis = new FileInputStream(file);
-            fc = fis.getChannel();
-
-            // Get the file's size and then map it into memory
-            int sz = (int) fc.size();
-            bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz);
+            try (FileChannel fc = FileChannel.open(file.toPath(), StandardOpenOption.READ)) {
+                // Get the file's size and then map it into memory
+                int sz = (int) fc.size();
+                bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz);
 
-            List<TextDetail> list = matchWholeFile(new FastCharSequence(bb, 0),
-                    fo);
+                List<TextDetail> list = matchWholeFile(new FastCharSequence(bb, 0),
+                        fo);
 
-            if (list != null && !list.isEmpty()) {
-                return new Def(fo, Charset.forName("ASCII"), list);
-            } else {
-                return null;
+                if (list != null && !list.isEmpty()) {
+                    return new Def(fo, Charset.forName("ASCII"), list);
+                } else {
+                    return null;
+                }
             }
         } catch (Exception e) {
             listener.generalError(e);
             return null;
         } finally {
-            if (fc != null) {
-                try {
-                    fc.close();
-                } catch (IOException ex) {
-                    listener.generalError(ex);
-                }
-            }
             MatcherUtils.unmap(bb);
         }
     }
diff --git a/api.search/src/org/netbeans/modules/search/matcher/FastMatcher.java b/api.search/src/org/netbeans/modules/search/matcher/FastMatcher.java
index 72b6d9fa5..dd49b70a9 100644
--- a/api.search/src/org/netbeans/modules/search/matcher/FastMatcher.java
+++ b/api.search/src/org/netbeans/modules/search/matcher/FastMatcher.java
@@ -31,6 +31,7 @@
 import java.nio.charset.CharsetDecoder;
 import java.nio.charset.CoderResult;
 import java.nio.charset.CodingErrorAction;
+import java.nio.file.StandardOpenOption;
 import java.util.ArrayList;
 import java.util.LinkedList;
 import java.util.List;
@@ -268,16 +269,9 @@ private TextDetail createLineMatchTextDetail(DataObject dataObject,
     /**
      * Check file content using Java NIO API.
      */
-    private Def checkSmall(FileObject fo, File file,
-            SearchListener listener) {
-
+    private Def checkSmall(FileObject fo, File file, SearchListener listener) {
         MappedByteBuffer bb = null;
-        FileChannel fc = null;
-        try {
-            // Open the file and then get a channel from the stream
-            FileInputStream fis = new FileInputStream(file);
-            fc = fis.getChannel();
-
+        try (FileChannel fc = FileChannel.open(file.toPath(), StandardOpenOption.READ)) {
             // Get the file's size and then map it into memory
             int sz = (int) fc.size();
             bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz);
@@ -304,13 +298,6 @@ private Def checkSmall(FileObject fo, File file,
             listener.generalError(e);
             return null;
         } finally {
-            if (fc != null) {
-                try {
-                    fc.close();
-                } catch (IOException ex) {
-                    listener.generalError(ex);
-                }
-            }
             unmap(bb);
         }
     }
diff --git a/api.search/src/org/netbeans/modules/search/matcher/MultiLineMappedMatcherBig.java b/api.search/src/org/netbeans/modules/search/matcher/MultiLineMappedMatcherBig.java
index 793397149..84620a6bf 100644
--- a/api.search/src/org/netbeans/modules/search/matcher/MultiLineMappedMatcherBig.java
+++ b/api.search/src/org/netbeans/modules/search/matcher/MultiLineMappedMatcherBig.java
@@ -19,8 +19,6 @@
 package org.netbeans.modules.search.matcher;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.nio.CharBuffer;
 import java.nio.MappedByteBuffer;
@@ -29,6 +27,7 @@
 import java.nio.charset.CharsetDecoder;
 import java.nio.charset.CoderResult;
 import java.nio.charset.CodingErrorAction;
+import java.nio.file.StandardOpenOption;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.regex.Matcher;
@@ -140,7 +139,6 @@ public void terminate() {
     private class LongCharSequence implements CharSequence {
 
         private long fileSize;
-        private FileInputStream fileInputStream;
         private FileChannel fileChannel;
         /**
          * At which character in the file the current buffer starts (counting
@@ -191,15 +189,11 @@ public void terminate() {
          */
         private State state = State.STANDARD;
 
-        public LongCharSequence(File file, Charset charset)
-                throws FileNotFoundException {
-
+        public LongCharSequence(File file, Charset charset) throws IOException {
             decoder = prepareDecoder(charset);
-            fileInputStream = new FileInputStream(file);
-            fileChannel = fileInputStream.getChannel();
+            fileChannel = FileChannel.open(file.toPath(), StandardOpenOption.READ);
             fileSize = file.length();
-            charBuffer = CharBuffer.allocate((int) Math.min(fileSize,
-                    SIZE_LIMIT));
+            charBuffer = CharBuffer.allocate((int) Math.min(fileSize, SIZE_LIMIT));
         }
 
         /**
@@ -447,13 +441,6 @@ public void close() {
                     Exceptions.printStackTrace(ex);
                 }
             }
-            if (fileInputStream != null) {
-                try {
-                    fileInputStream.close();
-                } catch (IOException ex) {
-                    Exceptions.printStackTrace(ex);
-                }
-            }
             if (byteBuffer != null) {
                 MatcherUtils.unmap(byteBuffer);
             }
diff --git a/api.search/src/org/netbeans/modules/search/matcher/MultiLineMappedMatcherSmall.java b/api.search/src/org/netbeans/modules/search/matcher/MultiLineMappedMatcherSmall.java
index 871113643..ce518a068 100644
--- a/api.search/src/org/netbeans/modules/search/matcher/MultiLineMappedMatcherSmall.java
+++ b/api.search/src/org/netbeans/modules/search/matcher/MultiLineMappedMatcherSmall.java
@@ -19,14 +19,13 @@
 package org.netbeans.modules.search.matcher;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
 import java.nio.CharBuffer;
 import java.nio.MappedByteBuffer;
 import java.nio.channels.FileChannel;
 import java.nio.charset.Charset;
 import java.nio.charset.CharsetDecoder;
 import java.nio.charset.CodingErrorAction;
+import java.nio.file.StandardOpenOption;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.regex.Matcher;
@@ -61,19 +60,13 @@ public MultiLineMappedMatcherSmall(SearchPattern searchPattern) {
     }
 
     @Override
-    protected Def checkMeasuredInternal(FileObject fo,
-            SearchListener listener) {
-
+    protected Def checkMeasuredInternal(FileObject fo, SearchListener listener) {
         MappedByteBuffer bb = null;
-        FileChannel fc = null;
         try {
-
             listener.fileContentMatchingStarted(fo.getPath());
             File file = FileUtil.toFile(fo);
 
-            // Open the file and then get a channel from the stream
-            FileInputStream fis = new FileInputStream(file);
-            fc = fis.getChannel();
+            try (FileChannel fc = FileChannel.open(file.toPath(), StandardOpenOption.READ)) {
 
             // Get the file's size and then map it into memory
             int sz = (int) fc.size();
@@ -97,17 +90,11 @@ protected Def checkMeasuredInternal(FileObject fo,
                 Def def = new Def(fo, decoder.charset(), textDetails);
                 return def;
             }
+            }
         } catch (Exception e) {
             listener.generalError(e);
             return null;
         } finally {
-            if (fc != null) {
-                try {
-                    fc.close();
-                } catch (IOException ex) {
-                    listener.generalError(ex);
-                }
-            }
             MatcherUtils.unmap(bb);
         }
     }
diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/suite/SuiteBrandingModel.java b/apisupport.ant/src/org/netbeans/modules/apisupport/project/suite/SuiteBrandingModel.java
index 05b3473d9..6df181bc9 100644
--- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/suite/SuiteBrandingModel.java
+++ b/apisupport.ant/src/org/netbeans/modules/apisupport/project/suite/SuiteBrandingModel.java
@@ -21,12 +21,12 @@
 
 import org.netbeans.modules.apisupport.project.spi.BrandingSupport;
 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.net.URL;
+import java.nio.file.Files;
 import java.util.Locale;
 import java.util.StringTokenizer;
 import org.netbeans.api.annotations.common.NonNull;
@@ -198,22 +198,16 @@ public void updateProjectInternationalizationLocales() {
     
     private static EditableProperties getEditableProperties(final File bundle) throws IOException {
         EditableProperties p = new EditableProperties(true);
-        InputStream is = new FileInputStream(bundle);
-        try {
+        try (InputStream is = Files.newInputStream(bundle.toPath())) {
             p.load(is);
-        } finally {
-            is.close();
         }
         return p;
     }
     
     private static void storeEditableProperties(final EditableProperties p, final File bundle) throws IOException {
         FileObject fo = FileUtil.toFileObject(bundle);
-        OutputStream os = null == fo ? new FileOutputStream(bundle) : fo.getOutputStream();
-        try {
+        try (OutputStream os = null == fo ? Files.newOutputStream(bundle.toPath()) : fo.getOutputStream()) {
             p.store(os);
-        } finally {
-            os.close();
         }
     }
 
diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/ModuleList.java b/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/ModuleList.java
index 17dc07428..941f27be3 100644
--- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/ModuleList.java
+++ b/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/ModuleList.java
@@ -22,10 +22,10 @@
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileFilter;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
@@ -329,17 +329,12 @@ public static File findNetBeansOrgDestDir(File nb_all) {
     private static final Map<File,File> netbeansOrgDestDirs = new HashMap<File,File>();
     private static File checkForNetBeansOrgDestDir(File properties) {
         if (properties.isFile()) {
-            try {
-                InputStream is = new FileInputStream(properties);
-                try {
-                    Properties p = new Properties();
-                    p.load(is);
-                    String d = p.getProperty(NETBEANS_DEST_DIR);
-                    if (d != null) {
-                        return new File(d);
-                    }
-                } finally {
-                    is.close();
+            try (InputStream is = Files.newInputStream(properties.toPath())) {
+                Properties p = new Properties();
+                p.load(is);
+                String d = p.getProperty(NETBEANS_DEST_DIR);
+                if (d != null) {
+                    return new File(d);
                 }
             } catch (IOException x) {
                 LOG.log(Level.INFO, "Could not read " + properties, x);
@@ -1118,11 +1113,8 @@ private static PropertyProvider loadPropertiesFile(File f) throws IOException {
             return PropertyUtils.fixedPropertyProvider(Collections.<String,String>emptyMap());
         }
         Properties p = new Properties();
-        InputStream is = new FileInputStream(f);
-        try {
+        try (InputStream is = Files.newInputStream(f.toPath())) {
             p.load(is);
-        } finally {
-            is.close();
         }
         return PropertyUtils.fixedPropertyProvider(NbCollections.checkedMapByFilter(p, String.class, String.class, true));
     }
diff --git a/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/PlatformLayersCacheManager.java b/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/PlatformLayersCacheManager.java
index ebd551a3f..496adb414 100644
--- a/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/PlatformLayersCacheManager.java
+++ b/apisupport.ant/src/org/netbeans/modules/apisupport/project/universe/PlatformLayersCacheManager.java
@@ -22,7 +22,6 @@
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileFilter;
-import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.FilenameFilter;
@@ -34,6 +33,7 @@
 import java.net.URL;
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Calendar;
@@ -175,21 +175,21 @@ private static File findCacheFile(File clusterDir) throws IOException {
         // XXX last access timestamp and cleaning of long unused cache files? If cache gets too big...
         if (cacheIndex == null) {
             cacheIndex = new LinkedHashMap<File, Integer>();
-            ObjectInputStream ois = null;
             try {
                 File indexF = new File(cacheLocation, "index.ser");
                 if (indexF.exists()) {
-                    ois = new ObjectInputStream(new FileInputStream(indexF));
-                    int version = ois.readInt();
-                    assert version == 1;
-                    int count = ois.readInt();
-                    for (int c = 0; c < count; c++) {
-                        String clusterPath = (String) ois.readObject();
-                        Date lastAccess = (Date) ois.readObject(); // last access timestamp, unused so far
-                        File cd = new File(clusterPath);
-                        if (cd.isDirectory()) {
-                            cacheIndex.put(cd, c);
+                    try (ObjectInputStream ois = new ObjectInputStream(Files.newInputStream(indexF.toPath()))) {
+                        int version = ois.readInt();
+                        assert version == 1;
+                        int count = ois.readInt();
+                        for (int c = 0; c < count; c++) {
+                            String clusterPath = (String) ois.readObject();
+                            Date lastAccess = (Date) ois.readObject(); // last access timestamp, unused so far
+                            File cd = new File(clusterPath);
+                            if (cd.isDirectory()) {
+                                cacheIndex.put(cd, c);
 
+                            }
                         }
                     }
                 }
@@ -199,9 +199,6 @@ private static File findCacheFile(File clusterDir) throws IOException {
                 // corrupted index file, keep what we've read and skip the rest
                 LOGGER.log(Level.WARNING, "Exception during loading project layers cache index file (for cluster "
                         + clusterDir + "): " + ex2.toString());
-            } finally {
-                if (ois != null)
-                    ois.close();
             }
         }
         Integer index = cacheIndex.get(clusterDir);
@@ -378,7 +375,7 @@ private static void doStoreCaches() {
             try {
                 try {
                     indexF = new File(cacheLocation, "index.ser");
-                    oos = new ObjectOutputStream(new FileOutputStream(indexF));
+                    oos = new ObjectOutputStream(Files.newOutputStream(indexF.toPath()));
                     oos.writeInt(1);    // index version
                     oos.writeInt(cacheIndex.size());
                     Date now = Calendar.getInstance().getTime();
@@ -411,7 +408,7 @@ private static void storeCache(PLFSCache cache, File cf) {
         ObjectOutputStream oos = null;
         try {
             try {
-                oos = new ObjectOutputStream(new FileOutputStream(cf));
+                oos = new ObjectOutputStream(Files.newOutputStream(cf.toPath()));
 
                 // cache file starts with version number (int), number of entries (int) and continues with a sequence of entries in format:
                 // <JAR name (no path)><JAR size><JAR timestamp><ignore JAR>[<has masked entries><binary layerFS size><serialized binary layerFS>];
@@ -530,55 +527,48 @@ private static PLFSCache loadCache(File clusterDir) {
             if (cacheFile == null) {
                 return null;
             }
-            FileInputStream fis = null;
             try {
                 File[] moduleDirs = new File[MODULE_DIRS.length];
                 for (int i = 0; i < moduleDirs.length; i++) {
                     moduleDirs[i] = new File(clusterDir, MODULE_DIRS[i]);
                 }
-                fis = new FileInputStream(cacheFile);
-                ObjectInputStream ois = new ObjectInputStream(fis);
-                // cache file starts with version number (int), number of entries (int) and continues with a sequence of entries in format:
-                // <JAR name (no path)><JAR size><JAR timestamp><ignore JAR>[<has masked entries><binary layerFS size><serialized binary layerFS>];
-                // when <ignore JAR> is true, the rest of the entry is missing
-                int version = ois.readInt();
-                assert version == 1;
-                int count = ois.readInt();
-                for (int c = 0; c < count; c++) {
-                    String jarName = (String) ois.readObject();
-                    File jarFile = null;
-                    for (File dir : moduleDirs) {
-                        jarFile = new File(dir, jarName);
-                        if (jarFile.exists())
-                            break;
-                    }
-                    long jarSize = ois.readLong();
-                    long jarTS = ois.readLong();
-                    boolean isIgnored = ois.readBoolean();
-                    boolean isMasked = false;
-                    FileSystem fs = null;
-                    byte[] bytes = null;
-                    if (! isIgnored) {
-                        isMasked = ois.readBoolean();
-                        int binFSSize = ois.readInt();
-                        bytes = new byte[binFSSize];
-                        ois.readFully(bytes, 0, binFSSize);
-                        fs = man.load(null, ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN));
+                try (ObjectInputStream ois = new ObjectInputStream(Files.newInputStream(cacheFile.toPath()))) {
+                    // cache file starts with version number (int), number of entries (int) and continues with a sequence of entries in format:
+                    // <JAR name (no path)><JAR size><JAR timestamp><ignore JAR>[<has masked entries><binary layerFS size><serialized binary layerFS>];
+                    // when <ignore JAR> is true, the rest of the entry is missing
+                    int version = ois.readInt();
+                    assert version == 1;
+                    int count = ois.readInt();
+                    for (int c = 0; c < count; c++) {
+                        String jarName = (String) ois.readObject();
+                        File jarFile = null;
+                        for (File dir : moduleDirs) {
+                            jarFile = new File(dir, jarName);
+                            if (jarFile.exists()) {
+                                break;
+                            }
+                        }
+                        long jarSize = ois.readLong();
+                        long jarTS = ois.readLong();
+                        boolean isIgnored = ois.readBoolean();
+                        boolean isMasked = false;
+                        FileSystem fs = null;
+                        byte[] bytes = null;
+                        if (!isIgnored) {
+                            isMasked = ois.readBoolean();
+                            int binFSSize = ois.readInt();
+                            bytes = new byte[binFSSize];
+                            ois.readFully(bytes, 0, binFSSize);
+                            fs = man.load(null, ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN));
+                        }
+                        cache.add(new PLFSCacheEntry(jarFile, jarSize, jarTS, isIgnored, isMasked, fs, bytes));
                     }
-                    cache.add(new PLFSCacheEntry(jarFile, jarSize, jarTS, isIgnored, isMasked, fs, bytes));
                 }
-            } catch (FileNotFoundException ex) {
-                // cache not found
+            } catch (FileNotFoundException | ClassNotFoundException ex) {
+                // cache not found or corrupted cache file, throw the cache away
                 LOGGER.log(Level.WARNING, "Exception while loading project layers cache (from file " + cacheFile.getAbsolutePath()
                         + " for cluster " + clusterDir + "): " + ex.toString());
                 return null;
-            } catch (ClassNotFoundException ex2) {
-                // corrupted cache file, throw the cache away
-                LOGGER.log(Level.WARNING, "Exception while loading project layers cache (from file " + cacheFile.getAbsolutePath()
-                        + " for cluster " + clusterDir + "): " + ex2.toString());
-                return null;
-            } finally {
-                fis.close();
             }
             LOGGER.fine("Cache for cluster " + clusterDir + " successfully loaded from cache file " + cacheFile);
         } catch (IOException ex) {
diff --git a/apisupport.harness/build.xml b/apisupport.harness/build.xml
index cd6b185ae..5847aad36 100644
--- a/apisupport.harness/build.xml
+++ b/apisupport.harness/build.xml
@@ -36,7 +36,7 @@
 
     <target name="compile-jnlp-launcher" depends="init,compile">
         <mkdir dir="${build.dir}/jnlp-launcher-classes"/>
-        <nb-javac srcdir="jnlp-src" destdir="${build.dir}/jnlp-launcher-classes" deprecation="${build.compiler.deprecation}" debug="${build.compiler.debug}" source="1.6" target="1.6" includeantruntime="false">
+        <nb-javac srcdir="jnlp-src" destdir="${build.dir}/jnlp-launcher-classes" deprecation="${build.compiler.deprecation}" debug="${build.compiler.debug}" source="1.7" target="1.7" includeantruntime="false">
             <classpath>
                 <path path="${jnlp.cp}"/>
             </classpath>
diff --git a/apisupport.harness/jnlp-src/org/netbeans/modules/apisupport/jnlplauncher/InstalledFileLocatorImpl.java b/apisupport.harness/jnlp-src/org/netbeans/modules/apisupport/jnlplauncher/InstalledFileLocatorImpl.java
index 77ef4de75..d000bf31e 100644
--- a/apisupport.harness/jnlp-src/org/netbeans/modules/apisupport/jnlplauncher/InstalledFileLocatorImpl.java
+++ b/apisupport.harness/jnlp-src/org/netbeans/modules/apisupport/jnlplauncher/InstalledFileLocatorImpl.java
@@ -20,12 +20,12 @@
 package org.netbeans.modules.apisupport.jnlplauncher;
 
 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.util.Iterator;
 import org.openide.modules.InstalledFileLocator;
 import org.openide.util.Exceptions;
@@ -87,27 +87,19 @@ public File locate(String relativePath, String codeNameBase, boolean localized)
                     }
                 }
             }
-            try {
-                InputStream is = loader.getResourceAsStream("META-INF/files/" + relativePath);
+            try (InputStream is = loader.getResourceAsStream("META-INF/files/" + relativePath)) {
                 if (is != null) {
-                    try {
-                        // XXX could try to cache previously created files
-                        File temp = File.createTempFile("nbjnlp-", relativePath.replaceFirst("^.+/", ""));
-                        temp.deleteOnExit();
-                        OutputStream os = new FileOutputStream(temp);
-                        try {
-                            byte[] buf = new byte[4096];
-                            int read;
-                            while ((read = is.read(buf)) != -1) {
-                                os.write(buf, 0, read);
-                            }
-                        } finally {
-                            os.close();
+                    // XXX could try to cache previously created files
+                    File temp = File.createTempFile("nbjnlp-", relativePath.replaceFirst("^.+/", ""));
+                    temp.deleteOnExit();
+                    try (OutputStream os = Files.newOutputStream(temp.toPath())) {
+                        byte[] buf = new byte[4096];
+                        int read;
+                        while ((read = is.read(buf)) != -1) {
+                            os.write(buf, 0, read);
                         }
-                        return temp;
-                    } finally {
-                        is.close();
                     }
+                    return temp;
                 }
             } catch (IOException x) {
                 Exceptions.printStackTrace(x);
diff --git a/apisupport.harness/nbproject/project.properties b/apisupport.harness/nbproject/project.properties
index 8f2145273..f6fe7f4a2 100644
--- a/apisupport.harness/nbproject/project.properties
+++ b/apisupport.harness/nbproject/project.properties
@@ -16,7 +16,7 @@
 # under the License.
 
 javac.compilerargs=-Xlint -Xlint:-serial
-javac.source=1.6
+javac.source=1.7
 jnlp.cp=\
     ${o.n.bootstrap.dir}/lib/boot.jar:\
     ${openide.modules.dir}/lib/org-openide-modules.jar:\
diff --git a/apisupport.installer.maven/nbproject/project.properties b/apisupport.installer.maven/nbproject/project.properties
index 7f641b767..409182252 100644
--- a/apisupport.installer.maven/nbproject/project.properties
+++ b/apisupport.installer.maven/nbproject/project.properties
@@ -15,5 +15,5 @@
 # specific language governing permissions and limitations
 # under the License.
 is.eager=true
-javac.source=1.6
+javac.source=1.7
 javac.compilerargs=-Xlint -Xlint:-serial
diff --git a/apisupport.installer.maven/src/org/netbeans/modules/apisupport/installer/maven/actions/BuildInstallersAction.java b/apisupport.installer.maven/src/org/netbeans/modules/apisupport/installer/maven/actions/BuildInstallersAction.java
index b595b0f7f..61323dd5f 100644
--- a/apisupport.installer.maven/src/org/netbeans/modules/apisupport/installer/maven/actions/BuildInstallersAction.java
+++ b/apisupport.installer.maven/src/org/netbeans/modules/apisupport/installer/maven/actions/BuildInstallersAction.java
@@ -20,12 +20,12 @@
 
 import java.awt.event.ActionEvent;
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
@@ -176,14 +176,13 @@ void actionPerformed(ActionEvent e) {
                                 licenseFile.getParentFile().mkdirs();
                                 licenseFile.deleteOnExit();
 
-                                OutputStream os = new FileOutputStream(licenseFile);
-                                byte[] bytes = new byte[4096];
-                                int read = 0;
-                                while ((read = is.read(bytes)) > 0) {
-                                    os.write(bytes, 0, read);
+                                try (OutputStream os = Files.newOutputStream(licenseFile.toPath())) {
+                                    byte[] bytes = new byte[4096];
+                                    int read = 0;
+                                    while ((read = is.read(bytes)) > 0) {
+                                        os.write(bytes, 0, read);
+                                    }
                                 }
-                                os.flush();
-                                os.close();
                             } else {
                                 Logger.getLogger(BuildInstallersAction.class.getName()).log(
                                         Level.WARNING, "License resource {0} not found", licenseResource);
diff --git a/apisupport.installer/nbproject/project.properties b/apisupport.installer/nbproject/project.properties
index 1e898986a..a9cccbd49 100644
--- a/apisupport.installer/nbproject/project.properties
+++ b/apisupport.installer/nbproject/project.properties
@@ -14,6 +14,6 @@
 # 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
 nbm.module.author=Dmitry Lipin
diff --git a/apisupport.installer/src/org/netbeans/modules/apisupport/installer/actions/BuildInstallersAction.java b/apisupport.installer/src/org/netbeans/modules/apisupport/installer/actions/BuildInstallersAction.java
index 6ecbf2964..d5c6f3846 100644
--- a/apisupport.installer/src/org/netbeans/modules/apisupport/installer/actions/BuildInstallersAction.java
+++ b/apisupport.installer/src/org/netbeans/modules/apisupport/installer/actions/BuildInstallersAction.java
@@ -20,12 +20,12 @@
 
 import java.awt.event.ActionEvent;
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
@@ -180,14 +180,13 @@ public ContextBuildInstaller(Lookup actionContext) {
                                         licenseFile.getParentFile().mkdirs();
                                         licenseFile.deleteOnExit();
 
-                                        OutputStream os = new FileOutputStream(licenseFile);
-                                        byte[] bytes = new byte[4096];
-                                        int read = 0;
-                                        while ((read = is.read(bytes)) > 0) {
-                                            os.write(bytes, 0, read);
+                                        try (OutputStream os = Files.newOutputStream(licenseFile.toPath())) {
+                                            byte[] bytes = new byte[4096];
+                                            int read = 0;
+                                            while ((read = is.read(bytes)) > 0) {
+                                                os.write(bytes, 0, read);
+                                            }
                                         }
-                                        os.flush();
-                                        os.close();
                                     } else {
                                         Logger.getLogger(BuildInstallersAction.class.getName()).log(
                                                 Level.WARNING, "License resource {0} not found", licenseResource);
diff --git a/apisupport.project/nbproject/project.properties b/apisupport.project/nbproject/project.properties
index c947b08c9..05d4f874d 100644
--- a/apisupport.project/nbproject/project.properties
+++ b/apisupport.project/nbproject/project.properties
@@ -16,7 +16,7 @@
 # under the License.
 
 javac.compilerargs=-Xlint -Xlint:-serial
-javac.source=1.6
+javac.source=1.7
 
 javadoc.arch=${basedir}/arch.xml
 javadoc.apichanges=${basedir}/apichanges.xml
diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/api/ManifestManager.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/api/ManifestManager.java
index d2d7997cf..bc1b7d6fc 100644
--- a/apisupport.project/src/org/netbeans/modules/apisupport/project/api/ManifestManager.java
+++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/api/ManifestManager.java
@@ -143,14 +143,9 @@ private ManifestManager(String cnb, String releaseVersion, String specVer,
     
     public static ManifestManager getInstance(File manifest, boolean loadPublicPackages) {
         if (manifest.exists()) {
-            try {
-                InputStream mis = new FileInputStream(manifest); // NOI18N
-                try {
-                    Manifest mf = new Manifest(mis);
-                    return ManifestManager.getInstance(mf, loadPublicPackages);
-                } finally {
-                    mis.close();
-                }
+            try (InputStream mis = new FileInputStream(manifest)) {
+                Manifest mf = new Manifest(mis);
+                return ManifestManager.getInstance(mf, loadPublicPackages);
             } catch (IOException x) {
                 LOG.log(Level.INFO, "While opening: " + manifest, x);
             }
diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/spi/BrandingModel.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/spi/BrandingModel.java
index 936225ff8..d59abb485 100644
--- a/apisupport.project/src/org/netbeans/modules/apisupport/project/spi/BrandingModel.java
+++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/spi/BrandingModel.java
@@ -22,10 +22,10 @@
 import java.awt.Graphics2D;
 import java.awt.image.BufferedImage;
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.net.URL;
+import java.nio.file.Files;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Locale;
@@ -296,11 +296,8 @@ public void run() {
                     if( !iconLocation.exists() )
                         iconLocation.createNewFile();
                     FileObject fo = FileUtil.toFileObject(iconLocation);
-                    OutputStream os = fo == null ? new FileOutputStream(iconLocation) : fo.getOutputStream();
-                    try {
+                    try (OutputStream os = fo == null ? Files.newOutputStream(iconLocation.toPath()) : fo.getOutputStream()) {
                         ImageIO.write(bi, "png", os);
-                    } finally {
-                        os.close();
                     }
                 } catch (IOException ex) {
                     ErrorManager.getDefault().notify(ex);
diff --git a/apisupport.project/src/org/netbeans/modules/apisupport/project/spi/BrandingSupport.java b/apisupport.project/src/org/netbeans/modules/apisupport/project/spi/BrandingSupport.java
index c3b7b2fdd..7bc33c9c5 100644
--- a/apisupport.project/src/org/netbeans/modules/apisupport/project/spi/BrandingSupport.java
+++ b/apisupport.project/src/org/netbeans/modules/apisupport/project/spi/BrandingSupport.java
@@ -20,14 +20,13 @@
 package org.netbeans.modules.apisupport.project.spi;
 
 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.lang.ref.SoftReference;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.nio.file.Files;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -483,22 +482,16 @@ private void loadBrandedFiles(final BrandableModule mEntry,
     
     private static EditableProperties getEditableProperties(final File bundle) throws IOException {
         EditableProperties p = new EditableProperties(true);
-        InputStream is = new FileInputStream(bundle);
-        try {
+        try (InputStream is = Files.newInputStream(bundle.toPath())) {
             p.load(is);
-        } finally {
-            is.close();
         }
         return p;
     }
     
     private static void storeEditableProperties(final EditableProperties p, final File bundle) throws IOException {
         FileObject fo = FileUtil.toFileObject(bundle);
-        OutputStream os = null == fo ? new FileOutputStream(bundle) : fo.getOutputStream();
-        try {
+        try (OutputStream os = null == fo ? Files.newOutputStream(bundle.toPath()) : fo.getOutputStream()) {
             p.store(os);
-        } finally {
-            os.close();
         }
     }
 
diff --git a/autoupdate.pluginimporter/src/org/netbeans/modules/autoupdate/pluginimporter/ClusterUpdateProvider.java b/autoupdate.pluginimporter/src/org/netbeans/modules/autoupdate/pluginimporter/ClusterUpdateProvider.java
index e7c5f7d43..d1ba73ebc 100644
--- a/autoupdate.pluginimporter/src/org/netbeans/modules/autoupdate/pluginimporter/ClusterUpdateProvider.java
+++ b/autoupdate.pluginimporter/src/org/netbeans/modules/autoupdate/pluginimporter/ClusterUpdateProvider.java
@@ -21,9 +21,9 @@
 
 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 java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
@@ -167,7 +167,7 @@ private static void readConfigFile (File cf, Map<String, String> attr) {
         Document document = null;
         InputStream is = null;
         try {
-            is = new BufferedInputStream (new FileInputStream (cf));
+            is = new BufferedInputStream(Files.newInputStream(cf.toPath()));
             InputSource xmlInputSource = new InputSource (is);
             document = XMLUtil.parse (xmlInputSource, false, false, null, EntityCatalog.getDefault ());
         } catch (SAXException saxe) {
diff --git a/autoupdate.pluginimporter/src/org/netbeans/modules/autoupdate/pluginimporter/PluginImporter.java b/autoupdate.pluginimporter/src/org/netbeans/modules/autoupdate/pluginimporter/PluginImporter.java
index a2c20dcea..6cc3c4059 100644
--- a/autoupdate.pluginimporter/src/org/netbeans/modules/autoupdate/pluginimporter/PluginImporter.java
+++ b/autoupdate.pluginimporter/src/org/netbeans/modules/autoupdate/pluginimporter/PluginImporter.java
@@ -21,10 +21,10 @@
 
 import java.io.BufferedInputStream;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -320,7 +320,7 @@ private static Node getUpdateTrackingConf (File moduleUpdateTracking) {
         Document document = null;
         InputStream is;
         try {
-            is = new BufferedInputStream (new FileInputStream (moduleUpdateTracking));
+            is = new BufferedInputStream(Files.newInputStream(moduleUpdateTracking.toPath()));
             InputSource xmlInputSource = new InputSource (is);
             document = XMLUtil.parse (xmlInputSource, false, false, null, org.openide.xml.EntityCatalog.getDefault ());
             if (is != null) {
diff --git a/autoupdate.services/libsrc/org/netbeans/updater/ModuleUpdater.java b/autoupdate.services/libsrc/org/netbeans/updater/ModuleUpdater.java
index b8b9ea8ff..4b3f4f0a1 100644
--- a/autoupdate.services/libsrc/org/netbeans/updater/ModuleUpdater.java
+++ b/autoupdate.services/libsrc/org/netbeans/updater/ModuleUpdater.java
@@ -20,6 +20,8 @@
 package org.netbeans.updater;
 
 import java.io.*;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.*;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
@@ -358,7 +360,7 @@ private void unpack ()  {
                         if (destFile.exists()) {
                             File bckFile = new File(getBackupDirectory(cluster), osgiJar.getName());
                             bckFile.getParentFile().mkdirs();
-                            copyStreams(new FileInputStream(destFile), context.createOS(bckFile), -1);
+                            copyStreams(Files.newInputStream(destFile.toPath()), context.createOS(bckFile), -1);
                             XMLUtil.LOG.info("Backup file " + destFile + " to " + bckFile);
                             if (!destFile.delete() && isWindows()) {
                                 trickyDeleteOnWindows(destFile);
@@ -369,7 +371,7 @@ private void unpack ()  {
                             destFile.getParentFile().mkdirs();
                         }
 
-                        bytesRead = copyStreams(new FileInputStream(osgiJar), context.createOS(destFile), bytesRead);
+                        bytesRead = copyStreams(Files.newInputStream(osgiJar.toPath()), context.createOS(destFile), bytesRead);
                         XMLUtil.LOG.info("Copied file " + osgiJar + " to " + destFile);
                         long crc = UpdateTracking.getFileCRC(destFile);
                         version.addFileWithCrc("modules/" + osgiJar.getName(), Long.toString(crc));
@@ -410,7 +412,7 @@ private void unpack ()  {
                                     if ( destFile.exists() ) {
                                         File bckFile = new File( getBackupDirectory (cluster), entry.getName() );
                                         bckFile.getParentFile ().mkdirs ();
-                                        copyStreams( new FileInputStream( destFile ), context.createOS( bckFile ), -1 );
+                                        copyStreams(Files.newInputStream(destFile.toPath()), context.createOS( bckFile ), -1 );
                                         XMLUtil.LOG.info("Backup file " + destFile + " to " + bckFile);
                                         if (!destFile.delete() && isWindows()) {
                                             trickyDeleteOnWindows(destFile);
@@ -428,7 +430,7 @@ private void unpack ()  {
                                         pathTo = pathTo.substring(0, pathTo.length() - ".external".length());
                                         long expectedCRC = externalDownload(spec, nbm);
                                         File external = new File(nbm + "." + Long.toHexString(expectedCRC));
-                                        InputStream is = new FileInputStream(external);
+                                        InputStream is = Files.newInputStream(external.toPath());
                                         try {
                                             spec.close();
                                             OutputStream os = context.createOS(downloaded);
@@ -998,15 +1000,10 @@ public boolean isValid() {
         @SuppressWarnings("empty-statement")
         private boolean readParms(String spath) {
             Properties details = new Properties();
-            FileInputStream fis = null;
-            try {
-                details.load(fis = new FileInputStream(spath)); // NOI18N
-            } catch (IOException e) {            
+            try (InputStream fis = Files.newInputStream(Paths.get(spath))) {
+                details.load(fis);
+            } catch (IOException e) {
                 return false;
-            } finally {
-                if (fis != null) {
-                    try { fis.close(); } catch (IOException e) { /* ignore */ }
-                };
             }
             
             String mainclass;
diff --git a/autoupdate.services/libsrc/org/netbeans/updater/UpdateTracking.java b/autoupdate.services/libsrc/org/netbeans/updater/UpdateTracking.java
index c8a67564e..899b97880 100644
--- a/autoupdate.services/libsrc/org/netbeans/updater/UpdateTracking.java
+++ b/autoupdate.services/libsrc/org/netbeans/updater/UpdateTracking.java
@@ -20,6 +20,7 @@
 package org.netbeans.updater;
 
 import java.io.*;
+import java.nio.file.Files;
 import java.util.*;
 import java.util.logging.Level;
 import java.util.zip.CRC32;
@@ -277,23 +278,17 @@ private void read() {
         /** org.w3c.dom.Document document */
         org.w3c.dom.Document document;
 
-        File file;
-        InputStream is;
         int avail = 0;
         try {
-            file = trackingFile;
-            
-            if ( ! file.isFile () ) {
+            File file = trackingFile;
+            if (!file.isFile()) {
                 return;
             }
-            
-            is = new FileInputStream( file );
-            avail = is.available();
 
-            InputSource xmlInputSource = new InputSource( is );
-            document = XMLUtil.parse(xmlInputSource, false, false, DUMMY_ERROR_HANDLER, XMLUtil.createAUResolver());
-            if (is != null) {
-                is.close();
+            try (InputStream is = Files.newInputStream(file.toPath())) {
+                avail = is.available();
+                InputSource xmlInputSource = new InputSource(is);
+                document = XMLUtil.parse(xmlInputSource, false, false, DUMMY_ERROR_HANDLER, XMLUtil.createAUResolver());
             }
         }
         catch ( org.xml.sax.SAXException e ) {
@@ -444,25 +439,17 @@ Version createVersion(String specversion) {
     }
     
     private Module readModuleFromFile( File file, String codename, boolean create ) {
-        
         /** org.w3c.dom.Document document */
         org.w3c.dom.Document document;
-        InputStream is;
-        try {
-            is = new FileInputStream( file );
-
-            InputSource xmlInputSource = new InputSource( is );
+        try (InputStream is = Files.newInputStream(file.toPath())) {
+            InputSource xmlInputSource = new InputSource(is);
             document = XMLUtil.parse(xmlInputSource, false, false, DUMMY_ERROR_HANDLER, XMLUtil.createAUResolver());
-            if (is != null) {
-                is.close();
-            }
-        } catch ( org.xml.sax.SAXException e ) {
+        } catch (org.xml.sax.SAXException e) {
             XMLUtil.LOG.log(Level.SEVERE, "Bad update_tracking", e); // NOI18N
             return null;
-        }
-        catch ( java.io.IOException e ) {
-            if ( create ) {
-                return new Module (codename, file);
+        } catch (java.io.IOException e) {
+            if (create) {
+                return new Module(codename, file);
             } else {
                 return null;
             }
@@ -501,19 +488,12 @@ void deleteUnusedFiles() {
     }
     
     public static long getFileCRC(File file) throws IOException {
-        BufferedInputStream bsrc = null;
         CRC32 crc = new CRC32();
-        try {
-            bsrc = new BufferedInputStream( new FileInputStream( file ) );
+        try (BufferedInputStream bsrc = new BufferedInputStream(Files.newInputStream(file.toPath()))) {
             byte[] bytes = new byte[1024];
             int i;
-            while( (i = bsrc.read(bytes)) != -1 ) {
-                crc.update(bytes, 0, i );
-            }
-        }
-        finally {
-            if ( bsrc != null ) {
-                bsrc.close();
+            while ((i = bsrc.read(bytes)) != -1) {
+                crc.update(bytes, 0, i);
             }
         }
         return crc.getValue();
@@ -1208,7 +1188,7 @@ public String getSource (String nbmFileName) {
 
             InputStream is = null;
             try {
-                is = new FileInputStream (f);
+                is = Files.newInputStream(f.toPath());
                 document = XMLUtil.parse (new InputSource (is), false, false, null, null);
             } catch (org.xml.sax.SAXException e) {
                 XMLUtil.LOG.log (Level.WARNING,"Bad " + UpdateTracking.ADDITIONAL_INFO_FILE_NAME + f, e); // NOI18N
diff --git a/autoupdate.services/libsrc/org/netbeans/updater/UpdaterFrame.java b/autoupdate.services/libsrc/org/netbeans/updater/UpdaterFrame.java
index c1c8eb230..5290c12f0 100644
--- a/autoupdate.services/libsrc/org/netbeans/updater/UpdaterFrame.java
+++ b/autoupdate.services/libsrc/org/netbeans/updater/UpdaterFrame.java
@@ -22,6 +22,7 @@
 import java.awt.*;
 import java.io.*;
 import java.net.URL;
+import java.nio.file.Files;
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -412,8 +413,8 @@ private static Image loadIcon(String iconPath) {
     }
 
     @Override
-    public OutputStream createOS(File bckFile) throws FileNotFoundException {
-        return new FileOutputStream(bckFile);
+    public OutputStream createOS(File bckFile) throws IOException {
+        return Files.newOutputStream(bckFile.toPath());
     }
         
     static class SplashFrame extends JFrame {
diff --git a/autoupdate.services/src/org/netbeans/modules/autoupdate/services/InstallManager.java b/autoupdate.services/src/org/netbeans/modules/autoupdate/services/InstallManager.java
index 4dceb9402..12e50a794 100644
--- a/autoupdate.services/src/org/netbeans/modules/autoupdate/services/InstallManager.java
+++ b/autoupdate.services/src/org/netbeans/modules/autoupdate/services/InstallManager.java
@@ -21,9 +21,9 @@
 
 import java.beans.PropertyVetoException;
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.nio.file.Files;
 import java.util.*;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
@@ -191,11 +191,8 @@ private static File createNonExistingCluster (String targetCluster) {
                         f.getParentFile().mkdirs();
                         f.createNewFile();
                     }
-                    OutputStream os = new FileOutputStream(f);
-                    try {
+                    try (OutputStream os = Files.newOutputStream(f.toPath())) {
                         os.write(sb.toString().getBytes());
-                    } finally {
-                        os.close();
                     }
                     ERR.log (Level.FINE, "Was written new netbeans.dirs " + sb);
 
diff --git a/autoupdate.services/src/org/netbeans/modules/autoupdate/services/InstallSupportImpl.java b/autoupdate.services/src/org/netbeans/modules/autoupdate/services/InstallSupportImpl.java
index 656f929ec..eef8c6d68 100644
--- a/autoupdate.services/src/org/netbeans/modules/autoupdate/services/InstallSupportImpl.java
+++ b/autoupdate.services/src/org/netbeans/modules/autoupdate/services/InstallSupportImpl.java
@@ -28,6 +28,7 @@
 import java.net.URL;
 import java.net.URLConnection;
 import java.net.UnknownHostException;
+import java.nio.file.Files;
 import java.security.KeyStore;
 import java.security.KeyStoreException;
 import java.security.cert.Certificate;
@@ -723,8 +724,7 @@ private int doDownload (UpdateElementImpl toUpdateImpl, ProgressHandle progress,
                             byte[] arr = new byte[4096];
                             CRC32 check = new CRC32();
                             File external = new File(dest.getPath() + "." + Long.toHexString(crc.get()));
-                            FileOutputStream fos = new FileOutputStream(external);
-                            try {
+                            try (OutputStream fos = Files.newOutputStream(external.toPath())) {
                                 for (;;) {
                                     int len = real.read(arr);
                                     if (len == -1) {
@@ -738,8 +738,6 @@ private int doDownload (UpdateElementImpl toUpdateImpl, ProgressHandle progress,
                                         }
                                     }
                                 }
-                            } finally {
-                                fos.close();
                             }
                             real.close();
                             if (check.getValue() != crc.get()) {
@@ -980,7 +978,7 @@ public void run() {
             int c = 0;
             while (!(canceled = cancelled()) && (size = bsrc.read (bytes)) != -1) {
                 if(bdest == null) {
-                    bdest = new BufferedOutputStream (new FileOutputStream (dest));
+                    bdest = new BufferedOutputStream(Files.newOutputStream(dest.toPath()));
                 }
                 bdest.write (bytes, 0, size);
                 increment += size;
diff --git a/autoupdate.services/src/org/netbeans/modules/autoupdate/services/ModuleDeleterImpl.java b/autoupdate.services/src/org/netbeans/modules/autoupdate/services/ModuleDeleterImpl.java
index babb7ff35..08b24f598 100644
--- a/autoupdate.services/src/org/netbeans/modules/autoupdate/services/ModuleDeleterImpl.java
+++ b/autoupdate.services/src/org/netbeans/modules/autoupdate/services/ModuleDeleterImpl.java
@@ -25,6 +25,7 @@
 import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.file.Files;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
@@ -365,7 +366,7 @@ private Node getModuleConfiguration (File moduleUpdateTracking) {
         Document document = null;
         InputStream is;
         try {
-            is = new BufferedInputStream (new FileInputStream (moduleUpdateTracking));
+            is = new BufferedInputStream (Files.newInputStream(moduleUpdateTracking.toPath()));
             InputSource xmlInputSource = new InputSource (is);
             document = XMLUtil.parse (xmlInputSource, false, false, null, org.openide.xml.EntityCatalog.getDefault ());
             if (is != null) {
diff --git a/autoupdate.services/src/org/netbeans/modules/autoupdate/services/Utilities.java b/autoupdate.services/src/org/netbeans/modules/autoupdate/services/Utilities.java
index 8c3c4400f..d122ab0a2 100644
--- a/autoupdate.services/src/org/netbeans/modules/autoupdate/services/Utilities.java
+++ b/autoupdate.services/src/org/netbeans/modules/autoupdate/services/Utilities.java
@@ -22,6 +22,7 @@
 import java.io.*;
 import java.lang.ref.Reference;
 import java.lang.ref.WeakReference;
+import java.nio.file.Files;
 import java.security.InvalidAlgorithmParameterException;
 import java.security.KeyStore;
 import java.security.KeyStoreException;
@@ -373,11 +374,11 @@ private static void writeXMLDocumentToFile (Document doc, File dest) {
         OutputStream fos = null;
         try {
             try {
-                XMLUtil.write (doc, bos, "UTF-8"); // NOI18N
-                bos.close ();
-                fos = new FileOutputStream (dest);
-                is = new ByteArrayInputStream (bos.toByteArray ());
-                FileUtil.copy (is, fos);
+                XMLUtil.write(doc, bos, "UTF-8"); // NOI18N
+                bos.close();
+                fos = Files.newOutputStream(dest.toPath());
+                is = new ByteArrayInputStream(bos.toByteArray());
+                FileUtil.copy(is, fos);
             } finally {
                 if (is != null) {
                     is.close ();
@@ -437,7 +438,7 @@ private static void writeMarkedFilesToFile (Collection<File> files, File dest) {
         
         try {
             try {
-                fos = new FileOutputStream (dest);
+                fos = Files.newOutputStream(dest.toPath());
                 is = new ByteArrayInputStream (content.toString().getBytes());
                 FileUtil.copy (is, fos);
             } finally {
@@ -523,7 +524,7 @@ static void writeUpdateOfUpdaterJar (JarEntry updaterJarEntry, File zipFileWithU
         
         try {
             try {
-                fos = new FileOutputStream (dest);
+                fos = Files.newOutputStream(dest.toPath());
                 is = jf.getInputStream (updaterJarEntry);
                 FileUtil.copy (is, fos);
             } finally {
@@ -1090,12 +1091,9 @@ public static String getProductVersion () {
     
     private static Node getModuleConfiguration (File moduleUpdateTracking) {
         Document document;
-        InputStream is;
-        try {
-            is = new BufferedInputStream (new FileInputStream (moduleUpdateTracking));
+        try (InputStream is = new BufferedInputStream (Files.newInputStream(moduleUpdateTracking.toPath()))){
             InputSource xmlInputSource = new InputSource (is);
             document = XMLUtil.parse (xmlInputSource, false, false, null, org.openide.xml.EntityCatalog.getDefault ());
-            is.close ();
         } catch (SAXException saxe) {
             getLogger ().log (Level.INFO, "SAXException when reading " + moduleUpdateTracking, saxe);
             return null;
@@ -1380,7 +1378,7 @@ public static KeyStore loadKeyStore () {
                 if (! f.exists ()) {
                     return null;
                 }
-                is = new BufferedInputStream (new FileInputStream (f));
+                is = new BufferedInputStream(Files.newInputStream(f.toPath()));
                 ks = KeyStore.getInstance (KeyStore.getDefaultType ());
                 ks.load (is, KS_USER_PASSWORD.toCharArray ());
             } catch (IOException ex) {
@@ -1408,7 +1406,7 @@ private static void storeKeyStore (KeyStore ks) {
         OutputStream os = null;
         try {
             File f = new File (getCacheDirectory (), USER_KS_FILE_NAME);
-            os = new BufferedOutputStream (new FileOutputStream (f));
+            os = new BufferedOutputStream (Files.newOutputStream(f.toPath()));
             ks.store (os, KS_USER_PASSWORD.toCharArray ());
             getPreferences ().put (USER_KS_KEY, USER_KS_FILE_NAME);
         } catch (KeyStoreException ex) {
diff --git a/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/AutoupdateCatalogCache.java b/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/AutoupdateCatalogCache.java
index ab94735c9..b1a6210f2 100644
--- a/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/AutoupdateCatalogCache.java
+++ b/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/AutoupdateCatalogCache.java
@@ -20,12 +20,13 @@
 package org.netbeans.modules.autoupdate.updateprovider;
 
 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.net.MalformedURLException;
 import java.net.URISyntaxException;
 import java.net.URL;
+import java.nio.file.Files;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import org.netbeans.modules.autoupdate.services.AutoupdateSettings;
@@ -155,14 +156,12 @@ public void storeLicense(String name, String content) {
     
     private String readLicenseFile(String name) {
         File file = getLicenseFile(name);
-        FileInputStream fr = null;
         synchronized (name.intern()) {
-            try {
-                fr = new FileInputStream(file);
+            try (InputStream is = Files.newInputStream(file.toPath())){
                 byte[] buffer = new byte[8192];
                 int n;
                 StringBuilder sb = new StringBuilder();
-                while ((n = fr.read(buffer)) != -1) {
+                while ((n = is.read(buffer)) != -1) {
                     sb.append(new String(buffer, 0, n, "utf-8"));//NOI18N
                 }
                 return sb.toString();
@@ -170,20 +169,14 @@ private String readLicenseFile(String name) {
                 err.log(Level.INFO, "Can`t read license from file " + file, e);
                 return null;
             } finally {
-                if (fr != null) {
-                    try {
-                        fr.close();
-                    } catch (IOException e) {
-                        err.log(Level.INFO, "Can`t read close input stream for " + file, e);
-                    }
-                }
             }
         }
     }
+
     private void writeToFile(String content, File file) {
-        FileOutputStream fw = null;
+        OutputStream fw = null;
         try {
-            fw = new FileOutputStream(file);
+            fw = Files.newOutputStream(file.toPath());
             fw.write(content.getBytes("utf-8")); //NOI18N
         } catch (IOException e) {
             err.log(Level.INFO, "Can`t write to " + file, e);
@@ -257,13 +250,10 @@ private void updateCachedFile(File cache, File temp) {
 
         if (!temp.renameTo(cache)) {
             err.log(Level.INFO, "Cannot rename temp {0} to cache {1}", new Object[]{temp, cache});
-            err.log(Level.INFO, "Trying to copy {0} to cache {1}", new Object[] {temp, cache});
-            try {
-                FileOutputStream os = new FileOutputStream(cache);
-                FileInputStream is = new FileInputStream(temp);
+            err.log(Level.INFO, "Trying to copy {0} to cache {1}", new Object[]{temp, cache});
+            try (OutputStream os = Files.newOutputStream(cache.toPath());
+                    InputStream is = Files.newInputStream(temp.toPath())) {
                 FileUtil.copy(is, os);
-                os.close();
-                is.close();
                 temp.delete();
             } catch (IOException ex) {
                 err.log(Level.INFO, "Cannot even copy: {0}", ex.getMessage());
diff --git a/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/DownloadListener.java b/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/DownloadListener.java
index 5cf8964ae..2ccbbf03a 100644
--- a/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/DownloadListener.java
+++ b/autoupdate.services/src/org/netbeans/modules/autoupdate/updateprovider/DownloadListener.java
@@ -21,11 +21,11 @@
 
 import java.io.BufferedOutputStream;
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.URL;
+import java.nio.file.Files;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -98,7 +98,7 @@ private void doCopy(URL sourceUrl, InputStream is, File temp, int contentLength)
         int totalRead = 0;
 
         try {
-            os = new BufferedOutputStream(new FileOutputStream(temp));
+            os = new BufferedOutputStream(Files.newOutputStream(temp.toPath()));
             byte[] bytes = new byte[1024];
             while ((read = is.read(bytes)) != -1) {
                 os.write(bytes, 0, read);
diff --git a/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/actions/AutoupdateSettings.java b/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/actions/AutoupdateSettings.java
index f1eb866c6..3d5fc3c50 100644
--- a/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/actions/AutoupdateSettings.java
+++ b/autoupdate.ui/src/org/netbeans/modules/autoupdate/ui/actions/AutoupdateSettings.java
@@ -28,6 +28,7 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.io.Writer;
+import java.nio.file.Files;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Date;
@@ -378,7 +379,7 @@ private static String readSuperFile(File superFile) {
         // read existing super Id
         InputStream is = null;
         try {
-            is = new FileInputStream (superFile);
+            is = Files.newInputStream(superFile.toPath());
             BufferedReader r = new BufferedReader (new InputStreamReader (is));
             res = r.readLine ().trim ();
             err.log (Level.FINE, "Read Super Id: " + res + " from " + superFile);
diff --git a/bugtracking/src/org/netbeans/modules/bugtracking/tasks/cache/DashboardStorage.java b/bugtracking/src/org/netbeans/modules/bugtracking/tasks/cache/DashboardStorage.java
index 035fca6c3..763422817 100644
--- a/bugtracking/src/org/netbeans/modules/bugtracking/tasks/cache/DashboardStorage.java
+++ b/bugtracking/src/org/netbeans/modules/bugtracking/tasks/cache/DashboardStorage.java
@@ -19,6 +19,8 @@
 package org.netbeans.modules.bugtracking.tasks.cache;
 
 import java.io.*;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -322,7 +324,7 @@ public boolean accept(File dir, String name) {
     }
 
     private DataOutputStream getCategoryOutputStream(File categoryFile) throws IOException {
-        ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(categoryFile, false)));
+        ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(Files.newOutputStream(categoryFile.toPath())));
         ZipEntry entry = new ZipEntry(categoryFile.getName());
         zos.putNextEntry(entry);
         return new DataOutputStream(zos);
@@ -332,13 +334,13 @@ private DataInputStream getCategoryInputStream(File file) throws IOException {
         if (!file.exists()) {
             return null;
         }
-        ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(file)));
+        ZipInputStream zis = new ZipInputStream(new BufferedInputStream(Files.newInputStream(file.toPath())));
         zis.getNextEntry();
         return new DataInputStream(zis);
     }
 
     private DataOutputStream getClosedOutputStream(File closedFile) throws IOException {
-        ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(closedFile, false)));
+        ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(Files.newOutputStream(closedFile.toPath())));
         ZipEntry entry = new ZipEntry(closedFile.getName());
         zos.putNextEntry(entry);
         return new DataOutputStream(zos);
@@ -348,7 +350,7 @@ private DataInputStream getClosedInputStream(File closedFile) throws IOException
         if (!closedFile.exists()) {
             return null;
         }
-        ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(closedFile)));
+        ZipInputStream zis = new ZipInputStream(new BufferedInputStream(Files.newInputStream(closedFile.toPath())));
         zis.getNextEntry();
         return new DataInputStream(zis);
     }
@@ -365,7 +367,8 @@ private File getStorageRootFile() {
     private void writeStorage() {
         DataOutputStream dos = null;
         try {
-            dos = new DataOutputStream(new FileOutputStream(new File(getStorageFolder(storageFolder), STORAGE_FILE), false));
+            Path path = new File(getStorageFolder(storageFolder), STORAGE_FILE).toPath();
+            dos = new DataOutputStream(Files.newOutputStream(path));
             writeString(dos, STORAGE_VERSION);
             dos.flush();
         } catch (IOException e) {
diff --git a/bugzilla/src/org/netbeans/modules/bugzilla/util/FileUtils.java b/bugzilla/src/org/netbeans/modules/bugzilla/util/FileUtils.java
index 901c3e0d2..26de08598 100644
--- a/bugzilla/src/org/netbeans/modules/bugzilla/util/FileUtils.java
+++ b/bugzilla/src/org/netbeans/modules/bugzilla/util/FileUtils.java
@@ -20,6 +20,7 @@
 package org.netbeans.modules.bugzilla.util;
 
 import java.io.*;
+import java.nio.file.Files;
 import java.util.logging.Level;
 import org.netbeans.modules.bugzilla.Bugzilla;
 import org.openide.filesystems.FileUtil;
@@ -227,7 +228,7 @@ public static BufferedInputStream createInputStream(File file) throws IOExceptio
         int retry = 0;
         while (true) {   
             try {
-                return new BufferedInputStream(new FileInputStream(file));                
+                return new BufferedInputStream(Files.newInputStream(file.toPath()));
             } catch (IOException ex) {
                 retry++;
                 if (retry > 7) {
@@ -246,7 +247,7 @@ public static BufferedOutputStream createOutputStream(File file) throws IOExcept
         int retry = 0;
         while (true) {            
             try {
-                return new BufferedOutputStream(new FileOutputStream(file));                
+                return new BufferedOutputStream(Files.newOutputStream(file.toPath()));
             } catch (IOException ex) {
                 retry++;
                 if (retry > 7) {
diff --git a/classfile/src/org/netbeans/modules/classfile/ClassFile.java b/classfile/src/org/netbeans/modules/classfile/ClassFile.java
index dae030c7b..a97501464 100644
--- a/classfile/src/org/netbeans/modules/classfile/ClassFile.java
+++ b/classfile/src/org/netbeans/modules/classfile/ClassFile.java
@@ -23,6 +23,8 @@
 package org.netbeans.modules.classfile;
 
 import java.io.*;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.*;
 import java.util.logging.Logger;
 
@@ -143,7 +145,7 @@ public ClassFile(String classFileName, boolean includeCode) throws IOException {
         try {
             if (classFileName == null)
                 throw new IOException("input stream not specified");
-            in = new BufferedInputStream(new FileInputStream(classFileName), BUFFER_SIZE);
+            in = new BufferedInputStream(Files.newInputStream(Paths.get(classFileName)), BUFFER_SIZE);
             load(in);
         } catch (InvalidClassFormatException e) {
             throw new InvalidClassFormatException(classFileName + '(' +
diff --git a/core.netigso/nbproject/project.properties b/core.netigso/nbproject/project.properties
index f00a0003a..d5937298e 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 3d3ae68e6..6be3dc577 100644
--- a/core.netigso/src/org/netbeans/core/netigso/Netigso.java
+++ b/core.netigso/src/org/netbeans/core/netigso/Netigso.java
@@ -22,10 +22,10 @@
 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.security.ProtectionDomain;
 import java.util.Arrays;
 import java.util.Collection;
@@ -36,7 +36,6 @@
 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 +452,9 @@ private void fakeOneModule(Module m, Bundle original) throws IOException {
             } 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);
+                    }
                     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 394c39a7a..440ff507c 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 @@
 
 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 @@ static boolean useSystemProxies() {
                 }
 
                 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 553d1e59f..8e5afa2ae 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,10 @@
 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.util.HashMap;
 import java.util.Map;
 import java.util.logging.Level;
@@ -133,10 +131,7 @@ public NetworkProxySettings getNetworkProxySettings() {
         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,7 +148,6 @@ public NetworkProxySettings getNetworkProxySettings() {
                         inGroup = true;
                     }
                 }
-                dis.close();
             } catch (FileNotFoundException fnfe) {
                 LOGGER.log(Level.SEVERE, "Cannot read file: ", fnfe);
             } catch (IOException ioe) {
diff --git a/core.osgi/nbproject/project.properties b/core.osgi/nbproject/project.properties
index 0624d2c37..0fd506d48 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 f25b1e133..bbba53389 100644
--- a/core.osgi/src/org/netbeans/core/osgi/OSGiInstalledFileLocator.java
+++ b/core.osgi/src/org/netbeans/core/osgi/OSGiInstalledFileLocator.java
@@ -20,12 +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.util.Arrays;
 import java.util.Collections;
 import java.util.Iterator;
@@ -122,20 +122,13 @@ public OSGiInstalledFileLocator(BundleContext context) {
                         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);
diff --git a/core.output2/nbproject/project.properties b/core.output2/nbproject/project.properties
index 25c2885b1..5db5e5d61 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 44b2d4c2f..2189ff5f2 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 @@
 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 @@ public void saveAs(String path) throws IOException {
         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 @@ public void saveAs(String path) throws IOException {
             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 56982b995..806fae907 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.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 @@ private static OutputStream getLogStream() {
                         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 2bda232f3..6cea6afaf 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 0fbceb5fc..e8585195c 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,7 @@
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLDecoder;
+import java.nio.file.Files;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
@@ -241,16 +241,8 @@ private static File copyJAR(FileObject fo, URI archiveFileURI, boolean replace)
                     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);
                 }
                 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 a697cbf1c..c15cac240 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,7 @@
 import java.net.URLConnection;
 import java.net.URLStreamHandler;
 import java.net.UnknownServiceException;
+import java.nio.file.Files;
 import org.openide.filesystems.FileObject;
 import org.openide.filesystems.FileUtil;
 import org.openide.util.Exceptions;
@@ -140,7 +140,7 @@ public int getContentLength() {
         public InputStream getInputStream() throws IOException {
             this.connect();
             if (iStream == null) {
-                iStream = new FileInputStream(f);
+                iStream = Files.newInputStream(f.toPath());
             }
             return iStream;
         }
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 6cc31e76d..285880fee 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,8 @@
 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.util.Arrays;
 import java.util.Objects;
 import java.util.logging.Level;
@@ -84,8 +84,8 @@ private boolean checkRotate(boolean always) {
     
     private void initStream() {
         try {
-            setOutputStream(new FileOutputStream(files[0], false));
-        } catch (FileNotFoundException ex) {
+            setOutputStream(Files.newOutputStream(files[0].toPath()));
+        } catch (IOException 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 198a90013..94d26cc83 100644
--- a/core.startup/src/org/netbeans/core/startup/logging/NbLogging.java
+++ b/core.startup/src/org/netbeans/core/startup/logging/NbLogging.java
@@ -19,9 +19,10 @@
 package org.netbeans.core.startup.logging;
 
 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.StandardOpenOption;
 import java.util.logging.Handler;
 import java.util.regex.Pattern;
 import java.util.regex.PatternSyntaxException;
@@ -43,8 +44,8 @@
             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(), StandardOpenOption.APPEND));
+            } catch (IOException x) {
                 x.printStackTrace();
             }
         }
diff --git a/csl.api/anttask/build.xml b/csl.api/anttask/build.xml
index f1b82b853..26a2672f7 100644
--- a/csl.api/anttask/build.xml
+++ b/csl.api/anttask/build.xml
@@ -33,7 +33,7 @@
 
   <target name="compile">
     <mkdir dir="build/classes"/>
-    <javac srcdir="src" destdir="build/classes" deprecation="${build.compiler.deprecation}" debug="${build.compiler.debug}" target="1.6" source="1.6" >
+    <javac srcdir="src" destdir="build/classes" deprecation="${build.compiler.deprecation}" debug="${build.compiler.debug}" target="1.7" source="1.7" >
 	  <classpath>
                 <!-- cmdline Ant -->
                 <pathelement location="${ant.core.lib}"/>
diff --git a/csl.api/anttask/src/org/netbeans/modules/csl/CslJar.java b/csl.api/anttask/src/org/netbeans/modules/csl/CslJar.java
index 9b1bdb7bb..2e8e5f493 100644
--- a/csl.api/anttask/src/org/netbeans/modules/csl/CslJar.java
+++ b/csl.api/anttask/src/org/netbeans/modules/csl/CslJar.java
@@ -21,7 +21,6 @@
 
 import java.io.BufferedWriter;
 import java.io.ByteArrayInputStream;
-import java.io.FileInputStream;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.net.URL;
@@ -37,6 +36,7 @@
 import java.io.StringWriter;
 import java.net.MalformedURLException;
 import java.net.URLClassLoader;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.ResourceBundle;
@@ -97,9 +97,8 @@ public void setManifest(File manifestFile) throws BuildException {
     protected void zipFile(File file, ZipOutputStream zOut, String vPath, int mode) throws IOException {
         if (vPath.equals(layer)) {
             System.setProperty("CslJar", Boolean.TRUE.toString());
-            try {
                 // Create a tempfile and trick it!
-                InputStream is = new FileInputStream(file);
+            try (InputStream is = Files.newInputStream(file.toPath())) {
                 String modifiedLayer = getModifiedLayer(is);
                 if (modifiedLayer != null) {
                     File tmpFile = File.createTempFile("csl", "tmp"); // NOI18N
diff --git a/csl.api/src/org/netbeans/modules/csl/editor/FileObjectAccessor.java b/csl.api/src/org/netbeans/modules/csl/editor/FileObjectAccessor.java
index bd18f6173..8f42c5884 100644
--- a/csl.api/src/org/netbeans/modules/csl/editor/FileObjectAccessor.java
+++ b/csl.api/src/org/netbeans/modules/csl/editor/FileObjectAccessor.java
@@ -21,9 +21,11 @@
 package org.netbeans.modules.csl.editor;
 
 import java.io.EOFException;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.StandardOpenOption;
 
 import org.netbeans.editor.ext.DataAccessor;
 import org.openide.filesystems.FileObject;
@@ -44,7 +46,7 @@
 
     FileObject fo;
     InputStream inputStream;
-    FileOutputStream fos;
+    OutputStream fos;
     int actOff;
 
     public FileObjectAccessor(FileObject fo) {
@@ -58,11 +60,9 @@ public FileObjectAccessor(FileObject fo) {
      * @param  len    the number of bytes to append.
      */
     public void append(byte[] buffer, int off, int len) throws IOException {
-        fos = new FileOutputStream(FileUtil.toFile(fo).getPath(), true);
-        fos.write(buffer, off, len);
-        fos.flush();
-        fos.close();
-        fos = null;
+        try (OutputStream fos = Files.newOutputStream(FileUtil.toFile(fo).toPath(), StandardOpenOption.APPEND)) {
+            fos.write(buffer, off, len);
+        }
     }
     
     /**
diff --git a/csl.api/src/org/netbeans/modules/csl/spi/GsfUtilities.java b/csl.api/src/org/netbeans/modules/csl/spi/GsfUtilities.java
index fbd053750..bef3278a9 100644
--- a/csl.api/src/org/netbeans/modules/csl/spi/GsfUtilities.java
+++ b/csl.api/src/org/netbeans/modules/csl/spi/GsfUtilities.java
@@ -21,10 +21,10 @@
 
 import java.io.BufferedInputStream;
 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.EventObject;
 import java.util.Map;
 import java.util.WeakHashMap;
@@ -299,7 +299,7 @@ private static boolean doOpen(FileObject fo, int offset, String search) {
 
     public static void extractZip(final FileObject extract, final FileObject dest) throws IOException {
         File extractFile = FileUtil.toFile(extract);
-        extractZip(dest, new BufferedInputStream(new FileInputStream(extractFile)));
+        extractZip(dest, new BufferedInputStream(Files.newInputStream(extractFile.toPath())));
     }
 
     // Based on openide/fs' FileUtil.extractJar


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services