Repository: syncope
Updated Branches:
  refs/heads/2_0_X c54018947 -> cfd946055


Remove FileInput/OutputStream.
 - See 
https://www.cloudbees.com/blog/fileinputstream-fileoutputstream-considered-harmful


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/cfd94605
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/cfd94605
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/cfd94605

Branch: refs/heads/2_0_X
Commit: cfd94605503326e716615a0d7a069b41db15ccdc
Parents: c540189
Author: Colm O hEigeartaigh <cohei...@apache.org>
Authored: Mon Apr 24 13:54:08 2017 +0100
Committer: Francesco Chicchiriccò <ilgro...@apache.org>
Committed: Mon Apr 24 18:43:29 2017 +0200

----------------------------------------------------------------------
 .../syncope/client/cli/SyncopeServices.java     |  7 +++---
 .../cli/commands/migrate/MigrateConf.java       |  7 ++++--
 .../report/ReportSyncopeOperations.java         | 26 +++++++++++---------
 .../commands/self/WorkflowExportDiagram.java    | 10 +++++---
 .../console/resources/FilesystemResource.java   |  7 +++---
 .../syncope/installer/utilities/MavenUtils.java |  4 +--
 6 files changed, 35 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/cfd94605/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeServices.java
----------------------------------------------------------------------
diff --git 
a/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeServices.java 
b/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeServices.java
index beb5feb..b2606e4 100644
--- 
a/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeServices.java
+++ 
b/client/cli/src/main/java/org/apache/syncope/client/cli/SyncopeServices.java
@@ -18,9 +18,10 @@
  */
 package org.apache.syncope.client.cli;
 
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.Properties;
 import org.apache.commons.lang3.BooleanUtils;
 import 
