[SDC-29] rebase continue work to align source
[sdc.git] / test-apis-ci / src / main / java / org / openecomp / sdc / ci / tests / utils / Decoder.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.ci.tests.utils;
22
23 import java.io.BufferedReader;
24 import java.io.FileReader;
25 import java.io.IOException;
26
27 import org.apache.commons.codec.binary.Base64;
28
29 public class Decoder {
30
31         public static String encode(byte[] byteArrayToEncode) {
32
33                 byte[] bytesEncoded = Base64.encodeBase64(byteArrayToEncode);
34                 String strEncoded = new String(bytesEncoded);
35                 return strEncoded;
36         }
37
38         public static String decode(String strEncoded) throws IOException {
39
40                 byte[] byteDecoded = Base64.decodeBase64(strEncoded);
41                 String decoded = new String(byteDecoded);
42
43                 return decoded;
44
45         }
46
47         public static String readFileToString(String file) throws IOException {
48
49                 BufferedReader reader = new BufferedReader(new FileReader(file));
50                 String line = null;
51                 StringBuilder stringBuilder = new StringBuilder();
52                 String ls = System.getProperty("line.separator");
53
54                 while ((line = reader.readLine()) != null) {
55                         stringBuilder.append(line);
56                         stringBuilder.append(ls);
57                 }
58                 reader.close();
59                 return stringBuilder.toString();
60         }
61
62 }