public void extractTo(ZipArchiveInputStream zis, ArchiveEntry entry) throws IOException { int count = 0; int curCount = 0; byte[] data = new byte[BUFFER]; while ((count = zis.read(data, 0, BUFFER)) != -1) { curCount += count; processInputData(entry.getName(), curCount); } }
private void extract(final String inputFile, final String outputDir) throws IOException { FileInputStream fileInputStream = null; ZipArchiveInputStream zipArchiveInputStream = null; FileOutputStream fileOutputStream = null; try { Log.d(this.getClass().getName(), "Will extract " + inputFile + " to " + outputDir); byte[] buffer = new byte[8192]; fileInputStream = new FileInputStream(inputFile); // We use null as encoding. zipArchiveInputStream = new ZipArchiveInputStream(fileInputStream, null, true); ArchiveEntry entry; while ((entry = zipArchiveInputStream.getNextEntry()) != null) { Log.d(this.getClass().getName(), "Extracting entry " + entry.getName()); File file = new File(outputDir, entry.getName()); if (entry.isDirectory()) { file.mkdirs(); } else { file.getParentFile().mkdirs(); fileOutputStream = new FileOutputStream(file); int bytesRead; while ((bytesRead = zipArchiveInputStream.read(buffer, 0, buffer.length)) != -1) fileOutputStream.write(buffer, 0, bytesRead); fileOutputStream.close(); fileOutputStream = null; } } // Delete the zip file File zipFile = new File(inputFile); zipFile.delete(); } catch (Exception e) { Log.e("UnzipperTask", "Error unzipping file: " + inputFile + ", " + e); } finally { try { zipArchiveInputStream.close(); fileInputStream.close(); if (fileOutputStream != null) { fileOutputStream.close(); } } catch (NullPointerException ex) { Log.e(this.getClass().getName(), "Error closing the file streams.", ex); } catch (IOException ex) { Log.e(this.getClass().getName(), "Error closing the file streams.", ex); } } }