Created
May 19, 2018 10:28
-
-
Save accasey/04076cf70b98c9e064f5601995549a64 to your computer and use it in GitHub Desktop.
Unzip a file in PeopleCode using Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Function unzip(&inputZipFile, &targetDir); | |
| Local JavaObject &zipFileInputStream = CreateJavaObject("java.io.FileInputStream", &inputZipFile); | |
| Local JavaObject &zipInputStream = CreateJavaObject("java.util.zip.ZipInputStream", &zipFileInputStream); | |
| Local JavaObject &zipEntry = &zipInputStream.getNextEntry(); | |
| Local JavaObject &buf = CreateJavaArray("byte[]", 1024); | |
| Local number &byteCount; | |
| While &zipEntry <> Null; | |
| If (&zipEntry.isDirectory()) Then; | |
| REM ** do nothing; | |
| Else | |
| Local JavaObject &outFile = CreateJavaObject("java.io.<File", &targetDir | &zipEntry.getName()); | |
| &outFile.getParentFile().mkdirs(); | |
| Local JavaObject &out = CreateJavaObject("java.io.FileOutputStream", &outFile); | |
| &byteCount = &zipInputStream.read(&buf); | |
| While &byteCount > 0; | |
| &out.write(&buf, 0, &byteCount); | |
| &byteCount = &zipInputStream.read(&buf); | |
| End-While; | |
| &zipInputStream.closeEntry(); | |
| End-If; | |
| &zipEntry = &zipInputStream.getNextEntry(); | |
| End-While; | |
| &zipInputStream.close(); | |
| &zipFileInputStream.close(); | |
| End-Function; | |
| unzip("/tmp/myzipfile.zip", "/tmp/out"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment