Example usage for java.util.zip ZipEntry getName

List of usage examples for java.util.zip ZipEntry getName

Introduction

In this page you can find the example usage for java.util.zip ZipEntry getName.

Prototype

public String getName() 

Source Link

Document

Returns the name of the entry.

Usage

From source file:Utils.java

/**
 * Validate that an archive contains a named entry
 * //from   w  w  w .  j  ava  2  s  .co m
 * @param theFile
 * @param name
 * @return true if the entry exists
 * @throws IOException
 */
public static boolean archiveContainsEntry(File theFile, String name) throws IOException {
    boolean result = false;
    ZipFile zipFile;
    zipFile = new ZipFile(theFile);
    for (Enumeration entries = zipFile.entries(); entries.hasMoreElements();) {
        ZipEntry entry = (ZipEntry) entries.nextElement();
        if (entry.getName().equals(name)) {
            result = true;
            break;
        }
    }
    zipFile.close();
    return result;
}

From source file:Main.java

public static ZipFile readZipEntriesForElectric(File archive,
        final HashMap<String, ZipEntry> compressionEntries) {
    ZipFile zipfile = null;/*w w w .j  a  v  a 2s. co  m*/
    try {
        zipfile = new ZipFile(archive);
        for (Enumeration<?> e = zipfile.entries(); e.hasMoreElements();) {
            ZipEntry entry = (ZipEntry) e.nextElement();

            if (!entry.getName().contains("MACOSX")) {
                compressionEntries.put(entry.getName(), entry);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {

    }
    return zipfile;
}

From source file:Main.java

public static void extractEntryContent(ZipInputStream zis, ZipEntry entry, String unzipdir)
        throws IOException, FileNotFoundException {

    String entryFileName = entry.getName();
    String entryPath = unzipdir + File.separator + entryFileName;

    createFile(entryPath);//from   w w w. ja  v  a 2s. c  o m

    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(entryPath));

    byte[] buffer = new byte[1024];
    int count = -1;
    while ((count = zis.read(buffer)) != -1) {
        bos.write(buffer, 0, count);
    }

    bos.close();
}

From source file:Main.java

public static ZipInputStream getFileFromZip(InputStream zipFileStream) throws IOException {
    ZipInputStream zis = new ZipInputStream(zipFileStream);
    ZipEntry ze;
    while ((ze = zis.getNextEntry()) != null) {
        Log.w("AssetUtil", "extracting file: '" + ze.getName() + "'...");
        return zis;
    }/* w w  w.j  av  a2  s .c o  m*/
    return null;
}

From source file:Main.java

public static String[] getXmlFiles(String path) {
    List<String> xmlFiles = new ArrayList<>();
    ZipFile zipFile = null;//from  w w w. j  a  va  2s.  c o  m
    try {
        zipFile = new ZipFile(path);
        Enumeration<? extends ZipEntry> entries = zipFile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            String name = entry.getName();
            if (name.endsWith(".xml") && !name.equals("AndroidManifest.xml")) {
                xmlFiles.add(name);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (zipFile != null) {
            try {
                zipFile.close();
            } catch (IOException ignored) {
            }
        }
    }
    Collections.sort(xmlFiles);
    return xmlFiles.toArray(new String[xmlFiles.size()]);
}

From source file:com.skcraft.launcher.builder.BuilderUtils.java

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;
        }/*from ww  w .j a  v  a2  s .  c  o  m*/
    }

    return null;
}

From source file:Main.java

/**
 * To check if the apk file is available to install.
 * /*from  www  .  ja va  2 s.  com*/
 * @param apkFilePath the apk file path
 * @return            true if available, otherwise return false
 */
public static boolean isApkAvailable(String apkFilePath) {
    File apkFile = new File(apkFilePath);
    if (!apkFile.exists()) {
        return false;
    }

    try {
        ZipFile zipFile = new ZipFile(apkFile);
        Enumeration<? extends ZipEntry> entries = zipFile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry zipEntry = entries.nextElement();
            if (APK_MANIFEST.equals(zipEntry.getName())) {
                zipFile.close();
                return true;
            }
        }

        zipFile.close();
    } catch (Exception e) {
        return false;
    }

    return false;
}

From source file:net.bpelunit.util.ZipUtil.java

public static void unzipFile(File zip, File dir) throws IOException {
    InputStream in = null;/*from   www .j  av  a2  s  . c  o  m*/
    OutputStream out = null;
    ZipFile zipFile = new ZipFile(zip);
    Enumeration<? extends ZipEntry> entries = zipFile.entries();

    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();
        if (!entry.getName().endsWith("/")) {
            File unzippedFile = new File(dir, entry.getName());
            try {
                in = zipFile.getInputStream(entry);
                unzippedFile.getParentFile().mkdirs();

                out = new FileOutputStream(unzippedFile);

                IOUtils.copy(in, out);
            } finally {
                IOUtils.closeQuietly(in);
                IOUtils.closeQuietly(out);
            }
        }
    }
}

From source file:b2s.idea.mavenize.JarCombiner.java

private static boolean isServiceEntry(ZipEntry entry) {
    return entry.getName().startsWith("META-INF/services/");
}

From source file:com.blackducksoftware.integration.hub.detect.util.DetectZipUtil.java

public static void unzip(File zip, File dest, Charset charset) throws IOException {
    Path destPath = dest.toPath();
    try (ZipFile zipFile = new ZipFile(zip, ZipFile.OPEN_READ, charset)) {
        Enumeration<? extends ZipEntry> entries = zipFile.entries();
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            Path entryPath = destPath.resolve(entry.getName());
            if (!entryPath.normalize().startsWith(dest.toPath()))
                throw new IOException("Zip entry contained path traversal");
            if (entry.isDirectory()) {
                Files.createDirectories(entryPath);
            } else {
                Files.createDirectories(entryPath.getParent());
                try (InputStream in = zipFile.getInputStream(entry)) {
                    try (OutputStream out = new FileOutputStream(entryPath.toFile())) {
                        IOUtils.copy(in, out);
                    }/*from  w w  w .  j  a v  a  2s. co m*/
                }
            }
        }
    }
}