Java Utililty Methods Zip File

List of utility methods to do Zip File

Description

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

Method

booleanzip(String src, String des)
zip
boolean result;
ZipOutputStream out = null;
try {
    File f = new File(src);
    out = new ZipOutputStream(new FileOutputStream(des));
    zip(out, f, "");
    f.delete();
    result = true;
...
voidzip(String src, String dest, PrintStream stream)
zip
src = src.replace("~", System.getProperty("user.home"));
dest = dest.replace("~", System.getProperty("user.home"));
File srcFile = new File(src);
if (!srcFile.exists()) {
    throw new RuntimeException(src + " does not exist.");
ZipOutputStream zos = new ZipOutputStream(new CheckedOutputStream(new FileOutputStream(dest), new CRC32()));
innerZip(zos, srcFile, null, stream);
...
voidzip(String srcPath)
zip
int end = srcPath.lastIndexOf(File.separator);
String targetPath = srcPath.substring(0, end);
String zipName = srcPath.substring(end + 1);
zip(srcPath, targetPath, zipName);
Filezip(String zipFileName, Map entries)
Zips every file in and under the given directory.
byte[] buffer = new byte[1024];
File zipFile = new File(zipFileName);
FileOutputStream fos = new FileOutputStream(zipFile);
ZipOutputStream zos = new ZipOutputStream(fos);
for (Map.Entry<String, InputStream> entry : entries.entrySet()) {
    zos.putNextEntry(new ZipEntry(entry.getKey()));
    InputStream input = entry.getValue();
    int length;
...
voidzip(String zipFileName, String inputFile)
zip
zip(zipFileName, new File(inputFile));
voidzip(String zipFileName, String[] zipEntries)
zip
String currentDirectory = System.getProperty("user.dir");
try (ZipOutputStream zos = new ZipOutputStream(
        new BufferedOutputStream(new FileOutputStream(zipFileName)))) {
    zos.setLevel(Deflater.BEST_COMPRESSION);
    for (int i = 0; i < zipEntries.length; i++) {
        File entryFile = new File(zipEntries[i]);
        if (!entryFile.exists()) {
            System.out.println("The entry file " + entryFile.getAbsolutePath() + " does not exist");
...
voidzip(String zipName, String[] fileNames, boolean path)
zip
int pathMode;
if (path)
    pathMode = ABSOLUTE_PATH;
else
    pathMode = NO_PATH;
String[] relativePaths = null;
zip(zipName, fileNames, pathMode, relativePaths);
voidzip(String zipPath, Map input)
Create a zip file and add contents.
ZipOutputStream zip = null;
try {
    zip = new ZipOutputStream(new FileOutputStream(zipPath));
    for (Map.Entry<File, FileFilter> e : input.entrySet()) {
        zip(zip, e.getKey(), e.getKey().getPath().length() + 1, e.getValue());
} finally {
    if (zip != null) {
...
FilezipFile(File aFileToZip)
Gets a File and creates on the same directory with the same level a new ziped version.
File target = null;
if (aFileToZip.exists() && aFileToZip.isFile()) {
    byte[] buffer = new byte[1024];
    target = new File(aFileToZip.getName() + ".zip");
    try (FileInputStream in = new FileInputStream(aFileToZip);
            FileOutputStream fos = new FileOutputStream(target);
            BufferedOutputStream bos = new BufferedOutputStream(fos);
            ZipOutputStream zos = new ZipOutputStream(bos)) {
...
voidzipFile(File file)
zip File
if (file.isDirectory()) {
    if (file.getName().equalsIgnoreCase(".metadata") || file.getName().equalsIgnoreCase("Libraries")
            || file.getName().equalsIgnoreCase("RepositoryBuild")
            || file.getName().equalsIgnoreCase("images")) {
        return;
    File list[] = file.listFiles();
    for (int i = 0; i < list.length; i++) {
...