summaryrefslogtreecommitdiffstats
path: root/ecomp-portal-widget-ms/src/main/java/org/openecomp/portalapp/widget/utils/UnzipUtil.java
diff options
context:
space:
mode:
authorChristopher Lott (cl778h) <clott@research.att.com>2017-08-23 18:27:19 -0400
committerChristopher Lott (cl778h) <clott@research.att.com>2017-08-23 21:12:56 -0400
commit978dbcf0a196acbafad72fe1e2478ec0e384f02f (patch)
tree17e1ceaa4a12a599320cbb317947e990bf1a5383 /ecomp-portal-widget-ms/src/main/java/org/openecomp/portalapp/widget/utils/UnzipUtil.java
parentbc7350dce5b7b1dcd1c472a3922b42c4ea99809d (diff)
Deliver centralized role management feature
Repair multiple defects also. Revise deployment to use docker-compose. Remove all zip archives. Issue: PORTAL-21, PORTAL-25, PORTAL-28, PORTAL-52, PORTAL-69, PORTAL-74, PORTAL-76, PORTAL-80, PORTAL-82 Change-Id: Ie72fec7d35ba78beb162bba6ed27b2caee340c61 Signed-off-by: Christopher Lott (cl778h) <clott@research.att.com>
Diffstat (limited to 'ecomp-portal-widget-ms/src/main/java/org/openecomp/portalapp/widget/utils/UnzipUtil.java')
-rw-r--r--ecomp-portal-widget-ms/src/main/java/org/openecomp/portalapp/widget/utils/UnzipUtil.java102
1 files changed, 0 insertions, 102 deletions
diff --git a/ecomp-portal-widget-ms/src/main/java/org/openecomp/portalapp/widget/utils/UnzipUtil.java b/ecomp-portal-widget-ms/src/main/java/org/openecomp/portalapp/widget/utils/UnzipUtil.java
deleted file mode 100644
index efbfe437..00000000
--- a/ecomp-portal-widget-ms/src/main/java/org/openecomp/portalapp/widget/utils/UnzipUtil.java
+++ /dev/null
@@ -1,102 +0,0 @@
-package org.openecomp.portalapp.widget.utils;
-
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Stack;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-
-import org.openecomp.portalapp.widget.constant.WidgetConstant;
-import org.openecomp.portalapp.widget.service.impl.StorageServiceImpl;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-public class UnzipUtil {
-
- /**
- * Size of the buffer to read/write data
- */
- private static final int BUFFER_SIZE = 4096;
- private static final Logger logger = LoggerFactory.getLogger(UnzipUtil.class);
- /**
- * Extracts a zip file specified by the zipFilePath to a directory specified by
- * destDirectory (will be created if does not exists)
- * @param zipFilePath
- * @param destDirectory
- * @throws IOException
- */
-
- public Map<String, byte[]> unzip_db(String zipFilePath, String destDirectory, String widgetName) throws IOException {
-
- logger.debug("UnzipUtil.unzip_db: unzip widget file {}", widgetName);
- File destDir = new File(destDirectory);
- if (!destDir.exists()) {
- destDir.mkdir();
- }
- ZipInputStream zipIn = new ZipInputStream(new FileInputStream(zipFilePath));
- ZipEntry entry = zipIn.getNextEntry();
- Map<String, byte[]> map = new HashMap<>();
-
- map.put(WidgetConstant.WIDGET_CONTROLLER_LOCATION, null);
- map.put(WidgetConstant.WIDGET_MARKUP_LOCATION, null);
- map.put(WidgetConstant.WIDGET_STYLE_LOCATION, null);
-
-
- Stack<File> stack = new Stack<>();
-
- // iterates over entries in the zip file
- while (entry != null) {
- String filePath = destDirectory + File.separator + widgetName + File.separator +
- entry.getName().substring(entry.getName().indexOf("/")+1);
- logger.debug("UnzipUtil.unzip_db: file path " + filePath);
- if (!entry.isDirectory()) {
- // if the entry is a file, extracts it
- logger.debug("UnzipUtil.unzip_db: unzip and save widget file {}", filePath);
- stack.push(new File(filePath));
- extractFile(zipIn, filePath);
- } else {
- // if the entry is a directory, make the directory
- logger.debug("UnzipUtil.unzip_db: unzip and create widget folder {}", filePath);
- File dir = new File(filePath);
- stack.push(new File(filePath));
-
- dir.mkdir();
-
- }
- if(map.containsKey(entry.getName().substring(entry.getName().indexOf("/")+1))){
- map.put(entry.getName().substring(entry.getName().indexOf("/")+1), Files.readAllBytes(Paths.get(filePath)));
- }
- zipIn.closeEntry();
- entry = zipIn.getNextEntry();
- }
- zipIn.close();
- while(!stack.isEmpty())
- stack.pop().delete();
- return map;
- }
-
-
-
-
- /**
- * Extracts a zip entry (file entry)
- * @param zipIn
- * @param filePath
- * @throws IOException
- */
- private void extractFile(ZipInputStream zipIn, String filePath) throws IOException {
- BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(filePath));
- byte[] bytesIn = new byte[BUFFER_SIZE];
- int read = 0;
- while ((read = zipIn.read(bytesIn)) != -1) {
- bos.write(bytesIn, 0, read);
- }
- bos.close();
- }
-} \ No newline at end of file