Decompress.java 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package de.tudarmstadt.informatik.hostage.system;
  2. import android.util.Log;
  3. import java.io.File;
  4. import java.io.FileInputStream;
  5. import java.io.FileOutputStream;
  6. import java.util.zip.ZipEntry;
  7. import java.util.zip.ZipInputStream;
  8. /**
  9. * Created by shankar on 16.05.14.
  10. */
  11. public class Decompress {
  12. private String _zipFile;
  13. private String _location;
  14. public Decompress(String zipFile, String location) {
  15. _zipFile = zipFile;
  16. _location = location;
  17. _dirChecker("");
  18. }
  19. public void unzip() {
  20. try {
  21. FileInputStream fin = new FileInputStream(_zipFile);
  22. ZipInputStream zin = new ZipInputStream(fin);
  23. ZipEntry ze = null;
  24. while ((ze = zin.getNextEntry()) != null) {
  25. Log.v("Decompress", "Unzipping " + ze.getName());
  26. if(ze.isDirectory()) {
  27. _dirChecker(ze.getName());
  28. } else {
  29. FileOutputStream fout = new FileOutputStream(_location + ze.getName());
  30. for (int c = zin.read(); c != -1; c = zin.read()) {
  31. fout.write(c);
  32. }
  33. zin.closeEntry();
  34. fout.close();
  35. }
  36. }
  37. zin.close();
  38. } catch(Exception e) {
  39. Log.e("Decompress", "unzip", e);
  40. }
  41. }
  42. private void _dirChecker(String dir) {
  43. File f = new File(_location + dir);
  44. if(!f.isDirectory()) {
  45. f.mkdirs();
  46. }
  47. }
  48. }