1 23 package org.archive.util; 24 25 import java.io.BufferedReader ; 26 import java.io.IOException ; 27 import java.io.InputStreamReader ; 28 import java.io.PrintWriter ; 29 import java.io.StringWriter ; 30 import java.util.logging.Logger ; 31 32 33 39 public class DevUtils { 40 public static Logger logger = 41 Logger.getLogger(DevUtils.class.getName()); 42 43 50 public static void warnHandle(Throwable ex, String note) { 51 logger.warning(TextUtils.exceptionToString(note, ex)); 52 } 53 54 58 public static String extraInfo() { 59 StringWriter sw = new StringWriter (); 60 PrintWriter pw = new PrintWriter (sw); 61 final Thread current = Thread.currentThread(); 62 if (current instanceof Reporter) { 63 Reporter tt = (Reporter)current; 64 try { 65 tt.reportTo(pw); 66 } catch (IOException e) { 67 e.printStackTrace(); 69 } 70 } 71 if (current instanceof ProgressStatisticsReporter) { 72 ProgressStatisticsReporter tt = (ProgressStatisticsReporter)current; 73 try { 74 tt.progressStatisticsLegend(pw); 75 tt.progressStatisticsLine(pw); 76 } catch (IOException e) { 77 e.printStackTrace(); 79 } 80 } 81 pw.flush(); 82 return sw.toString(); 83 } 84 85 89 @Deprecated 90 public static void betterPrintStack(RuntimeException re) { 91 re.printStackTrace(System.err); 92 } 93 94 103 public static void sigquitSelf() { 104 try { 105 Process p = Runtime.getRuntime().exec( 106 new String [] {"perl", "-e", "print getppid(). \"\n\";"}); 107 BufferedReader br = 108 new BufferedReader (new InputStreamReader (p.getInputStream())); 109 String ppid = br.readLine(); 110 Runtime.getRuntime().exec( 111 new String [] {"sh", "-c", "kill -3 "+ppid}).waitFor(); 112 } catch (IOException e) { 113 e.printStackTrace(); 115 } catch (InterruptedException e) { 116 e.printStackTrace(); 118 } 119 } 120 } 121 | Popular Tags |