Guest User

Untitled

a guest
Jan 14th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. private class Decompress extends AsyncTask<Void, Integer, Integer> {
  2.  
  3. private String _zipFile;
  4. private String _location;
  5. private int per = 0;
  6.  
  7. public Decompress(String zipFile, String location) {
  8. _zipFile = zipFile;
  9. _location = location;
  10. _dirChecker("");
  11. }
  12.  
  13. protected Integer doInBackground() {
  14. try {
  15. ZipFile zip = new ZipFile(_zipFile);
  16. bar.setMax(zip.size());
  17. FileInputStream fin = new FileInputStream(_zipFile);
  18. ZipInputStream zin = new ZipInputStream(fin);
  19. ZipEntry ze = null;
  20. while ((ze = zin.getNextEntry()) != null) {
  21.  
  22. Log.v("Decompress", "Unzipping " + ze.getName());
  23. if(ze.isDirectory()) {
  24. _dirChecker(ze.getName());
  25. } else {
  26. // Here I am doing the update of my progress bar
  27.  
  28. per++;
  29. publishProgress(per);
  30.  
  31. FileOutputStream fout = new FileOutputStream(_location +ze.getName());
  32. for (int c = zin.read(); c != -1; c = zin.read()) {
  33.  
  34. fout.write(c);
  35. }
  36. zin.closeEntry();
  37. fout.close();
  38. }
  39. }
  40. zin.close();
  41. } catch(Exception e) {
  42. Log.e("Decompress", "unzip", e);
  43. }
  44. }
  45.  
  46.  
  47. }
  48. return totalSize;
  49. }
  50.  
  51. protected void onProgressUpdate(Integer... progress) {
  52. bar.setProgress(per); //Since it's an inner class, Bar should be able to be called directly
  53. }
  54.  
  55. protected void onPostExecute(Integer... result) {
  56. Log.i("Completed. Total size: "+result);
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment