Removing blueprints-processor
[ccsdk/features.git] / sdnr / wt / devicemanager / provider / src / test / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / test / util / ZipFile.java
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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
15  * the License.
16  * ============LICENSE_END==========================================================================
17  ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.test.util;
19
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;
26
27 public class ZipFile implements AutoCloseable {
28
29     private final ZipOutputStream zos;
30     private final FileOutputStream fos;
31
32     public ZipFile(String zipPath) throws FileNotFoundException {
33         fos = new FileOutputStream(zipPath);
34         zos = new ZipOutputStream(fos);
35     }
36
37     public void addToZipFile(String fileName) throws FileNotFoundException, IOException {
38
39         System.out.println("Writing '" + fileName + "' to zip file");
40
41         InputStream fis = ZipFile.class.getClassLoader().getResourceAsStream(fileName);
42         if (fis == null) {
43             throw new FileNotFoundException("Resource not found: " + fileName);
44         }
45
46         ZipEntry zipEntry = new ZipEntry(fileName);
47         zos.putNextEntry(zipEntry);
48         byte[] bytes = new byte[1024];
49         int length;
50         while ((length = fis.read(bytes)) >= 0) {
51             zos.write(bytes, 0, length);
52         }
53         zos.closeEntry();
54         fis.close();
55     }
56
57     @Override
58     public void close() throws IOException {
59         zos.close();
60         fos.close();
61     }
62
63 }