Java Unzip File uncompressZipEntry(ZipInputStream zis, ZipEntry zipEntry, String dest)

Here you can find the source of uncompressZipEntry(ZipInputStream zis, ZipEntry zipEntry, String dest)

Description

uncompress Zip Entry

License

Open Source License

Declaration

private static long uncompressZipEntry(ZipInputStream zis,
            ZipEntry zipEntry, String dest) throws Exception 

Method Source Code

//package com.java2s;
/*/*from  w  w w  .  j  a  va2  s .c  o  m*/
 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of the License "Eclipse Public License v1.0"
 * which accompanies this distribution, and is available
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
 *
 * Initial Contributors:
 * Nokia Corporation - initial contribution.
 *
 * Contributors:
 *            Deniz TURAN
 * Description: 
 *             
 */

import java.io.File;
import java.io.FileOutputStream;

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

public class Main {
    private static long uncompressZipEntry(ZipInputStream zis,
            ZipEntry zipEntry, String dest) throws Exception {
        byte[] buf = new byte[1024];
        String entryName = zipEntry.getName();
        int n;
        File rootDir = new File(dest);
        FileOutputStream fileoutputstream;
        File newFile = new File(rootDir, entryName);
        long totalLen = 0;

        if (zipEntry.isDirectory()) {
            if (!newFile.exists()) {
                newFile.mkdir();
            }
            return 0;
        }
        fileoutputstream = new FileOutputStream(newFile);

        while ((n = zis.read(buf, 0, 1024)) > -1) {
            fileoutputstream.write(buf, 0, n);
            totalLen += n;
        }

        fileoutputstream.close();
        zis.closeEntry();
        return totalLen;
    }
}

Related

  1. uncompress(String str)
  2. uncompress(ZipInputStream zipIn)
  3. uncompressDirectory(File zipSource, File target)
  4. uncompressEveryFileFromDirectory(File srcPath, File dstPath)
  5. unCompressGzipFile(String path)
  6. unzip(File aFile)
  7. unzip(File archive)
  8. unzip(File archive, File output)
  9. unzip(File archiveFile, File destination)