Added Throwable.toStackTrace function in UtilsFactory

This commit is contained in:
2022-09-22 15:06:54 +08:00
parent 4c521abe67
commit 6d10673e07

View File

@@ -27,6 +27,8 @@
*/
package com.highcapable.yukihookapi.hook.utils
import java.io.ByteArrayOutputStream
import java.io.PrintStream
import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
@@ -85,6 +87,12 @@ internal inline fun <T> T.takeIf(other: Any?, predicate: (T) -> Boolean) = if (o
*/
internal inline fun <T, R> T.let(other: Any?, block: (T) -> R) = if (other != null) let(block) else null
/**
* 获取完整的异常堆栈内容
* @return [String]
*/
internal fun Throwable.toStackTrace() = ByteArrayOutputStream().also { printStackTrace(PrintStream(it)) }.toString()
/**
* 计算方法执行耗时
* @param block 方法块