Example usage for java.lang StackTraceElement getFileName

List of usage examples for java.lang StackTraceElement getFileName

Introduction

In this page you can find the example usage for java.lang StackTraceElement getFileName.

Prototype

public String getFileName() 

Source Link

Document

Returns the name of the source file containing the execution point represented by this stack trace element.

Usage

From source file:Main.java

public static void main(String[] args) {
    Thread t = Thread.currentThread();
    StackTraceElement e = t.getStackTrace()[0];
    System.out.print("file name : ");
    System.out.print(e.getFileName());
}

From source file:Main.java

public static String getDefaultTag(StackTraceElement stackTraceElement) {
    String fileName = stackTraceElement.getFileName();
    String stringArray[] = fileName.split("\\.");
    String tag = stringArray[0];/* w  w w  .  j  av  a  2s  .  co m*/
    return tag;
}

From source file:Main.java

public static String getLineInfo() {
    StackTraceElement ste = new Throwable().getStackTrace()[1];
    return ste.getFileName() + ": Line " + ste.getLineNumber();
}

From source file:Main.java

public static String getThreadStack(Thread t) {
    StackTraceElement[] stacks = t.getStackTrace();
    StringBuffer buffer = new StringBuffer();
    for (StackTraceElement stack : stacks) {
        String filename = stack.getFileName();
        if (filename == null) {
            filename = "NULL";
        }/*w  w w  . j  av  a 2 s .  c  o  m*/
        String className = stack.getClassName();
        String methodName = stack.getMethodName();
        int line = stack.getLineNumber();
        buffer.append(String.format("%s.%s(%s:%d)\r", className, methodName, filename, line));
    }
    return buffer.toString();
}

From source file:Main.java

public static String _FILE_() {
    StackTraceElement traceElement = ((new Exception()).getStackTrace())[1];
    return traceElement.getFileName();
}

From source file:Main.java

public static String _FILE_() {
    StackTraceElement traceElement = ((new Exception()).getStackTrace())[2];
    return traceElement.getFileName();
}

From source file:Main.java

private static String rebuildMsg(StackTraceElement stackTraceElement, String msg) {
    StringBuffer sb = new StringBuffer();
    sb.append(stackTraceElement.getFileName());
    sb.append(" (");
    sb.append(stackTraceElement.getLineNumber());
    sb.append(") ");
    sb.append(stackTraceElement.getMethodName());
    sb.append(": ");
    sb.append(msg);/*ww w  . ja v  a 2  s. c  om*/
    return sb.toString();
}

From source file:Main.java

public static String dumpStack(Thread t) {
    StringBuilder sb = new StringBuilder();
    sb.append(t.getName() + "[" + t.getId() + "] - " + t.getState() + ":\n");
    for (StackTraceElement ste : t.getStackTrace()) {
        sb.append("\tat " + ste.getClassName() + "." + ste.getMethodName() + "(" + ste.getFileName() + ":"
                + ste.getLineNumber() + ")\n");
    }//from   w  w  w. j  a  v  a 2 s  .  c o  m
    return sb.toString();
}

From source file:Main.java

public static String getFileLineMethod() {
    StackTraceElement traceElement = ((new Exception()).getStackTrace())[2];
    StringBuffer toStringBuffer = new StringBuffer("[").append(traceElement.getFileName()).append(" | ")
            .append(traceElement.getLineNumber()).append(" | ").append(traceElement.getMethodName())
            .append("]");
    return toStringBuffer.toString();
}

From source file:Main.java

private static String getTag(Exception exception) {
    StackTraceElement traceElement = ((exception).getStackTrace())[1];
    StringBuffer toStringBuffer = new StringBuffer("[").append(traceElement.getFileName()).append(" | ")
            .append(traceElement.getLineNumber()).append(" | ").append(traceElement.getMethodName())
            .append("()").append("]");
    String TAG = toStringBuffer.toString();
    return TAG;/*from   w  w w  . jav a2 s.c o  m*/
}