Situation:
A ZIP file may contain a large number of files (for example, 100+ XML/CSV files), and often these files are located inside one or more nested subfolders within the ZIP archive.
Users frequently need to pull all files from the ZIP without specifying individual file names in the Process Flow.
📌 Example
If your ZIP contains:
data.zip
├── abc/
│ ├── file1.csv
│ ├── file2.csv
│
├── reports/
│ └── 2024/
│ ├── q1.csv
│ ├── q2.csv
│
└── rootfile.csv
Solution:
The following Custom Plugin extracts all files from a ZIP file, including files inside folders or multi-level nested folders.
This ensures complete and accurate extraction for any ZIP structure.
Process Flow Configuration:
Add this Custom Plugin after the File Source activity and set:
Consume Stream:
trueGenerate Stream:
false
Then specify the target directory where the extracted files should be stored inside the Custom Plugin code.
Set your extraction folder path:
String targetFolder = "<path of target location >";Example:
String targetFolder = "D:\\DecompressedFiles\\Target\\";Custom Plugin Code (UnzipPlugin.txt)
import java.io.*;
import java.util.zip.*;
ZipInputStream in = null;
OutputStream out = null;
ZipEntry ze = null;
String targetFolder = "<path of target location>";
try {
in = new ZipInputStream(inputStream);
while ((ze = in.getNextEntry()) != null) {
try {
System.out.println("Extracting: " + ze.getName());
// Build full output path
File outFile = new File(targetFolder, ze.getName());
// If the entry is a directory, create it and continue
if (ze.isDirectory()) {
outFile.mkdirs();
continue;
}
// Ensure parent folder exists (handles nested folders)
outFile.getParentFile().mkdirs();
// Create stream to write file
out = new FileOutputStream(outFile);
byte[] buffer = new byte[1024];
int len;
while ((len = in.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
out.flush();
} finally {
try {
if (out != null)
out.close();
} catch (IOException e) {
service.getLogger().error("Output stream cannot be closed: " + e.getMessage(), e);
throw e;
}
}
}
} catch (Exception e) {
service.getLogger().error("Error while decompression: " + e.getMessage(), e);
throw e;
}
Comments
0 comments
Please sign in to leave a comment.