mirror of
https://github.com/tursom/TursomServer.git
synced 2025-03-24 08:30:05 +08:00
添加 ClassLoaderUtil
This commit is contained in:
parent
a6ccba5d1a
commit
fa4202e2d1
@ -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('.')}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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())
|
||||
}
|
@ -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?) {
|
||||
|
||||
}
|
||||
}
|
@ -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
|
||||
)
|
@ -1,5 +0,0 @@
|
||||
package cn.tursom.web.ws
|
||||
|
||||
interface TextWebSocketFrame : WebSocketFrame {
|
||||
val text: String
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
package cn.tursom.web.ws
|
||||
|
||||
interface WebSocketContent {
|
||||
val frame: WebSocketFrame
|
||||
fun write(frame: WebSocketFrame)
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
package cn.tursom.web.ws
|
||||
|
||||
import cn.tursom.core.buffer.ByteBuffer
|
||||
|
||||
interface WebSocketFrame {
|
||||
val data: ByteBuffer
|
||||
}
|
@ -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) {
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user