com.couchbase.lite.util.ZipUtils Maven / Gradle / Ivy
package com.couchbase.lite.util;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
/**
* Created by hideki on 8/27/15.
*/
public class ZipUtils {
public static void unzip(InputStream in, File destination) throws IOException {
byte[] buffer = new byte[1024];
ZipInputStream zis = new ZipInputStream(in);
ZipEntry ze = zis.getNextEntry();
while (ze != null) {
String fileName = ze.getName();
File newFile = new File(destination, fileName);
if (ze.isDirectory()) {
newFile.mkdirs();
} else {
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();
in.close();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy