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());}
@BuvaneshV The provided code is a Java code snippet that unzips a non-password protected .zip file. It reads the Base64-encoded zip file content from an attachment page, decodes it, and processes the content using a ZipInputStream. The code extracts the individual files within the zip archive, encodes them back to Base64, and adds their names and content to two separate lists on the primary work page. The code handles exceptions and logs any error messages.
It is possible to use Java to unzip a password-protected zipped file. You can use third-party libraries like Apache Commons Compress or Zip4j to handle password-protected zip files in Java. These libraries provide methods to read, write, and manipulate password-protected zip files easily
File attachment configuration in REST and SOAP integrations
If you believe your code should work, please log a support ticket on the MSP. Please provide the ticket id here so we can help track it.