private static boolean decompress()

in src/main/java/org/apache/sling/feature/maven/mojos/JarDecompressor.java [50:103]


    private static boolean decompress(File in, File out) throws IOException {
        try (JarInputStream jis = new JarInputStream(new FileInputStream(in));
            ZipOutputStream jos = new JarOutputStream(new FileOutputStream(out))) {
            jos.setMethod(ZipOutputStream.STORED);

            writeManifestIfPresent(jis, jos);

            byte[] buffer = new byte[BUFFER_SIZE];
            JarEntry je = null;
            while ((je = jis.getNextJarEntry()) != null) {
                if (JarFile.MANIFEST_NAME.equals(je.getName()))
                    continue;

                if (je.getName().startsWith("META-INF/") &&
                    je.getName().endsWith(".SF")) {
                    // This is a signed jar, don't decompress it.
                    return false;
                }

                // Put the jar entry in a temp file because we need to read it twice
                // once to compute the CRC and once again to write it to the Jar file
                File tmpFile = Files.createTempFile("tempfile", ".tmp").toFile();
                try (FileOutputStream fos = new FileOutputStream(tmpFile)) {
                    drainStream(jis, fos, buffer);
                }

                // If the embedded file is a jar file, also decompress that one
                if (je.getName().toLowerCase().endsWith(".jar")) {
                    File tmpFile2 = tmpFile;
                    tmpFile = Files.createTempFile("tempfile", ".tmp").toFile();
                    copyDecompress(tmpFile2, tmpFile);

                    if (!tmpFile2.delete()) {
                        throw new IOException("Could not delete temp file " + tmpFile);
                    }
                }

                ZipEntry ze = new ZipEntry(je);
                crcEntry(ze, tmpFile, buffer);
                jos.putNextEntry(ze);

                try (InputStream is = new FileInputStream(tmpFile)) {
                    drainStream(is, jos, buffer);
                }
                jos.closeEntry();

                if (!tmpFile.delete()) {
                    throw new IOException("Could not delete temp file " + tmpFile);
                }

            }
        }
        return true;
    }