2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.sdc.ci.tests.utilities;
23 import java.io.BufferedReader;
24 import java.io.FileReader;
25 import java.io.IOException;
27 import org.apache.commons.codec.binary.Base64;
29 public class Decoder {
31 public static String encode(byte[] byteArrayToEncode) {
33 byte[] bytesEncoded = Base64.encodeBase64(byteArrayToEncode);
34 String strEncoded = new String(bytesEncoded);
38 public static String decode(String strEncoded) throws IOException {
40 byte[] byteDecoded = Base64.decodeBase64(strEncoded);
41 String decoded = new String(byteDecoded);
47 public static String readFileToString(String file) throws IOException {
49 BufferedReader reader = new BufferedReader(new FileReader(file));
51 StringBuilder stringBuilder = new StringBuilder();
52 String ls = System.getProperty("line.separator");
54 while ((line = reader.readLine()) != null) {
55 stringBuilder.append(line);
56 stringBuilder.append(ls);
59 return stringBuilder.toString();