All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.redskap.swagger.brake.maven.jar.JarScanner Maven / Gradle / Ivy

There is a newer version: 2.4.0
Show newest version
package io.redskap.swagger.brake.maven.jar;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

import org.apache.commons.collections4.EnumerationUtils;
import org.springframework.stereotype.Component;

@Component
public class JarScanner {
    public Optional find(File jarFile, Predicate criteria) throws IOException {
        Optional result = Optional.empty();
        try (JarFile jar = new JarFile(jarFile)) {
            List jarEntries = EnumerationUtils.toList(jar.entries());
            for (JarEntry entry : jarEntries) {
                if (criteria.test(entry)) {
                    result = Optional.of(entry);
                }
            }
        }
        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy