class JarContentsManager {

    public void copyFilesFromJarTrimmingBasePath(File jar,
            String jarDirectoryToCopyFrom, File outputDirectory,
            String... wildcardPathExclusions) {
        requireFileExistence(jar);

        if (!Objects.requireNonNull(outputDirectory).isDirectory()) {
            throw new IllegalArgumentException(
                    String.format("Expect '%s' to be an existing directory",
                            outputDirectory));
        }

        String basePath = normalizeJarBasePath(jarDirectoryToCopyFrom);

        try (JarFile jarFile = new JarFile(jar, false)) {
            jarFile.stream().filter(file -> !file.isDirectory())
                    .filter(file -> file.getName().toLowerCase(Locale.ENGLISH)
                            .startsWith(basePath.toLowerCase(Locale.ENGLISH)))
                    .filter(file -> isFileIncluded(file,
                            wildcardPathExclusions))
                    .forEach(jarEntry -> copyJarEntryTrimmingBasePath(jarFile,
                            jarEntry, basePath, outputDirectory));
        } catch (IOException e) {
            throw new UncheckedIOException(String.format(
                    "Failed to extract files from jarFile '%s' to directory '%s'",
                    jar, outputDirectory), e);
        }
    }

}