Search in sources :

Example 1 with TraceClassVisitor

use of org.powermock.api.mockito.repackaged.asm.util.TraceClassVisitor in project powermock by powermock.

the class DebuggingClassWriter method toByteArray.

public byte[] toByteArray() {
    return (byte[]) java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {

        public Object run() {
            byte[] b = DebuggingClassWriter.super.toByteArray();
            if (debugLocation != null) {
                String dirs = className.replace('.', File.separatorChar);
                try {
                    new File(debugLocation + File.separatorChar + dirs).getParentFile().mkdirs();
                    File file = new File(new File(debugLocation), dirs + ".class");
                    OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
                    try {
                        out.write(b);
                    } finally {
                        out.close();
                    }
                    if (traceEnabled) {
                        file = new File(new File(debugLocation), dirs + ".asm");
                        out = new BufferedOutputStream(new FileOutputStream(file));
                        try {
                            ClassReader cr = new ClassReader(b);
                            PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
                            TraceClassVisitor tcv = new TraceClassVisitor(null, pw);
                            cr.accept(tcv, 0);
                            pw.flush();
                        } finally {
                            out.close();
                        }
                    }
                } catch (IOException e) {
                    throw new CodeGenerationException(e);
                }
            }
            return b;
        }
    });
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) IOException(java.io.IOException) TraceClassVisitor(org.powermock.api.mockito.repackaged.asm.util.TraceClassVisitor) FileOutputStream(java.io.FileOutputStream) ClassReader(org.powermock.api.mockito.repackaged.asm.ClassReader) OutputStreamWriter(java.io.OutputStreamWriter) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) PrintWriter(java.io.PrintWriter)

Aggregations

BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 ClassReader (org.powermock.api.mockito.repackaged.asm.ClassReader)1 TraceClassVisitor (org.powermock.api.mockito.repackaged.asm.util.TraceClassVisitor)1