public static boolean unzip(final File zipFile, final File destRootFolder, final boolean flatten, final Callback.a1<Float> progressCallback) { try { final float knownLength = progressCallback == null ? -1f : getZipLength(zipFile); return unzip(new FileInputStream(zipFile), destRootFolder, flatten, progressCallback, knownLength); } catch (IOException ignored) { return false; } }
private static void addFolderToZip(String pathInsideZip, final File folderToZip, final ZipOutputStream outZip) throws IOException { pathInsideZip = pathInsideZip.isEmpty() ? folderToZip.getName() : pathInsideZip + "/" + folderToZip.getName(); File[] files = folderToZip.listFiles(); if (files != null) { for (File file : files) addFileToZip(pathInsideZip, file, outZip); } } }
public static void zipFolder(final File srcFolder, final OutputStream out) throws IOException { ZipOutputStream outZip = null; try { outZip = new ZipOutputStream(out); addFolderToZip("", srcFolder, outZip); } finally { if (outZip != null) { try { outZip.close(); } catch (IOException ignored) { } } } }
public static boolean unzip(final File zipFile, final File destRootFolder, boolean flatten) { return unzip(zipFile, destRootFolder, flatten, null); }
public void exportZip(OutputStream output) { try { ZipUtils.zipFolder(mRoot, output); } catch (IOException e) { e.printStackTrace(); } }
ZipUtils.unzip(inputStream, dir, false, null, -1f);
ZipUtils.unzip(getIndexFile("jar"), mRoot, true, new Callback.a1<Float>() { @Override public void callback(Float progress) {
private static void addFileToZip(final String pathInsideZip, final File fileToZip, final ZipOutputStream outZip) throws IOException { if (fileToZip.isDirectory()) { addFolderToZip(pathInsideZip, fileToZip, outZip); } else { FileInputStream in = null; try { in = new FileInputStream(fileToZip); outZip.putNextEntry(new ZipEntry(pathInsideZip + "/" + fileToZip.getName())); int count; byte[] buffer = new byte[BUFFER_SIZE]; while ((count = in.read(buffer)) > 0) outZip.write(buffer, 0, count); } finally { if (in != null) { try { in.close(); } catch (IOException ignored) { } } } } }