org.apache.syncope.client.cli.commands.install.InstallConfigFileTemplate;
@@ -39,7 +40,7 @@ public final class SyncopeServices {
 
     public static <T> T get(final Class<T> clazz) {
         final Properties properties = new Properties();
-        try (InputStream is = new 
FileInputStream(InstallConfigFileTemplate.configurationFilePath())) {
+        try (InputStream is = 
Files.newInputStream(Paths.get(InstallConfigFileTemplate.configurationFilePath())))
 {
             properties.load(is);
         } catch (final IOException e) {
             LOG.error("Error opening properties file", e);
@@ -63,7 +64,7 @@ public final class SyncopeServices {
 
     public static void testUsernameAndPassword(final String username, final 
String password) {
         final Properties properties = new Properties();
-        try (InputStream is = new 
FileInputStream(InstallConfigFileTemplate.configurationFilePath())) {
+        try (InputStream is = 
Files.newInputStream(Paths.get(InstallConfigFileTemplate.configurationFilePath())))
 {
             properties.load(is);
         } catch (final IOException e) {
             LOG.error("Error opening properties file", e);

http://git-wip-us.apache.org/repos/asf/syncope/blob/cfd94605/client/cli/src/main/java/org/apache/syncope/client/cli/commands/migrate/MigrateConf.java
----------------------------------------------------------------------
diff --git 
a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/migrate/MigrateConf.java
 
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/migrate/MigrateConf.java
index 9187555..8edf1f8 100644
--- 
a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/migrate/MigrateConf.java
+++ 
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/migrate/MigrateConf.java
@@ -21,10 +21,12 @@ package org.apache.syncope.client.cli.commands.migrate;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ObjectNode;
-import java.io.FileInputStream;
 import java.io.FileWriter;
+import java.io.InputStream;
 import java.io.IOException;
 import java.io.StringWriter;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -137,7 +139,8 @@ public class MigrateConf {
         reporter.writeStartDocument("UTF-8", "1.0");
         reporter.writeStartElement("dataset");
 
-        XMLStreamReader reader = INPUT_FACTORY.createXMLStreamReader(new 
FileInputStream(src));
+        InputStream inputStream = Files.newInputStream(Paths.get(src));
+        XMLStreamReader reader = 
INPUT_FACTORY.createXMLStreamReader(inputStream);
         reader.nextTag(); // root
         reader.nextTag(); // dataset
 

http://git-wip-us.apache.org/repos/asf/syncope/blob/cfd94605/client/cli/src/main/java/org/apache/syncope/client/cli/commands/report/ReportSyncopeOperations.java
----------------------------------------------------------------------
diff --git 
a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/report/ReportSyncopeOperations.java
 
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/report/ReportSyncopeOperations.java
index efbd821..0109d5e 100644
--- 
a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/report/ReportSyncopeOperations.java
+++ 
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/report/ReportSyncopeOperations.java
@@ -18,9 +18,11 @@
  */
 package org.apache.syncope.client.cli.commands.report;
 
-import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.OutputStream;
 import java.io.SequenceInputStream;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.List;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.TransformerException;
@@ -58,7 +60,7 @@ public class ReportSyncopeOperations {
                 getEntity();
 
         String fileName = "export_" + executionKey;
-        FileOutputStream fos = null;
+        OutputStream os = null;
         switch (format) {
             case XML:
                 fileName += ".xml";
@@ -67,33 +69,33 @@ public class ReportSyncopeOperations {
 
             case CSV:
                 fileName += ".csv";
-                fos = new FileOutputStream(fileName);
-                IOUtils.copyAndCloseInput(report, fos);
+                os = Files.newOutputStream(Paths.get(fileName));
+                IOUtils.copyAndCloseInput(report, os);
                 break;
 
             case PDF:
                 fileName += ".pdf";
-                fos = new FileOutputStream(fileName);
-                IOUtils.copyAndCloseInput(report, fos);
+                os = Files.newOutputStream(Paths.get(fileName));
+                IOUtils.copyAndCloseInput(report, os);
                 break;
 
             case HTML:
                 fileName += ".html";
-                fos = new FileOutputStream(fileName);
-                IOUtils.copyAndCloseInput(report, fos);
+                os = Files.newOutputStream(Paths.get(fileName));
+                IOUtils.copyAndCloseInput(report, os);
                 break;
 
             case RTF:
                 fileName += ".rtf";
-                fos = new FileOutputStream(fileName);
-                IOUtils.copyAndCloseInput(report, fos);
+                os = Files.newOutputStream(Paths.get(fileName));
+                IOUtils.copyAndCloseInput(report, os);
                 break;
 
             default:
                 return format + " not supported";
         }
-        if (fos != null) {
-            fos.close();
+        if (os != null) {
+            os.close();
         }
 
         return fileName;

http://git-wip-us.apache.org/repos/asf/syncope/blob/cfd94605/client/cli/src/main/java/org/apache/syncope/client/cli/commands/self/WorkflowExportDiagram.java
----------------------------------------------------------------------
diff --git 
a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/self/WorkflowExportDiagram.java
 
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/self/WorkflowExportDiagram.java
index ee5c541..80b6e41 100644
--- 
a/client/cli/src/main/java/org/apache/syncope/client/cli/commands/self/WorkflowExportDiagram.java
+++ 
b/client/cli/src/main/java/org/apache/syncope/client/cli/commands/self/WorkflowExportDiagram.java
@@ -18,9 +18,11 @@
  */
 package org.apache.syncope.client.cli.commands.self;
 
-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.Paths;
 import javax.ws.rs.core.Response;
 import javax.xml.ws.WebServiceException;
 import org.apache.cxf.helpers.IOUtils;
@@ -44,9 +46,9 @@ public class WorkflowExportDiagram extends 
AbstractWorkflowCommand {
             try {
                 final Response response = 
workflowSyncopeOperations.exportDiagram(input.firstParameter());
                 final byte[] diagram = 
IOUtils.readBytesFromStream((InputStream) response.getEntity());
-                try (final FileOutputStream fos = new 
FileOutputStream("/tmp/diagram.png")) {
-                    fos.write(diagram);
-                    fos.close();
+                try (final OutputStream os = 
Files.newOutputStream(Paths.get("/tmp/diagram.png"))) {
+                    os.write(diagram);
+                    os.close();
                 }
                 workflowResultManager.genericMessage("Diagram created: 
/tmp/diagram.png");
             } catch (final SyncopeClientException | WebServiceException ex) {

http://git-wip-us.apache.org/repos/asf/syncope/blob/cfd94605/client/console/src/main/java/org/apache/syncope/client/console/resources/FilesystemResource.java
----------------------------------------------------------------------
diff --git 
a/client/console/src/main/java/org/apache/syncope/client/console/resources/FilesystemResource.java
 
b/client/console/src/main/java/org/apache/syncope/client/console/resources/FilesystemResource.java
index a05a5b5..dad9917 100644
--- 
a/client/console/src/main/java/org/apache/syncope/client/console/resources/FilesystemResource.java
+++ 
b/client/console/src/main/java/org/apache/syncope/client/console/resources/FilesystemResource.java
@@ -19,9 +19,10 @@
 package org.apache.syncope.client.console.resources;
 
 import java.io.File;
-import java.io.FileInputStream;
+import java.io.InputStream;
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
 import org.apache.wicket.request.resource.AbstractResource;
 import org.apache.wicket.util.io.IOUtils;
 import org.slf4j.Logger;
@@ -61,9 +62,9 @@ public class FilesystemResource extends AbstractResource {
 
                 @Override
                 public void writeData(final Attributes attributes) throws 
IOException {
-                    FileInputStream resourceIS = null;
+                    InputStream resourceIS = null;
                     try {
-                        resourceIS = new FileInputStream(new File(baseDir, 
subPath));
+                        resourceIS = Files.newInputStream(new File(baseDir, 
subPath).toPath());
                         IOUtils.copy(resourceIS, 
attributes.getResponse().getOutputStream());
                     } catch (IOException e) {
                         LOG.error("Could not read from {}", 
baseDir.getAbsolutePath() + subPath, e);

http://git-wip-us.apache.org/repos/asf/syncope/blob/cfd94605/installer/src/main/java/org/apache/syncope/installer/utilities/MavenUtils.java
----------------------------------------------------------------------
diff --git 
a/installer/src/main/java/org/apache/syncope/installer/utilities/MavenUtils.java
 
b/installer/src/main/java/org/apache/syncope/installer/utilities/MavenUtils.java
index 2464a6b..3959af0 100644
--- 
a/installer/src/main/java/org/apache/syncope/installer/utilities/MavenUtils.java
+++ 
b/installer/src/main/java/org/apache/syncope/installer/utilities/MavenUtils.java
@@ -21,9 +21,9 @@ package org.apache.syncope.installer.utilities;
 import com.izforge.izpack.panels.process.AbstractUIProcessHandler;
 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.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -203,7 +203,7 @@ public class MavenUtils {
 
             proxies.appendChild(proxy);
 
-            FileSystemUtils.writeXML(settings, new 
FileOutputStream(tempSettingsXML));
+            FileSystemUtils.writeXML(settings, 
Files.newOutputStream(tempSettingsXML.toPath()));
 
         }
         return tempSettingsXML;

Reply via email to