📄 bugreport.java
字号:
/* * YALE - Yet Another Learning Environment * Copyright (C) 2002, 2003 * Simon Fischer, Ralf Klinkenberg, Ingo Mierswa, * Katharina Morik, Oliver Ritthoff * Artificial Intelligence Unit * Computer Science Department * University of Dortmund * 44221 Dortmund, Germany * email: yale@ls8.cs.uni-dortmund.de * web: http://yale.cs.uni-dortmund.de/ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA. */package edu.udo.cs.yale.tools;import edu.udo.cs.yale.Experiment;import java.util.Enumeration;import java.util.Date;import java.util.zip.*;import java.io.File;import java.io.PrintStream;import java.io.FileOutputStream;import java.io.FileInputStream;import java.io.InputStream;import java.io.IOException;/** * @version $Id: BugReport.java,v 1.1 2003/06/17 19:45:34 fischer Exp $ */public class BugReport { private static final int BUFFER_SIZE = 1024; private static void getProperties(String prefix, StringBuffer string) { string.append(prefix+" properties:\n"); Enumeration keys = System.getProperties().propertyNames(); while (keys.hasMoreElements()) { String key = (String)keys.nextElement(); if (key.startsWith(prefix)) { string.append(" "+key + "\t= "+System.getProperty(key) + "\n"); } } } public static String getProperties() { StringBuffer string = new StringBuffer(); string.append("System properties:\n"); string.append("------------------\n\n"); getProperties("os", string); getProperties("java", string); getProperties("yale", string); return string.toString(); } public static String getStackTrace(Throwable throwable) { StringBuffer string = new StringBuffer(); string.append("Stack trace:\n"); string.append("------------\n\n"); while (throwable != null) { string.append("Exception:\t"+throwable.getClass().getName()+"\n"); string.append("Message:\t" +throwable.getMessage()+"\n"); string.append("Stack trace:\n"); StackTraceElement[] ste = throwable.getStackTrace(); for (int i = 0; i < ste.length; i++) { string.append(" "+ste[i]+"\n"); } string.append("\n"); throwable = throwable.getCause(); if (throwable != null) { string.append(""); string.append("Cause:"); } } return string.toString(); } public static void createBugReport(File reportFile, Throwable exception, String userMessage, Experiment experiment, String logMessage, File[] attachments) throws IOException { ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(reportFile)); zipOut.setComment("Yale bug report - generated "+new Date()); write("message.txt", "User message", userMessage, zipOut); write("_experiment.xml", "Experiment as in memory.", experiment.getRootOperator().getXML(""), zipOut); if (experiment.getExperimentFile() != null) { try { String contents = Tools.readTextFile(experiment.getExperimentFile()); write(experiment.getExperimentFile().getName(), "Experiment file on disc.", contents, zipOut); } catch (Throwable t) { write(experiment.getExperimentFile().getName(), "Experiment file on disc.", "could not read: "+t, zipOut); } } write("_log.txt", "Log message", logMessage, zipOut); write("_properties.txt", "System properties, information about java version and operating system", getProperties(), zipOut); write("_exception.txt", "Exception stack trace", getStackTrace(exception), zipOut); for (int i = 0; i < attachments.length; i++) writeFile(attachments[i], zipOut); zipOut.close(); } private static void writeFile(File file, ZipOutputStream out) throws IOException { InputStream in = new FileInputStream(file); out.putNextEntry(new ZipEntry(file.getName())); byte[] buffer = new byte[BUFFER_SIZE]; int read = -1; do { read = in.read(buffer); if (read > -1) { out.write(buffer, 0, read); } } while (read > -1); out.closeEntry(); } private static void write(String name, String comment, String string, ZipOutputStream out) throws IOException { ZipEntry entry = new ZipEntry(name); entry.setComment(comment); out.putNextEntry(entry); PrintStream print = new PrintStream(out); print.println(string); print.flush(); out.closeEntry(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -