diff options
Diffstat (limited to 'sdc-distribution-ci/src/main/java/org/openecomp/test/Decoder.java')
-rw-r--r-- | sdc-distribution-ci/src/main/java/org/openecomp/test/Decoder.java | 60 |
1 files changed, 28 insertions, 32 deletions
diff --git a/sdc-distribution-ci/src/main/java/org/openecomp/test/Decoder.java b/sdc-distribution-ci/src/main/java/org/openecomp/test/Decoder.java index c7345f2..434952b 100644 --- a/sdc-distribution-ci/src/main/java/org/openecomp/test/Decoder.java +++ b/sdc-distribution-ci/src/main/java/org/openecomp/test/Decoder.java @@ -23,40 +23,36 @@ package org.openecomp.test; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; - import org.apache.commons.codec.binary.Base64; public class Decoder { - public static String encode(byte[] byteArrayToEncode) { - - byte[] bytesEncoded = Base64.encodeBase64(byteArrayToEncode); - String strEncoded = new String(bytesEncoded); - return strEncoded; - } - - public static String decode(String strEncoded) throws IOException { - - byte[] byteDecoded = Base64.decodeBase64(strEncoded); - String decoded = new String(byteDecoded); - - return decoded; - - } - - public static String readFileToString(String file) throws IOException { - - BufferedReader reader = new BufferedReader(new FileReader(file)); - String line = null; - StringBuilder stringBuilder = new StringBuilder(); - String ls = System.getProperty("line.separator"); - - while ((line = reader.readLine()) != null) { - stringBuilder.append(line); - stringBuilder.append(ls); - } - reader.close(); - return stringBuilder.toString(); - } - + public static String encode(byte[] byteArrayToEncode) { + return new String(Base64.encodeBase64(byteArrayToEncode)); + } + + public static String decode(String strEncoded) { + return new String(Base64.decodeBase64(strEncoded)); + } + + public static String readFileToString(String file) throws IOException { + + try (FileReader fileReader = new FileReader(file); + BufferedReader reader = new BufferedReader(fileReader)) { + String line; + StringBuilder stringBuilder = new StringBuilder(); + String ls = System.getProperty("line.separator"); + + while ((line = reader.readLine()) != null) { + stringBuilder.append(line); + stringBuilder.append(ls); + } + + reader.close(); + fileReader.close(); + return stringBuilder.toString(); + } catch (IOException e) { + throw new IOException(e); + } + } } |