aboutsummaryrefslogtreecommitdiffstats
path: root/asdc-controller/src
diff options
context:
space:
mode:
authorzm330 <zhangminyj@chinamobile.com>2020-02-28 17:01:34 +0800
committerzm330 <zhangminyj@chinamobile.com>2020-02-28 17:01:45 +0800
commit806a46b2f785dd6b0a453ae1a6f74f4091e2d656 (patch)
tree63fdddcda58df9c38c810b454625f8aec3b8fc99 /asdc-controller/src
parenta9e3132226baa83fdf1c5f05ddd30017b6d1b3f9 (diff)
Add zip parser
Issue-ID: SO-2368 Signed-off-by: zm330 <zhangminyj@chinamobile.com> Change-Id: I6174746badecec59a16573e56ac2924dbadc6747
Diffstat (limited to 'asdc-controller/src')
-rw-r--r--asdc-controller/src/main/java/org/onap/so/asdc/util/ZipParser.java67
1 files changed, 67 insertions, 0 deletions
diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/util/ZipParser.java b/asdc-controller/src/main/java/org/onap/so/asdc/util/ZipParser.java
new file mode 100644
index 0000000000..c2f04dca7b
--- /dev/null
+++ b/asdc-controller/src/main/java/org/onap/so/asdc/util/ZipParser.java
@@ -0,0 +1,67 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (c) 2019, CMCC Technologies Co., Ltd.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.asdc.util;
+
+import java.io.*;
+import java.nio.charset.Charset;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import java.util.zip.ZipInputStream;
+
+public class ZipParser {
+
+ private static volatile ZipParser instance;
+
+ public static ZipParser getInstance() {
+ if (instance == null) {
+ synchronized (ZipParser.class) {
+ if (instance == null) {
+ instance = new ZipParser();
+ }
+ }
+ }
+ return instance;
+ }
+
+ public String parseJsonForZip(String path) throws IOException {
+ ZipFile zf = new ZipFile(path);
+ InputStream in = new BufferedInputStream(new FileInputStream(path));
+ Charset cs = Charset.forName("utf-8");
+ ZipInputStream zin = new ZipInputStream(in, cs);
+ ZipEntry ze;
+ String artifactContent = null;
+ while ((ze = zin.getNextEntry()) != null) {
+ if (ze.toString().endsWith("json")) {
+ StringBuilder jsonStr = new StringBuilder();
+ BufferedReader br = new BufferedReader(new InputStreamReader(zf.getInputStream(ze)));
+ String line;
+ while ((line = br.readLine()) != null) {
+ jsonStr.append(line);
+ }
+ br.close();
+ artifactContent = jsonStr.toString().replace("\"", "\\\"").replaceAll("\\s", "");
+ }
+ }
+ zin.closeEntry();
+ return artifactContent;
+ }
+
+}