Java Utililty Methods Zip File List

List of utility methods to do Zip File List

Description

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

Method

voidzipFiles(File[] dirList, ZipOutputStream zos)
Utility to zip a set of files to a ZipOutputStream
byte[] readBuffer = new byte[2156];
int bytesIn = 0;
for (File f : dirList) {
    if (f.isDirectory())
        continue;
    FileInputStream fis = new FileInputStream(f);
    ZipEntry anEntry = new ZipEntry(f.getName());
    zos.putNextEntry(anEntry);
...
voidzipFiles(File[] listFiles2Zip, File output)
zip Files
byte[] buf = new byte[1024];
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(output));
for (File actualFile : listFiles2Zip) {
    FileInputStream in = new FileInputStream(actualFile);
    out.putNextEntry(new ZipEntry(actualFile.getName()));
    int len;
    while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
...
voidzipFiles(final File outputFile, final File[] files)
Create a zip file.
if (outputFile == null || files == null)
    return;
final byte[] buf = new byte[ZIP_BUFFER];
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outputFile));
for (int i = 0; i < files.length; i++) {
    final File f = files[i];
    if (f == null)
        continue;
...
voidzipFiles(List files, File output)
Create a ZIP archive of a list of files.
try {
    FileOutputStream fos = new FileOutputStream(output);
    ZipOutputStream zos = new ZipOutputStream(fos);
    Collections.sort(files, new Comparator<File>() {
        @Override
        public int compare(File f1, File f2) {
            return f1.getAbsolutePath().compareTo(f2.getAbsolutePath());
    });
    File baseDirectory = files.get(0).getParentFile();
    Deque<File> entries = new ArrayDeque<File>(files);
    while (!entries.isEmpty()) {
        File entry = entries.poll();
        if (entry.isDirectory()) {
            for (File current : entry.listFiles()) {
                entries.add(current);
        } else if (entry.isFile()) {
            ZipEntry ze = new ZipEntry(
                    entry.getAbsolutePath().substring(baseDirectory.getAbsolutePath().length() + 1));
            zos.putNextEntry(ze);
            FileInputStream in = new FileInputStream(entry);
            byte[] buffer = new byte[1024];
            int len;
            while ((len = in.read(buffer)) > 0) {
                zos.write(buffer, 0, len);
            in.close();
    zos.closeEntry();
    zos.close();
} catch (IOException ioe) {
    ioe.printStackTrace();
voidzipFiles(List files, OutputStream os)
Zip a set of files.
FileInputStream in = null;
ZipOutputStream zos = new ZipOutputStream(os);
for (File file : files) {
    ZipEntry ze = new ZipEntry(file.getName());
    zos.putNextEntry(ze);
    try {
        byte[] buffer = new byte[1024];
        in = new FileInputStream(file.getAbsolutePath());
...
voidzipFiles(List srcfile, File zipfile)
zip Files
byte[] buf = new byte[4096];
try {
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipfile));
    for (File file : srcfile) {
        FileInputStream in = new FileInputStream(file);
        out.putNextEntry(new ZipEntry(file.getName()));
        int len;
        while ((len = in.read(buf)) > 0) {
...
voidZipFiles(String destination, Vector files)
Compress a list of files in a .zip file
byte[] buf = new byte[1024];
try {
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(destination));
    for (int i = 0; i < files.size(); i++) {
        String fichero = (String) files.elementAt(i);
        File file = new File(fichero);
        if (file.isDirectory()) {
            out.putNextEntry(new ZipEntry(fichero));
...
voidzipFiles(String filename, String[] files)
zip Files
ZipOutputStream zip = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(filename)));
byte[] buffer = new byte[10000];
for (int i = 0; i < files.length; i++) {
    File f = new File(files[i]);
    if (f.exists()) {
        BufferedInputStream in = new BufferedInputStream(new FileInputStream(files[i]));
        zip.putNextEntry(new ZipEntry(files[i]));
        boolean done = false;
...
byte[]zipFiles(String files[], String fielPath)
zip Files
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(bout);
zos.setLevel(6);
byte[] bytes = new byte[10000];
for (int i = 0; i < files.length; i++) {
    FileInputStream fis = new FileInputStream(fielPath + "\\" + files[i]);
    BufferedInputStream bis = new BufferedInputStream(fis);
    zos.putNextEntry(new ZipEntry(files[i]));
...
voidzipFiles(String filesPathToZip, String pathToSave)
zip Files
File filesToZip = new File(filesPathToZip);
ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(new File(pathToSave)));
try {
    archiveFile(null, zos, filesToZip);
} finally {
    zos.close();