mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add logtube support
This commit is contained in:
@@ -150,7 +150,25 @@ public class ExceptionUtil {
|
||||
* @since 4.1.4
|
||||
*/
|
||||
public static StackTraceElement getStackElement(int i) {
|
||||
return getStackElements()[i];
|
||||
return Thread.currentThread().getStackTrace()[i];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定层的堆栈信息
|
||||
*
|
||||
* @param fqcn 指定类名为基础
|
||||
* @param i 指定类名的类堆栈相对层数
|
||||
* @return 指定层的堆栈信息
|
||||
* @since 5.6.6
|
||||
*/
|
||||
public static StackTraceElement getStackElement(String fqcn, int i) {
|
||||
final StackTraceElement[] stackTraceArray = Thread.currentThread().getStackTrace();
|
||||
final int index = ArrayUtil.matchIndex((ele) -> StrUtil.equals(fqcn, ele.getClassName()), stackTraceArray);
|
||||
if(index > 0){
|
||||
return stackTraceArray[index + i];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,8 +178,8 @@ public class ExceptionUtil {
|
||||
* @since 4.1.4
|
||||
*/
|
||||
public static StackTraceElement getRootStackElement() {
|
||||
final StackTraceElement[] stackElements = getStackElements();
|
||||
return stackElements[stackElements.length - 1];
|
||||
final StackTraceElement[] stackElements = Thread.currentThread().getStackTrace();
|
||||
return Thread.currentThread().getStackTrace()[stackElements.length - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1422,8 +1422,8 @@ public class FileUtil extends PathUtil {
|
||||
pathToUse = StrUtil.removePrefixIgnoreCase(pathToUse, URLUtil.FILE_URL_PREFIX);
|
||||
|
||||
// 识别home目录形式,并转换为绝对路径
|
||||
if (pathToUse.startsWith("~")) {
|
||||
pathToUse = pathToUse.replaceFirst("~", getUserHomePath());
|
||||
if (StrUtil.startWith(pathToUse, '~')) {
|
||||
pathToUse = getUserHomePath() + pathToUse.substring(1);
|
||||
}
|
||||
|
||||
// 统一使用斜杠
|
||||
|
@@ -26,6 +26,10 @@ public class ExceptionUtilTest {
|
||||
Assert.assertEquals("main", ele.getMethodName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getStackElementTest(){
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertTest() {
|
||||
// RuntimeException e = new RuntimeException();
|
||||
|
@@ -168,6 +168,13 @@ public class FileUtilTest {
|
||||
Assert.assertEquals(home + "/bar/", FileUtil.normalize("~/foo/../bar/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void normalizeHomePathTest2() {
|
||||
String home = FileUtil.getUserHomePath().replace('\\', '/');
|
||||
// 多个~应该只替换开头的
|
||||
Assert.assertEquals(home + "/~bar/", FileUtil.normalize("~/foo/../~bar/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void normalizeClassPathTest() {
|
||||
Assert.assertEquals("", FileUtil.normalize("classpath:"));
|
||||
|
Reference in New Issue
Block a user