Android Utililty Methods Zip Directory

List of utility methods to do Zip Directory

Description

The list of methods to do Zip Directory are organized into topic(s).

Method

voidzipDirectory(File p2BeZippedDir, File pZipFile)
zip Directory
if (p2BeZippedDir == null) {
    throw new IllegalArgumentException(
            "parameter p2BeZippedDir must not be null");
if (!p2BeZippedDir.isDirectory()) {
    throw new IllegalArgumentException(
            "parameter p2BeZippedDir has to be a directory");
if (pZipFile == null) {
    throw new IllegalArgumentException(
            "parameter pZipFile must not be null");
if (pZipFile.isDirectory()) {
    throw new IllegalArgumentException(
            "parameter pZipFile has to be a file and not a directory");
Vector<File> lFileList = find(p2BeZippedDir, ".+");
String lDirName = p2BeZippedDir.getAbsolutePath();
int lBegin = lDirName.length() + 1;
String lEntryName = null;
try {
    boolean lIsEntryWritten = false;
    pZipFile.delete();
    FileOutputStream lFOS = new FileOutputStream(pZipFile);
    BufferedOutputStream lBOS = new BufferedOutputStream(lFOS);
    ZipOutputStream lZOS = new ZipOutputStream(lBOS);
    for (File lFile : lFileList) {
        if (lFile.isFile()) {
            lIsEntryWritten = true;
            lEntryName = lFile.getAbsolutePath();
            lEntryName = "/" + lEntryName.substring(lBegin);
            lEntryName = lEntryName.replaceAll("\\\\", "/");
            ZipEntry lZipEntry = new ZipEntry(lEntryName);
            lZOS.putNextEntry(lZipEntry);
            FileInputStream lFIS = new FileInputStream(lFile);
            BufferedInputStream lBIS = new BufferedInputStream(lFIS);
            copy(lBIS, lZOS);
            lZOS.closeEntry();
    if (!lIsEntryWritten) {
        lZOS.putNextEntry(new ZipEntry("ZipFileIsEmpty"));
        lZOS.closeEntry();
    lZOS.close();
} catch (ZipException e) {
    throw new RuntimeException("could not zip entry:" + lEntryName,
            e);
} catch (IOException e) {
    throw new RuntimeException(e);
voidzip(File directory, File base, ZipOutputStream zos)
zip
File[] files = directory.listFiles();
byte[] buffer = new byte[8192];
int read = 0;
for (int i = 0, n = files.length; i < n; i++) {
    if (files[i].isDirectory()) {
        zip(files[i], base, zos);
    } else {
        FileInputStream in = new FileInputStream(files[i]);
...
voidzip(File directory, File base, ZipOutputStream zos)
zip
File[] files = directory.listFiles();
byte[] buffer = new byte[8192];
int read = 0;
for (int i = 0, n = files.length; i < n; i++) {
    if (files[i].isDirectory()) {
        zip(files[i], base, zos);
    } else {
        FileInputStream in = new FileInputStream(files[i]);
...
voidzipFolder(ZipOutputStream zos, File folder, int baseLength)
zip Folder
if (zos == null || folder == null) {
    return;
File[] fileList = folder.listFiles();
if (fileList == null || fileList.length == 0) {
    return;
for (File file : fileList) {
...