添加 ClassLoaderUtil

This commit is contained in:
tursom 2019-12-12 23:01:36 +08:00
parent a6ccba5d1a
commit fa4202e2d1
8 changed files with 9 additions and 85 deletions

View File

@ -32,7 +32,7 @@ object ClassLoaderUtil {
val url: URL? = loader.getResource(packagePath)
return if (url != null) {
when (url.protocol) {
"file" -> getClassNameByFile(url.path, childPackage)
"file" -> getClassNameByFile(url.path, packageName, childPackage)
"jar" -> getClassNameByJar(url.path, childPackage)
else -> listOf()
}
@ -47,21 +47,23 @@ object ClassLoaderUtil {
* @param childPackage 是否遍历子包
* @return 类的完整名称
*/
private fun getClassNameByFile(filePath: String, childPackage: Boolean): List<String> {
private fun getClassNameByFile(filePath: String, basePackage: String, childPackage: Boolean): List<String> {
val myClassName: MutableList<String> = ArrayList()
val file = File(filePath)
val childFiles: Array<File> = file.listFiles()!!
for (childFile in childFiles) {
if (childFile.isDirectory) {
if (childPackage) {
myClassName.addAll(getClassNameByFile(childFile.path, childPackage))
myClassName.addAll(getClassNameByFile(
childFile.path,
"$basePackage.${childFile.path.substringAfterLast(File.separator)}",
childPackage
))
}
} else {
var childFilePath: String = childFile.getPath()
val childFilePath: String = childFile.path
if (childFilePath.endsWith(".class")) {
childFilePath = childFilePath.substring(childFilePath.indexOf("\\classes") + 9, childFilePath.lastIndexOf("."))
childFilePath = childFilePath.replace("\\", ".")
myClassName.add(childFilePath)
myClassName.add("$basePackage.${childFilePath.substringAfterLast(File.separator).substringBeforeLast('.')}")
}
}
}

View File

@ -1,12 +0,0 @@
package cn.tursom.web.netty.ws
import cn.tursom.core.buffer.ByteBuffer
import cn.tursom.web.netty.NettyByteBuffer
import cn.tursom.web.ws.TextWebSocketFrame
class NettyTextWebSocketFrame(
@Suppress("MemberVisibilityCanBePrivate") val frame: io.netty.handler.codec.http.websocketx.TextWebSocketFrame
) : TextWebSocketFrame {
override val text: String by lazy { data.toString(data.readable) }
override val data: ByteBuffer = NettyByteBuffer(frame.content())
}

View File

@ -1,15 +0,0 @@
package cn.tursom.web.netty.ws
import cn.tursom.web.netty.NettyExceptionContent
import cn.tursom.web.ws.WebSocketHandler
import io.netty.channel.ChannelHandlerContext
import io.netty.channel.SimpleChannelInboundHandler
import io.netty.handler.codec.http.websocketx.WebSocketFrame
class NettyWebSocketHandler(
val handler: WebSocketHandler<NettyExceptionContent>
) : SimpleChannelInboundHandler<WebSocketFrame>() {
override fun channelRead0(ctx: ChannelHandlerContext?, msg: WebSocketFrame?) {
}
}

View File

@ -1,9 +0,0 @@
package cn.tursom.web.netty.ws
import io.netty.channel.ChannelHandlerContext
import io.netty.handler.codec.http.FullHttpRequest
class NettyWsHttpContent(
val ctx: ChannelHandlerContext,
val msg: FullHttpRequest
)

View File

@ -1,5 +0,0 @@
package cn.tursom.web.ws
interface TextWebSocketFrame : WebSocketFrame {
val text: String
}

View File

@ -1,6 +0,0 @@
package cn.tursom.web.ws
interface WebSocketContent {
val frame: WebSocketFrame
fun write(frame: WebSocketFrame)
}

View File

@ -1,7 +0,0 @@
package cn.tursom.web.ws
import cn.tursom.core.buffer.ByteBuffer
interface WebSocketFrame {
val data: ByteBuffer
}

View File

@ -1,24 +0,0 @@
package cn.tursom.web.ws
import cn.tursom.web.ExceptionContent
import cn.tursom.web.HttpHandler
interface WebSocketHandler<T : ExceptionContent> : HttpHandler<WsHttpContent, T> {
override fun handle(content: WsHttpContent) {
val frame = content.frame
when (frame) {
is TextWebSocketFrame -> {
handle(content, frame)
}
else -> {
}
}
handle(content, frame)
}
fun handle(content: WsHttpContent, frame: TextWebSocketFrame) {
}
fun handle(content: WsHttpContent, frame: WebSocketFrame) {
}
}