Question
2
Replies
3238
Views
Posted: October 24, 2016
Last activity: October 25, 2016
Closed
How to create Zip file
I've requirement to create zip file based out of set up Rule-File-Text instances. I could see few post to use ZipOutputStream classes, but I'm looking for OOTB way.
Can you provide your thoughts?
I'm not sure of OOTB way, however you could write a java step in activity and refer below piece of code.
To zip all files in PRPC using Java API
java.lang.StringBuilder sb = new java.lang.StringBuilder();
char sep = PRFile.separatorChar;
String FileName = tools.getParamValue("FileName");
String TmpDir = pega.getSystemSettings().getFSSetting("initialization/explicittempdir", null, true, false);
String FullPath = TmpDir + "\\StaticContent\\global\\ServiceExport";
int BUFFER = 2048;
try {
java.io.BufferedInputStream origin = null;
String zipfileName = FullPath + sep + "SystemInfo.zip";
java.io.File f = new java.io.File(zipfileName);
f.createNewFile();
java.io.FileOutputStream dest = new java.io.FileOutputStream(f);
java.util.zip.ZipOutputStream out = new java.util.zip.ZipOutputStream(new java.io.BufferedOutputStream(dest));
byte data[] = new byte[BUFFER];
String files[] = {"FrameworkDetails.csv","HotFix.csv","DynamicSystemSettings.csv"};
for(int i=0; i<files.length; i++){
java.io.FileInputStream fi = new java.io.FileInputStream(FullPath + sep +files[i]);
origin = new java.io.BufferedInputStream(fi, BUFFER);
java.util.zip.ZipEntry entry = new java.util.zip.ZipEntry(files[i]);
out.putNextEntry(entry);
int count;
while((count = origin.read(data, 0,
BUFFER)) != -1)
{
out.write(data, 0, count);
}
origin.close();
}
out.close();
}
catch (Exception e)
{
oLog.error(e.getStackTrace());
}
Hope this helps!