try {
File outFile = new File(outputDirectory);
if (!outFile.exists()) {
outFile.mkdirs();
}
org.apache.tools.zip.ZipFile zipFile = new org.apache.tools.zip.ZipFile(uploadFileName);
java.util.Enumeration e = zipFile.getEntries();
org.apache.tools.zip.ZipEntry zipEntry = null;
while (e.hasMoreElements()){
zipEntry = (org.apache.tools.zip.ZipEntry)e.nextElement();
def zipEntryName = zipEntry.getName()
if (zipEntry.isDirectory()) {
// mkdir directory
def dirName = zipEntryName.substring(0, zipEntryName.length() - 1);
File f = new File(outFile.getPath() + File.separator + dirName);
f.mkdirs();
}
if (! zipEntry.isDirectory()){
//mkdir entryDirectory
if( -1 != zipEntry.getName().indexOf("/")){
def fileDirName = zipEntryName.substring(0,zipEntryName.lastIndexOf("/"))
//println(fileDirName)
File fDir = new File(outFile.getPath() + File.separator + fileDirName)
//println(fDir.mkdirs())
}
File f = new File(outputDirectory + File.separator + zipEntry.getName());
if(!f.exists()){
f.createNewFile()
}
InputStream fin = zipFile.getInputStream(zipEntry);
FileOutputStream out = new FileOutputStream(f);
int c;
byte[] b = new byte[1024];
while((c=fin.read(b)) != -1){
out.write(b,0,c);
}
out.close();
fin.close();
}
}
zipFile.close();
}catch (Exception ex){
ex.printStackTrace();
}
new File(uploadFileName).delete()