Java Zip Files addToZip(File input, String entryName, ZipOutputStream zos, boolean withHidden, Set excludeEntries)

Here you can find the source of addToZip(File input, String entryName, ZipOutputStream zos, boolean withHidden, Set excludeEntries)

Description

add To Zip

License

Open Source License

Declaration

private static void addToZip(File input, String entryName, ZipOutputStream zos, boolean withHidden,
            Set<String> excludeEntries) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;

import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public class Main {
    private static void addToZip(File input, String entryName, ZipOutputStream zos, boolean withHidden,
            Set<String> excludeEntries) throws IOException {
        if (input.isHidden() && !withHidden)
            return;
        if (input.isDirectory()) {
            if (entryName.length() > 0)
                entryName += "/";
            for (File f : input.listFiles())
                addToZip(f, entryName + f.getName(), zos, withHidden, excludeEntries);
        } else if (input.isFile()) {
            if (excludeEntries != null && excludeEntries.contains(entryName))
                return;
            FileInputStream fis = null;
            try {
                byte[] buffer = new byte[10000];
                fis = new FileInputStream(input);
                zos.putNextEntry(new ZipEntry(entryName));
                int length;
                while ((length = fis.read(buffer)) > 0)
                    zos.write(buffer, 0, length);
                zos.closeEntry();/*w  ww.ja v a  2s  . co m*/
            } finally {
                try {
                    if (fis != null)
                        fis.close();
                } catch (Exception ignore) {
                }
            }
        }
    }
}

Related

  1. addFileToZipOutputStream(File file, ZipOutputStream zipOs)
  2. addToZip(byte[] zip, String file, String fileName)
  3. addToZip(File directoryToZip, File file, ZipOutputStream zos)
  4. addToZip(File f, int truncate, ZipOutputStream os, byte[] buff)
  5. addToZip(File file, ZipOutputStream out, String folder)
  6. addToZip(String path, String srcFile, ZipOutputStream zip)
  7. addToZip(String path, String srcFile, ZipOutputStream zip)
  8. addToZip(String[] sourceFiles, ZipOutputStream output)
  9. addToZip(ZipOutputStream zos, String rootDirectoryName, String fileName)