private static void extractResourcePathFromJar()

in src/main/java/org/apache/maven/shared/verifier/util/ResourceExtractor.java [92:126]


    private static void extractResourcePathFromJar(Class<?> cl, File jarFile, String resourcePath, File dest)
            throws IOException {
        ZipFile z = new ZipFile(jarFile, ZipFile.OPEN_READ);
        String zipStyleResourcePath = resourcePath.substring(1) + "/";
        ZipEntry ze = z.getEntry(zipStyleResourcePath);
        if (ze != null) {
            // DGF If it's a directory, then we need to look at all the entries
            for (Enumeration<? extends ZipEntry> entries = z.entries(); entries.hasMoreElements(); ) {
                ze = entries.nextElement();
                if (ze.getName().startsWith(zipStyleResourcePath)) {
                    String relativePath = ze.getName().substring(zipStyleResourcePath.length());
                    File destFile = new File(dest, relativePath);
                    if (ze.isDirectory()) {
                        destFile.mkdirs();
                    } else {
                        FileOutputStream fos = new FileOutputStream(destFile);
                        try {
                            IOUtil.copy(z.getInputStream(ze), fos);
                        } finally {
                            IOUtil.close(fos);
                            z.close();
                        }
                    }
                }
            }
        } else {
            FileOutputStream fos = new FileOutputStream(dest);
            try {
                IOUtil.copy(cl.getResourceAsStream(resourcePath), fos);
            } finally {
                IOUtil.close(fos);
                z.close();
            }
        }
    }