Merge "Replace FileUtils.toByteArray() with IOUtils"
authorMichael Lando <ml636r@att.com>
Wed, 16 Aug 2017 14:01:39 +0000 (14:01 +0000)
committerGerrit Code Review <gerrit@onap.org>
Wed, 16 Aug 2017 14:01:39 +0000 (14:01 +0000)
common/openecomp-sdc-artifact-generator-lib/openecomp-sdc-artifact-generator-test/dependency-reduced-pom.xml
openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/pom.xml
openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java
openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/services/impl/ToscaFileOutputServiceCsarImpl.java

index a1ced43..a71fe7f 100644 (file)
@@ -1,43 +1,43 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-  <parent>
-    <artifactId>openecomp-common-lib</artifactId>
-    <groupId>org.openecomp.sdc.common</groupId>
-    <version>1.1.0-SNAPSHOT</version>
-    <relativePath>../../pom.xml</relativePath>
-  </parent>
-  <modelVersion>4.0.0</modelVersion>
-  <groupId>org.openecomp.sdc.common</groupId>
-  <artifactId>openecomp-sdc-artifact-generator-test</artifactId>
-  <build>
-    <plugins>
-      <plugin>
-        <artifactId>maven-compiler-plugin</artifactId>
-        <configuration>
-          <source>1.7</source>
-          <target>1.7</target>
-        </configuration>
-      </plugin>
-      <plugin>
-        <artifactId>maven-shade-plugin</artifactId>
-        <version>${mvn.shade.version}</version>
-        <executions>
-          <execution>
-            <phase>package</phase>
-            <goals>
-              <goal>shade</goal>
-            </goals>
-            <configuration>
-              <artifactSet>
-                <excludes>
-                  <exclude>com.google.guava:*</exclude>
-                </excludes>
-              </artifactSet>
-            </configuration>
-          </execution>
-        </executions>
-      </plugin>
-    </plugins>
-  </build>
-</project>
-
+<?xml version="1.0" encoding="UTF-8"?>\r
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">\r
+  <parent>\r
+    <artifactId>openecomp-common-lib</artifactId>\r
+    <groupId>org.openecomp.sdc.common</groupId>\r
+    <version>1.1.0-SNAPSHOT</version>\r
+    <relativePath>../../pom.xml</relativePath>\r
+  </parent>\r
+  <modelVersion>4.0.0</modelVersion>\r
+  <groupId>org.openecomp.sdc.common</groupId>\r
+  <artifactId>openecomp-sdc-artifact-generator-test</artifactId>\r
+  <build>\r
+    <plugins>\r
+      <plugin>\r
+        <artifactId>maven-compiler-plugin</artifactId>\r
+        <configuration>\r
+          <source>1.7</source>\r
+          <target>1.7</target>\r
+        </configuration>\r
+      </plugin>\r
+      <plugin>\r
+        <artifactId>maven-shade-plugin</artifactId>\r
+        <version>${mvn.shade.version}</version>\r
+        <executions>\r
+          <execution>\r
+            <phase>package</phase>\r
+            <goals>\r
+              <goal>shade</goal>\r
+            </goals>\r
+            <configuration>\r
+              <artifactSet>\r
+                <excludes>\r
+                  <exclude>com.google.guava:*</exclude>\r
+                </excludes>\r
+              </artifactSet>\r
+            </configuration>\r
+          </execution>\r
+        </executions>\r
+      </plugin>\r
+    </plugins>\r
+  </build>\r
+</project>\r
+\r
index 76d6ff6..490bcf7 100644 (file)
             <artifactId>snakeyaml</artifactId>
             <version>${snakeyaml.version}</version>
         </dependency>
+        <!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+            <version>${commons.io.version}</version>
+        </dependency>
         <dependency>
             <groupId>org.apache.commons</groupId>
             <artifactId>commons-lang3</artifactId>
index 08d9bd8..87ce8d3 100644 (file)
 
 package org.openecomp.core.utilities.file;
 
+import org.apache.commons.io.IOUtils;
 import org.openecomp.core.utilities.json.JsonUtil;
 import org.openecomp.sdc.tosca.services.YamlUtil;
 
 import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Enumeration;
@@ -179,48 +178,15 @@ public class FileUtils {
    * @return the byte [ ]
    */
   public static byte[] toByteArray(InputStream input) {
-    ByteArrayOutputStream output = new ByteArrayOutputStream();
+    if (input == null) {
+      return new byte[0];
+    }
     try {
-      copy(input, output);
+      return IOUtils.toByteArray(input);
     } catch (IOException exception) {
       throw new RuntimeException(
           "error will convertion input stream to byte array:" + exception.getMessage());
     }
-    return output.toByteArray();
-  }
-
-  /**
-   * Copy int.
-   *
-   * @param input  the input
-   * @param output the output
-   * @return the int
-   * @throws IOException the io exception
-   */
-  public static int copy(InputStream input, OutputStream output) throws IOException {
-    long count = copyLarge(input, output);
-    return count > 2147483647L ? -1 : (int) count;
-  }
-
-  private static long copyLarge(InputStream input, OutputStream output) throws IOException {
-    return copyLarge(input, output, new byte[4096]);
-  }
-
-  private static long copyLarge(InputStream input, OutputStream output, byte[] buffer)
-      throws IOException {
-    long count = 0L;
-
-    int n1;
-    if (input == null) {
-      return count;
-    }
-    for (; -1 != (n1 = input.read(buffer)); count += (long) n1) {
-      output.write(buffer, 0, n1);
-    }
-
-    return count;
-
-
   }
 
   /**
index b518057..9a3ed8e 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.openecomp.sdc.tosca.services.impl;
 
+import org.apache.commons.io.IOUtils;
 import org.openecomp.core.utilities.file.FileContentHandler;
 import org.openecomp.core.utilities.file.FileUtils;
 import org.openecomp.sdc.common.errors.CoreException;
@@ -176,6 +177,8 @@ public class ToscaFileOutputServiceCsarImpl implements ToscaFileOutputService {
   }
 
   private void writeBytesToZip(ZipOutputStream zos, InputStream is) throws IOException {
-    FileUtils.copy(is, zos);
+    if(is != null){
+      IOUtils.copy(is, zos);
+    }
   }
 }