-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added support to download and extract zip file.
- Loading branch information
Showing
3 changed files
with
131 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
61 changes: 61 additions & 0 deletions
61
core/src/main/java/com/jukusoft/updater/utils/ZIPUtils.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.jukusoft.updater.utils; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.util.zip.ZipEntry; | ||
import java.util.zip.ZipInputStream; | ||
|
||
/** | ||
* Created by Justin on 23.04.2017. | ||
*/ | ||
public class ZIPUtils { | ||
|
||
public static boolean unZipIt(String zipFile, String outputFolder){ | ||
|
||
byte[] buffer = new byte[1024]; | ||
|
||
try { | ||
//get the zip file content | ||
ZipInputStream zis = | ||
new ZipInputStream(new FileInputStream(zipFile)); | ||
//get the zipped file list entry | ||
ZipEntry ze = zis.getNextEntry(); | ||
|
||
while(ze!=null){ | ||
|
||
String fileName = ze.getName(); | ||
File newFile = new File(outputFolder + File.separator + fileName); | ||
|
||
System.out.println("file unzip : "+ newFile.getAbsoluteFile()); | ||
|
||
//create all non exists folders | ||
//else you will hit FileNotFoundException for compressed folder | ||
new File(newFile.getParent()).mkdirs(); | ||
|
||
FileOutputStream fos = new FileOutputStream(newFile); | ||
|
||
int len; | ||
while ((len = zis.read(buffer)) > 0) { | ||
fos.write(buffer, 0, len); | ||
} | ||
|
||
fos.close(); | ||
ze = zis.getNextEntry(); | ||
} | ||
|
||
zis.closeEntry(); | ||
zis.close(); | ||
|
||
System.out.println("Done"); | ||
} catch(IOException ex){ | ||
ex.printStackTrace(); | ||
|
||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} |