Here you can find the source of getZipEntry(final ZipFile zipFile, final CharSequence zippedName)
Parameter | Description |
---|---|
zipFile | The ZipFile to retrieve the entry for. |
zippedName | The /-delimited pathname of the entry. |
@Nullable public static ZipEntry getZipEntry(final ZipFile zipFile, final CharSequence zippedName)
//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; } }