📄 debug.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: Debug.java
package org.gudy.azureus2.core3.util;
import java.io.*;
import java.net.UnknownHostException;
import java.util.*;
// Referenced classes of package org.gudy.azureus2.core3.util:
// AEDiagnostics, AEDiagnosticsLogger, SystemTime, AEThread
public class Debug
{
private static AEDiagnosticsLogger diag_logger = AEDiagnostics.getLogger("debug");
public Debug()
{
}
public static void out(String _debug_message)
{
out(_debug_message, null);
}
public static void out(Throwable _exception)
{
out("", _exception);
}
public static void outNoStack(String str)
{
outNoStack(str, false);
}
public static void outNoStack(String str, boolean stderr)
{
diagLoggerLogAndOut((new StringBuilder()).append("DEBUG::").append((new Date(SystemTime.getCurrentTime())).toString()).append(" ").append(str).toString(), stderr);
}
public static void outDiagLoggerOnly(String str)
{
diagLoggerLog(str);
}
public static void out(String _debug_msg, Throwable _exception)
{
String header = "DEBUG::";
header = (new StringBuilder()).append(header).append((new Date(SystemTime.getCurrentTime())).toString()).append("::").toString();
String trace_trace_tail = null;
try
{
throw new Exception();
}
catch (Exception e)
{
StackTraceElement st[] = e.getStackTrace();
StackTraceElement first_line = st[2];
String className = (new StringBuilder()).append(first_line.getClassName()).append("::").toString();
String methodName = (new StringBuilder()).append(first_line.getMethodName()).append("::").toString();
int lineNumber = first_line.getLineNumber();
trace_trace_tail = getCompressedStackTrace(e, 3, 200);
diagLoggerLogAndOut((new StringBuilder()).append(header).append(className).append(methodName).append(lineNumber).append(":").toString(), true);
}
if (_debug_msg.length() > 0)
diagLoggerLogAndOut((new StringBuilder()).append(" ").append(_debug_msg).toString(), true);
if (trace_trace_tail != null)
diagLoggerLogAndOut((new StringBuilder()).append(" ").append(trace_trace_tail).toString(), true);
if (_exception != null)
diagLoggerLogAndOut(_exception);
}
public static String getLastCaller()
{
return getLastCaller(0);
}
public static String getLastCaller(int numToGoBackFurther)
{
try
{
throw new Exception();
}
catch (Exception e)
{
StackTraceElement st[] = e.getStackTrace();
if (st == null || st.length == 0)
return "??";
if (st.length > 3 + numToGoBackFurther)
return st[3 + numToGoBackFurther].toString();
else
return st[st.length - 1].toString();
}
}
public static void outStackTrace()
{
diagLoggerLogAndOut(getStackTrace(1), false);
}
private static String getStackTrace(int endNumToSkip)
{
String sStackTrace = "";
try
{
throw new Exception();
}
catch (Exception e)
{
StackTraceElement st[] = e.getStackTrace();
for (int i = 1; i < st.length - endNumToSkip; i++)
if (!st[i].getMethodName().endsWith("StackTrace"))
sStackTrace = (new StringBuilder()).append(sStackTrace).append(st[i].toString()).append("\n").toString();
if (e.getCause() != null)
sStackTrace = (new StringBuilder()).append(sStackTrace).append("\tCaused By: ").append(getStackTrace(e.getCause())).append("\n").toString();
return sStackTrace;
}
}
public static void killAWTThreads()
{
ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
killAWTThreads(threadGroup);
}
private static String getCompressedStackTrace(Throwable t, int frames_to_skip)
{
return getCompressedStackTrace(t, frames_to_skip, 200);
}
public static String getCompressedStackTrace(Throwable t, int frames_to_skip, int iMaxLines)
{
String sStackTrace = "";
StackTraceElement st[] = t.getStackTrace();
int iMax = Math.min(st.length, iMaxLines + frames_to_skip);
for (int i = frames_to_skip; i < iMax; i++)
{
if (i > frames_to_skip)
sStackTrace = (new StringBuilder()).append(sStackTrace).append(",").toString();
String cn = st[i].getClassName();
cn = cn.substring(cn.lastIndexOf(".") + 1);
sStackTrace = (new StringBuilder()).append(sStackTrace).append(cn).append("::").append(st[i].getMethodName()).append("::").append(st[i].getLineNumber()).toString();
}
Throwable cause = t.getCause();
if (cause != null)
sStackTrace = (new StringBuilder()).append(sStackTrace).append("\n\tCaused By: ").append(getCompressedStackTrace(cause, 0)).toString();
return sStackTrace;
}
public static String getStackTrace(boolean bCompressed, boolean bIncludeSelf)
{
return getStackTrace(bCompressed, bIncludeSelf, bIncludeSelf ? 0 : 1, 200);
}
public static String getStackTrace(boolean bCompressed, boolean bIncludeSelf, int iNumLinesToSkip, int iMaxLines)
{
if (bCompressed)
return getCompressedStackTrace(bIncludeSelf ? 2 + iNumLinesToSkip : 3 + iNumLinesToSkip, iMaxLines);
else
return getStackTrace(1);
}
private static String getCompressedStackTrace(int frames_to_skip, int iMaxLines)
{
String trace_trace_tail = null;
try
{
throw new Exception();
}
catch (Exception e)
{
trace_trace_tail = getCompressedStackTrace(((Throwable) (e)), frames_to_skip, iMaxLines);
}
return trace_trace_tail;
}
public static void killAWTThreads(ThreadGroup threadGroup)
{
Thread threadList[] = new Thread[threadGroup.activeCount()];
threadGroup.enumerate(threadList);
for (int i = 0; i < threadList.length; i++)
{
Thread t = threadList[i];
if (t == null)
continue;
String name = t.getName();
if (name.startsWith("AWT"))
{
out("Interrupting thread '".concat(t.toString()).concat("'"));
t.interrupt();
}
}
if (threadGroup.getParent() != null)
killAWTThreads(threadGroup.getParent());
}
public static void dumpThreads(String name)
{
out((new StringBuilder()).append(name).append(":").toString());
ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
dumpThreads(threadGroup, "\t");
}
public static void dumpThreads(ThreadGroup threadGroup, String indent)
{
Thread threadList[] = new Thread[threadGroup.activeCount()];
threadGroup.enumerate(threadList);
for (int i = 0; i < threadList.length; i++)
{
Thread t = threadList[i];
if (t != null)
out(indent.concat("active thread = ").concat(t.toString()).concat(", daemon = ").concat(String.valueOf(t.isDaemon())));
}
if (threadGroup.getParent() != null)
dumpThreads(threadGroup.getParent(), (new StringBuilder()).append(indent).append("\t").toString());
}
public static void dumpThreadsLoop(String name)
{
(new AEThread("Thread Dumper", name) {
final String val$name;
public void runSupport()
{
do
{
Debug.dumpThreads(name);
try
{
Thread.sleep(5000L);
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
} while (true);
}
{
name = s;
super(x0);
}
}).start();
}
public static void dumpSystemProperties()
{
out("System Properties:");
Properties props = System.getProperties();
String name;
for (Iterator it = props.keySet().iterator(); it.hasNext(); out("\t".concat(name).concat(" = '").concat(props.get(name).toString()).concat("'")))
name = (String)it.next();
}
public static String getNestedExceptionMessage(Throwable e)
{
String last_message = "";
for (; e != null; e = e.getCause())
{
String this_message;
if (e instanceof UnknownHostException)
this_message = (new StringBuilder()).append("Unknown host ").append(e.getMessage()).toString();
else
this_message = e.getMessage();
if (this_message == null)
{
this_message = e.getClass().getName();
int pos = this_message.lastIndexOf(".");
this_message = this_message.substring(pos + 1).trim();
}
if (this_message.length() > 0 && last_message.indexOf(this_message) == -1)
last_message = (new StringBuilder()).append(last_message).append(last_message.length() != 0 ? ", " : "").append(this_message).toString();
}
return last_message;
}
public static String getNestedExceptionMessageAndStack(Throwable e)
{
return (new StringBuilder()).append(getNestedExceptionMessage(e)).append(", ").append(getCompressedStackTrace(e, 0)).toString();
}
public static String getCompressedStackTrace()
{
return getCompressedStackTrace(new Throwable(), 2);
}
public static String getCompressedStackTrace(int iMaxLines)
{
return getCompressedStackTrace(new Throwable(), 2, iMaxLines);
}
public static String getExceptionMessage(Throwable e)
{
String message = e.getMessage();
if (message == null || message.length() == 0)
{
message = e.getClass().getName();
int pos = message.lastIndexOf(".");
message = message.substring(pos + 1);
} else
if ((e instanceof ClassNotFoundException) && message.toLowerCase().indexOf("found") == -1)
message = (new StringBuilder()).append("Class ").append(message).append(" not found").toString();
return message;
}
public static void printStackTrace(Throwable e)
{
printStackTrace(e, null);
}
public static void printStackTrace(Throwable e, Object context)
{
String header = "DEBUG::";
header = (new StringBuilder()).append(header).append((new Date(SystemTime.getCurrentTime())).toString()).append("::").toString();
String className = "?::";
String methodName = "?::";
int lineNumber = -1;
StackTraceElement st[];
int i;
try
{
throw new Exception();
}
catch (Exception f)
{
st = f.getStackTrace();
i = 1;
}
do
{
if (i >= st.length)
break;
StackTraceElement first_line = st[i];
className = (new StringBuilder()).append(first_line.getClassName()).append("::").toString();
methodName = (new StringBuilder()).append(first_line.getMethodName()).append("::").toString();
lineNumber = first_line.getLineNumber();
if (className.indexOf(".logging.") == -1 && !className.endsWith(".Debug::"))
break;
i++;
} while (true);
diagLoggerLogAndOut((new StringBuilder()).append(header).append(className).append(methodName).append(lineNumber).append(":").toString(), true);
try
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter pw = new PrintWriter(new OutputStreamWriter(baos));
if (context != null)
{
pw.print(" ");
pw.println(context);
}
pw.print(" ");
e.printStackTrace(pw);
pw.close();
String stack = baos.toString();
diagLoggerLogAndOut(stack, true);
}
catch (Throwable ignore)
{
e.printStackTrace();
}
}
public static String getStackTrace(Throwable e)
{
ByteArrayOutputStream baos;
baos = new ByteArrayOutputStream();
PrintWriter pw = new PrintWriter(new OutputStreamWriter(baos));
e.printStackTrace(pw);
pw.close();
return baos.toString();
Throwable ignore;
ignore;
return "";
}
private static void diagLoggerLog(String str)
{
diag_logger.log(str);
}
private static void diagLoggerLogAndOut(String str, boolean stderr)
{
if (diag_logger == null)
{
if (stderr)
System.err.println(str);
else
System.out.println(str);
} else
{
diag_logger.logAndOut(str, stderr);
}
}
private static void diagLoggerLogAndOut(Throwable e)
{
if (diag_logger == null)
e.printStackTrace();
else
diag_logger.logAndOut(e);
}
public static String secretFileName(String key)
{
if (key == null)
return "";
String sep = File.separator;
String regex = (new StringBuilder()).append("([\\").append(sep).append("]?[^\\").append(sep).append("]{0,3}+)[^\\").append(sep).append("]*").toString();
String secretName = key.replaceAll(regex, "$1");
int iExtensionPos = key.lastIndexOf(".");
if (iExtensionPos >= 0)
secretName = (new StringBuilder()).append(secretName).append(key.substring(iExtensionPos)).toString();
return secretName;
}
public static void main(String args[])
{
System.out.println(secretFileName("c:\\temp\\hello there.txt"));
System.out.println(secretFileName("hello there.txt"));
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -