Add zip parser

Issue-ID: SO-2368

Signed-off-by: zm330 <zhangminyj@chinamobile.com>
Change-Id: I6174746badecec59a16573e56ac2924dbadc6747
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 0000000..c2f04dc
--- /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;
+    }
+
+}