1 /*******************************************************************************
2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
17 ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.test.util;
20 import java.io.FileNotFoundException;
21 import java.io.FileOutputStream;
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.util.zip.ZipEntry;
25 import java.util.zip.ZipOutputStream;
27 public class ZipFile implements AutoCloseable {
29 private final ZipOutputStream zos;
30 private final FileOutputStream fos;
32 public ZipFile(String zipPath) throws FileNotFoundException {
33 fos = new FileOutputStream(zipPath);
34 zos = new ZipOutputStream(fos);
37 public void addToZipFile(String fileName) throws FileNotFoundException, IOException {
39 System.out.println("Writing '" + fileName + "' to zip file");
41 InputStream fis = ZipFile.class.getClassLoader().getResourceAsStream(fileName);
43 throw new FileNotFoundException("Resource not found: " + fileName);
46 ZipEntry zipEntry = new ZipEntry(fileName);
47 zos.putNextEntry(zipEntry);
48 byte[] bytes = new byte[1024];
50 while ((length = fis.read(bytes)) >= 0) {
51 zos.write(bytes, 0, length);
58 public void close() throws IOException {