Java Zip Folder doZip(Properties properties, String name, File f)

Here you can find the source of doZip(Properties properties, String name, File f)

Description

same as above given a .zip or .jar file object.

License

Open Source License

Declaration

static boolean doZip(Properties properties, String name, File f) 

Method Source Code


//package com.java2s;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import java.io.IOException;
import java.util.Properties;

import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class Main {
    /**//from w ww  .  j ava  2  s. co m
     * same as above given a .zip or .jar file object. The difference with
     * this method is that the search does not go deeper than the top level;
     * ie. no directory recursion is done.
     */
    static boolean doZip(Properties properties, String name, File f) {
        ZipInputStream zip;
        try {
            zip = new ZipInputStream(new FileInputStream(f));
        } catch (FileNotFoundException x) {
            return false;
        }
        boolean result = false;
        ZipEntry ze;
        try {
            while ((ze = zip.getNextEntry()) != null) {
                if (ze.isDirectory())
                    continue;
                String it = ze.getName();
                int n;
                if (it.endsWith(name)) {
                    ByteArrayOutputStream out = new ByteArrayOutputStream(2048);
                    byte[] buffer = new byte[512];
                    while ((n = zip.read(buffer)) != -1)
                        out.write(buffer, 0, n);
                    BufferedInputStream in = new BufferedInputStream(new ByteArrayInputStream(out.toByteArray()));
                    properties.load(in);
                    in.close();
                    result = true;
                    break;
                }
            }
        } catch (IOException x1) {
        } finally {
            try {
                zip.close();
            } catch (IOException x2) {
            }
        }
        return result;
    }
}

Related

  1. addFolderToZip(String path, String srcFolder, ZipOutputStream zip, boolean addFolder)
  2. addFolderToZip(String path, String srcFolder, ZipOutputStream zip, boolean includeFullPath)
  3. addFolderToZip(String pathInsideZip, final File folderToZip, final ZipOutputStream outZip)
  4. doZip(File fileIn, String fileOut)
  5. doZip(Map zipStructure, File zipFile)
  6. doZip(String baseDir, String fileName)
  7. doZip(String filename, String zipFileName)
  8. doZip(String inFilePath, String outFilePath)
  9. doZipFile(ZipOutputStream zipOut, File file, String dirPath)