Java ZipEntry Read getZipEntryStream(File zipFile, String entryName)

Here you can find the source of getZipEntryStream(File zipFile, String entryName)

Description

get Zip Entry Stream

License

Open Source License

Parameter

Parameter Description
zipFile a parameter
entryName a parameter

Exception

Parameter Description
IOException an exception

Return

A Zip Entry Stream

Declaration

public static InputStream getZipEntryStream(File zipFile, String entryName) throws IOException 

Method Source Code

//package com.java2s;
/**/*  w w  w  . j a v  a 2 s  .co  m*/
 * This program and the accompanying materials
 * are made available under the terms of the License
 * which accompanies this distribution in the file LICENSE.txt
 */

import java.io.BufferedInputStream;

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

import java.io.IOException;
import java.io.InputStream;

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

public class Main {
    /**
     * @param zipFile
     * @param entryName
     * @return A Zip Entry Stream
     * @throws IOException
     */
    public static InputStream getZipEntryStream(File zipFile, String entryName) throws IOException {
        ZipEntry zipEntry;
        ZipInputStream zIn;

        BufferedInputStream in = new BufferedInputStream(new FileInputStream(zipFile));
        zIn = new ZipInputStream(in);

        // Get zip entry
        while ((zipEntry = zIn.getNextEntry()) != null) {
            String zipEntryName = zipEntry.getName();
            if (zipEntryName.equalsIgnoreCase(entryName)) {
                break;
            }
            zIn.closeEntry();
        }

        // If we didn't get it return null
        if (zipEntry == null) {
            try {
                zIn.close();
            } catch (IOException ex) {
            }
            return null;
        }

        return zIn;
    }
}

Related

  1. getZipEntryContent(final File zip, final String entry)
  2. getZipEntryFileName(final ZipEntry zipEntry)
  3. getZipEntryName(int pathOffset, String absolutePath)
  4. getZipEntryNames(File zipFile)
  5. getZipEntryPath(File f, String archiveSourceDir)
  6. getZipEntryStreamOrThrow(File file, String filenamePart)