aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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;
+ }
+
+}