How to unzip file which contains password protected file.
Below code works fine to unzip the zipped file (.zip), not password protected one.
ParameterPage MyParam = tools.getParameterPage(); ClipboardPage WorkPage = tools.getPrimaryPage(); ClipboardProperty StreamList = WorkPage.getProperty("pyModeList"); ClipboardProperty NamesList = WorkPage.getProperty("pyNames"); String TemplateName = MyParam.getString("TemplateName"); java.util.zip.ZipEntry entry = null; try { java.util.zip.ZipInputStream zipStream = new java.util.zip.ZipInputStream(new java.io.ByteArrayInputStream(Base64Util.decodeToByteArray(tools.findPage("AttachmentPage").getString("pyAttachStream")))); ArrayList<String> OutputList = new ArrayList<String>(); ArrayList<String> NameList = new ArrayList<String>();
Below code works fine to unzip the zipped file (.zip), not password protected one.
ParameterPage MyParam = tools.getParameterPage(); ClipboardPage WorkPage = tools.getPrimaryPage(); ClipboardProperty StreamList = WorkPage.getProperty("pyModeList"); ClipboardProperty NamesList = WorkPage.getProperty("pyNames"); String TemplateName = MyParam.getString("TemplateName"); java.util.zip.ZipEntry entry = null; try { java.util.zip.ZipInputStream zipStream = new java.util.zip.ZipInputStream(new java.io.ByteArrayInputStream(Base64Util.decodeToByteArray(tools.findPage("AttachmentPage").getString("pyAttachStream")))); ArrayList<String> OutputList = new ArrayList<String>(); ArrayList<String> NameList = new ArrayList<String>();
while((entry=zipStream.getNextEntry())!=null) { String entryName= entry.getName(); if (entryName != null) { NameList.add(entryName); } Boolean IsDirectory = false; if (entryName.endsWith(java.io.File.separator)) { IsDirectory = true; } int bytesRead = -1 ; java.io.ByteArrayOutputStream outStream = new java.io.ByteArrayOutputStream(); int len= (int) entry.getSize(); byte[] tempBuffer = new byte[8192]; while((bytesRead = zipStream.read(tempBuffer))!= -1) { outStream.write(tempBuffer,0,bytesRead); } if (outStream!=null) { String EncodedOut = new com.pega.pegarules.pub.util.Base64Util().encodeToString( outStream.toByteArray()); OutputList.add(EncodedOut); } } if(zipStream!=null) { zipStream.closeEntry(); zipStream.close(); } for(int i=0; i<OutputList.size();i++) { StreamList.add(OutputList.get(i)); NamesList.add(NameList.get(i)); }
} catch (Exception ex) {oLog.infoForced("failed " + ex.getMessage());}