Java ZipEntry Read getZipEntry(final ZipFile zipFile, final CharSequence zippedName)

Here you can find the source of getZipEntry(final ZipFile zipFile, final CharSequence zippedName)

Description

A sane way of retrieving an entry from a ZipFile based on its /-delimited path name.

License

Apache License

Parameter

Parameter Description
zipFile The ZipFile to retrieve the entry for.
zippedName The /-delimited pathname of the entry.

Return

The for the pathname or null if none was present.

Declaration

@Nullable
public static ZipEntry getZipEntry(final ZipFile zipFile, final CharSequence zippedName) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Enumeration;

import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import javax.annotation.Nullable;

public class Main {
    private static final Pattern PATH_SEPARATORS = Pattern.compile("[\\\\/]+");

    /**//www .  j  av a2  s.c  o  m
     * A sane way of retrieving an entry from a {@link ZipFile} based on its /-delimited path name.
     *
     * @param zipFile    The {@link ZipFile} to retrieve the entry for.
     * @param zippedName The /-delimited pathname of the entry.
     *
     * @return The {@link ZipEntry} for the pathname or {@code null} if none was present.
     */
    @Nullable
    public static ZipEntry getZipEntry(final ZipFile zipFile, final CharSequence zippedName) {

        Enumeration<? extends ZipEntry> entries = zipFile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            if (PATH_SEPARATORS.matcher(entry.getName()).replaceAll("/")
                    .equals(PATH_SEPARATORS.matcher(zippedName).replaceAll("/")))
                return entry;
        }

        return null;
    }
}

Related

  1. getNextZipEntry(ZipInputStream in)
  2. getSimpleName(ZipEntry entry)
  3. getZipEntry(File f, String nameToRead, String fileName)
  4. getZipEntry(String name, ZipFile zipFile)
  5. getZipEntry(String zipEntryName)
  6. getZipEntry(String zipFileLoc)
  7. getZipEntry(ZipFile jarFile, String path)