summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib
diff options
context:
space:
mode:
authorMichael Lando <ml636r@att.com>2017-08-16 14:01:39 +0000
committerGerrit Code Review <gerrit@onap.org>2017-08-16 14:01:39 +0000
commitba9ef462ad61930afee6123c17427942e8b5d28f (patch)
treedf9affa011a0b7a3569ef44f49bc95670676e7f7 /openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib
parentfa222906b5b31c34ee165e290de94dd19c8f18b3 (diff)
parent4970625eaa858c0ab84d04e0306882fb8c8ba743 (diff)
Merge "Replace FileUtils.toByteArray() with IOUtils"
Diffstat (limited to 'openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib')
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/pom.xml6
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java44
2 files changed, 11 insertions, 39 deletions
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/pom.xml b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/pom.xml
index 76d6ff6b74..490bcf742a 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/pom.xml
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/pom.xml
@@ -23,6 +23,12 @@
<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>
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java
index 08d9bd8a41..87ce8d37c3 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java
@@ -20,14 +20,13 @@
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;
-
-
}
/**