Java ZipEntry Read getZipEntry(ZipFile jarFile, String path)

Here you can find the source of getZipEntry(ZipFile jarFile, String path)

Description

get Zip Entry

License

Open Source License

Declaration

public static ZipEntry getZipEntry(ZipFile jarFile, String path) 

Method Source Code

//package com.java2s;
/*/*from   www  .  j a v a 2  s .  co m*/
 * SK's Minecraft Launcher
 * Copyright (C) 2010-2014 Albert Pham <http://www.sk89q.com> and contributors
 * Please see LICENSE.txt for license information.
 */

import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class Main {
    public static ZipEntry getZipEntry(ZipFile jarFile, String path) {
        Enumeration<? extends ZipEntry> entries = jarFile.entries();
        String expected = normalizePath(path);

        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            String test = normalizePath(entry.getName());
            if (expected.equals(test)) {
                return entry;
            }
        }

        return null;
    }

    public static String normalizePath(String path) {
        return path.replaceAll("^[/\\\\]*", "").replaceAll("[/\\\\]+", "/");
    }
}

Related

  1. getZipEntry(File f, String nameToRead, String fileName)
  2. getZipEntry(final ZipFile zipFile, final CharSequence zippedName)
  3. getZipEntry(String name, ZipFile zipFile)
  4. getZipEntry(String zipEntryName)
  5. getZipEntry(String zipFileLoc)
  6. getZipEntry(ZipFile zip, final String name)
  7. getZipEntry(ZipFile zip, String name)
  8. getZipEntryAsString(File archive, String name)
  9. getZipEntryAsString(InputStream is)