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.openecomp.sdc;
23 import org.apache.commons.codec.binary.Base64;
24 import org.apache.commons.io.output.ByteArrayOutputStream;
26 import java.io.ByteArrayInputStream;
27 import java.io.IOException;
28 import java.nio.file.Files;
29 import java.nio.file.Path;
30 import java.nio.file.Paths;
31 import java.util.HashMap;
33 import java.util.zip.ZipEntry;
34 import java.util.zip.ZipInputStream;
36 public class ZipUtil {
38 public static void main(String[] args) {
40 String zipFileName = "/src/test/resources/config/config.zip";
42 zipFileName = "C:\\Git_work\\D2-SDnC\\catalog-be\\src\\test\\resources\\config\\config.zip";
43 zipFileName = "src/test/resources/config/config.zip";
45 Path path = Paths.get(zipFileName);
48 byte[] zipAsBytes = Files.readAllBytes(path);
51 byte[] decodedMd5 = Base64.encodeBase64(zipAsBytes);
52 String decodedStr = new String(decodedMd5);
54 zipAsBytes = Base64.decodeBase64(decodedStr.getBytes());
56 // String str = new String(zipAsBytes);
58 // readZip(str.getBytes());
61 } catch (IOException e) {
67 private static Map<String, byte[]> readZip(byte[] zipAsBytes) {
69 Map<String, byte[]> fileNameToByteArray = new HashMap<>();
71 byte[] buffer = new byte[1024];
72 ZipInputStream zis = null;
75 zis = new ZipInputStream(new ByteArrayInputStream(zipAsBytes));
76 // get the zipped file list entry
77 ZipEntry ze = zis.getNextEntry();
81 String fileName = ze.getName();
83 if (!ze.isDirectory()) {
85 ByteArrayOutputStream os = new ByteArrayOutputStream();
88 while ((len = zis.read(buffer)) > 0) {
89 os.write(buffer, 0, len);
92 // aClass.outputStreamMethod(os);
93 String aString = new String(os.toByteArray(), "UTF-8");
95 fileNameToByteArray.put(fileName, os.toByteArray());
103 ze = zis.getNextEntry();
110 } catch (IOException ex) {
111 ex.printStackTrace();
118 } catch (IOException e) {
125 return fileNameToByteArray;