private static String getPackageName()

in components-starter/camel-xml-jaxb-starter/src/main/java/org/apache/camel/xml/jaxb/springboot/JAXBRuntimeHints.java [258:293]


    private static String getPackageName(Resource resource, String fileName) throws IOException {
        URL url = resource.getURL();
        String protocol = url.getProtocol();
        String packageName = null;
        if ("jar".equals(protocol)) {
            String path = url.getPath();
            String suffix = ".jar!/";
            int index = path.indexOf(suffix);
            if (index == -1) {
                LOG.trace("The jar suffix could not be found in {}", path);
            } else {
                packageName = path.substring(index + suffix.length(), path.length() - fileName.length());
            }
        } else if (resource.isFile()) {
            File file = resource.getFile();
            File[] files = file.getParentFile().listFiles((dir, name) -> name.endsWith(".class"));
            if (files != null && files.length > 0) {
                try (InputStream is = new FileInputStream(files[0])) {
                    ClassReader reader = new ClassReader(is);
                    String className = reader.getClassName();
                    int index = className.lastIndexOf('/');
                    if (index == -1) {
                        packageName = "";
                    } else {
                        packageName = className.substring(0, index + 1);
                    }
                }
            } else {
                LOG.trace("No class file could be found in {}", file.getParentFile());
            }
        }
        if (packageName != null) {
            packageName = packageName.replace('/', '.');
        }
        return packageName;
    }