2 * Copyright 2016-2017, Nokia Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer;
19 import com.google.common.io.ByteStreams;
21 import java.io.ByteArrayInputStream;
22 import java.io.ByteArrayOutputStream;
23 import java.io.IOException;
24 import java.util.zip.ZipEntry;
25 import java.util.zip.ZipInputStream;
26 import java.util.zip.ZipOutputStream;
28 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions;
31 * Builds a CBAM VNF package capable to be deployed on ONAP from a CBAM package
33 public class CbamVnfPackageBuilder {
36 * @param originalCbamVnfPackage the original CBAM VNF package
37 * @param vnfdLocation the location of the VNFD within the CBAM VNF package
38 * @param modifiedCbamVnfdContent the modified CBAM VNFD content
41 public byte[] toModifiedCbamVnfPackage(byte[] originalCbamVnfPackage, String vnfdLocation, String modifiedCbamVnfdContent) throws IOException {
42 ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(originalCbamVnfPackage));
43 ByteArrayOutputStream result = new ByteArrayOutputStream();
44 ZipOutputStream out = new ZipOutputStream(result);
46 while ((zipEntry = zipInputStream.getNextEntry()) != null) {
47 if (zipEntry.getName().matches(vnfdLocation)) {
48 out.putNextEntry(new ZipEntry(vnfdLocation));
49 out.write(modifiedCbamVnfdContent.getBytes());
52 out.putNextEntry(new ZipEntry(zipEntry.getName()));
53 ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
54 ByteStreams.copy(zipInputStream, byteArrayOutputStream);
55 out.write(byteArrayOutputStream.toByteArray());
59 out.putNextEntry(new ZipEntry("javascript/cbam.pre.collectConnectionPoints.js"));
60 out.write(systemFunctions().loadFile("cbam.pre.collectConnectionPoints.js"));
62 out.putNextEntry(new ZipEntry("javascript/cbam.collectConnectionPoints.js"));
63 out.write(systemFunctions().loadFile("cbam.collectConnectionPoints.js"));
65 out.putNextEntry(new ZipEntry("javascript/cbam.post.collectConnectionPoints.js"));
66 out.write(systemFunctions().loadFile("cbam.post.collectConnectionPoints.js"));
69 zipInputStream.close();
70 return result.toByteArray();