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 java.io.ByteArrayInputStream;
25 import java.io.FileInputStream;
26 import java.io.IOException;
27 import java.nio.file.Files;
28 import java.nio.file.Path;
29 import java.nio.file.Paths;
30 import java.util.HashMap;
32 import java.util.zip.ZipEntry;
33 import java.util.zip.ZipInputStream;
35 import org.apache.commons.codec.binary.Base64;
36 import org.apache.commons.io.output.ByteArrayOutputStream;
38 public class ZipUtil {
40 public static void main(String[] args) {
42 String zipFileName = "/src/test/resources/config/config.zip";
44 zipFileName = "C:\\Git_work\\D2-SDnC\\catalog-be\\src\\test\\resources\\config\\config.zip";
45 zipFileName = "src/test/resources/config/config.zip";
47 Path path = Paths.get(zipFileName);
50 byte[] zipAsBytes = Files.readAllBytes(path);
53 byte[] decodedMd5 = Base64.encodeBase64(zipAsBytes);
54 String decodedStr = new String(decodedMd5);
56 zipAsBytes = Base64.decodeBase64(decodedStr.getBytes());
58 // String str = new String(zipAsBytes);
60 // readZip(str.getBytes());
63 } catch (IOException e) {
69 private static Map<String, byte[]> readZip(byte[] zipAsBytes) {
71 Map<String, byte[]> fileNameToByteArray = new HashMap<String, byte[]>();
73 byte[] buffer = new byte[1024];
74 ZipInputStream zis = null;
77 zis = new ZipInputStream(new ByteArrayInputStream(zipAsBytes));
78 // get the zipped file list entry
79 ZipEntry ze = zis.getNextEntry();
83 String fileName = ze.getName();
85 if (false == ze.isDirectory()) {
87 ByteArrayOutputStream os = new ByteArrayOutputStream();
90 while ((len = zis.read(buffer)) > 0) {
91 os.write(buffer, 0, len);
94 // aClass.outputStreamMethod(os);
95 String aString = new String(os.toByteArray(), "UTF-8");
97 fileNameToByteArray.put(fileName, os.toByteArray());
105 ze = zis.getNextEntry();
112 } catch (IOException ex) {
113 ex.printStackTrace();
120 } catch (IOException e) {
127 return fileNameToByteArray;