代码拉取完成,页面将自动刷新
package cn.platform.agent.frame.core.helper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.*;
import java.util.ArrayList;
/**
* <p>标题: </p>
* <p>功能描述: </p>
* <p>创建时间:17/4/12 </p>
* <p>作者:SIVEN</p>
* <p>修改历史记录:</p>
* ============================================================<br>
*/
public class ThrowableInfoHelper {
protected final Log logger = LogFactory.getLog(getClass());
/**
* =======================================================================
* 获得操作系统中,换行字符串。如Micorsoft Windows XP专业版中换行符"\r\n"
* =======================================================================
*/
// Note that the line.separator property can be looked up even by applets.
// 参考org.apache.log4j.Layout
public final static String LINE_SEP = System.getProperty("line.separator");
// 参考java.io.BufferedWriter
public final static String LINE_SEP2 = (String) java.security.AccessController
.doPrivileged(new sun.security.action.GetPropertyAction(
"line.separator"));
/**
* @param throwable 异常对象
* @return
* @Description:将Throwable对象的错误堆栈内容形成字符串<br> 参考
* {@link org.apache.log4j.spi.ThrowableInformation}
* 代码
* @author mahh
* @since:2014-9-30 下午02:32:51
*/
public static String[] getThrowableStrRep(Throwable throwable) {
if (throwable == null) {
return new String[0];
}
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
throwable.printStackTrace(pw);
pw.flush();
LineNumberReader reader = new LineNumberReader(new StringReader(
sw.toString()));
ArrayList lines = new ArrayList();
try {
String line = reader.readLine();
while (line != null) {
lines.add(line);
line = reader.readLine();
}
} catch (IOException ex) {
lines.add(ex.toString());
}
String[] rep = new String[lines.size()];
lines.toArray(rep);
return rep;
}
public static String getThrowableStr(Throwable throwable) {
StringBuffer throwableStr = new StringBuffer();
String[] errorStrArray = getThrowableStrRep(throwable);
for (int i = 0; i < errorStrArray.length; i++) {
throwableStr.append(errorStrArray[i]).append(LINE_SEP2);
}
return throwableStr.toString();
}
// 测试代码
public static void main(String[] args) {
RuntimeException e1 = new RuntimeException("aaa");
RuntimeException e2 = new RuntimeException("e2", e1);
RuntimeException e3 = new RuntimeException(e2);
System.out.println("=====");
String throwableStr = getThrowableStr(e3);
System.out.println(throwableStr);
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。