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

com.hxl.miniapi.core.io.JarResourceLoader.kt Maven / Gradle / Ivy

There is a newer version: 1.3.3
Show newest version
package com.hxl.miniapi.core.io

import java.net.JarURLConnection
import java.net.URL


/**
* @description: 扫描jar中符合条件的class
* @date: 2022/10/5 上午8:52
*/

class JarResourceLoader:ResourceLoader {
    override fun getResources(location: String): List {
        val jarUrl =URL("jar:$location")
        val result = mutableListOf()

        val keyword = jarUrl.path.substring(2 + jarUrl.path.indexOf("!/"))
        val connection = jarUrl.openConnection()
        if (connection is JarURLConnection){
            val entries = connection.jarFile.entries()
            val jarFile = connection.jarFile
            while (entries.hasMoreElements()){
                val name = entries.nextElement().name
                if (name.startsWith(keyword) && name.endsWith(".class")){
                    result.add(URL("jar:file:${jarFile.name}!/${name}"))
                }
            }
        }
        return result
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy