[Jrisk-cvs] SF.net SVN: jrisk-code:[1055] Grasshopper
Brought to you by:
yuranet
|
From: <yu...@us...> - 2024-12-27 15:20:20
|
Revision: 1055
http://sourceforge.net/p/jrisk/code/1055
Author: yuranet
Date: 2024-12-27 15:20:16 +0000 (Fri, 27 Dec 2024)
Log Message:
-----------
started on size limit for multi part submit
Modified Paths:
--------------
Grasshopper/src/net/yura/grasshopper/BugManager.java
Grasshopper/src/net/yura/grasshopper/SimpleBug.java
Grasshopper/src_swing/net/yura/grasshopper/BugUIInfo.java
Grasshopper/src_swing/net/yura/grasshopper/ConsoleHandler.java
Grasshopper/src_swing/net/yura/grasshopper/PopupBug.java
Added Paths:
-----------
Grasshopper/src/net/yura/grasshopper/info/
Grasshopper/src/net/yura/grasshopper/info/ApplicationInfoProvider.java
Grasshopper/src/net/yura/grasshopper/info/BugSystemInfo.java
Grasshopper/src/net/yura/grasshopper/info/LogFile.java
Grasshopper/src/net/yura/grasshopper/info/LogList.java
Grasshopper/src/net/yura/grasshopper/info/LogText.java
Grasshopper/src/net/yura/grasshopper/info/ScreenShot.java
Grasshopper/src/net/yura/grasshopper/submitter/
Grasshopper/src/net/yura/grasshopper/submitter/BugSubmitter.java
Grasshopper/src/net/yura/grasshopper/submitter/BugSubmitterMultipart.java
Grasshopper/src/net/yura/grasshopper/util/
Grasshopper/src/net/yura/grasshopper/util/ColorFormatter.java
Grasshopper/src/net/yura/grasshopper/util/LimitedOutputStream.java
Grasshopper/src/net/yura/grasshopper/util/LoggingOutputStream.java
Grasshopper/src/net/yura/grasshopper/util/ReallySimpleFormatter.java
Grasshopper/src/net/yura/grasshopper/util/StdOutErrLevel.java
Grasshopper/src/net/yura/grasshopper/util/TextHandler.java
Removed Paths:
-------------
Grasshopper/src/net/yura/grasshopper/ApplicationInfoProvider.java
Grasshopper/src/net/yura/grasshopper/BugSubmitter.java
Grasshopper/src/net/yura/grasshopper/BugSubmitterMultipart.java
Grasshopper/src/net/yura/grasshopper/BugSystemInfo.java
Grasshopper/src/net/yura/grasshopper/ColorFormatter.java
Grasshopper/src/net/yura/grasshopper/LogFile.java
Grasshopper/src/net/yura/grasshopper/LogList.java
Grasshopper/src/net/yura/grasshopper/LogText.java
Grasshopper/src/net/yura/grasshopper/LoggingOutputStream.java
Grasshopper/src/net/yura/grasshopper/ReallySimpleFormatter.java
Grasshopper/src/net/yura/grasshopper/ScreenShot.java
Grasshopper/src/net/yura/grasshopper/StdOutErrLevel.java
Grasshopper/src/net/yura/grasshopper/TextHandler.java
Deleted: Grasshopper/src/net/yura/grasshopper/ApplicationInfoProvider.java
===================================================================
--- Grasshopper/src/net/yura/grasshopper/ApplicationInfoProvider.java 2024-12-27 14:08:21 UTC (rev 1054)
+++ Grasshopper/src/net/yura/grasshopper/ApplicationInfoProvider.java 2024-12-27 15:20:16 UTC (rev 1055)
@@ -1,14 +0,0 @@
-package net.yura.grasshopper;
-
-import java.util.Map;
-import java.util.logging.LogRecord;
-
-/**
- * @author Yura Mamyrin
- */
-public interface ApplicationInfoProvider {
-
- boolean ignoreError(LogRecord record);
- void addInfoForSubmit(Map map);
-
-}
Modified: Grasshopper/src/net/yura/grasshopper/BugManager.java
===================================================================
--- Grasshopper/src/net/yura/grasshopper/BugManager.java 2024-12-27 14:08:21 UTC (rev 1054)
+++ Grasshopper/src/net/yura/grasshopper/BugManager.java 2024-12-27 15:20:16 UTC (rev 1055)
@@ -1,5 +1,8 @@
package net.yura.grasshopper;
+import net.yura.grasshopper.util.StdOutErrLevel;
+import net.yura.grasshopper.util.TextHandler;
+import net.yura.grasshopper.util.LoggingOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileDescriptor;
import java.io.FileOutputStream;
@@ -13,7 +16,7 @@
public abstract class BugManager {
- public final static String VER = "2.14";
+ public final static String VER = "2.15";
protected abstract void action(String cause);
Deleted: Grasshopper/src/net/yura/grasshopper/BugSubmitter.java
===================================================================
--- Grasshopper/src/net/yura/grasshopper/BugSubmitter.java 2024-12-27 14:08:21 UTC (rev 1054)
+++ Grasshopper/src/net/yura/grasshopper/BugSubmitter.java 2024-12-27 15:20:16 UTC (rev 1055)
@@ -1,265 +0,0 @@
-package net.yura.grasshopper;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.net.URLConnection;
-import java.net.URLEncoder;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
-/**
- * @author Yura Mamyrin
- */
-public class BugSubmitter {
-
- /**
- * primary system
- * - supports sending image attachments
- * - only send to one address
- */
- public static final String TF_MAIL_URL;
-
- /**
- * backup system
- * - does not support attachments
- * - can send to any address on domain
- */
- public static final String FORM_MAIL_URL;
-
- public static final String RECIPIENT;
-
- static {
- Properties settings = new Properties();
- String fileName = "/grasshopper.properties";
- InputStream settingsData = BugSubmitter.class.getResourceAsStream(fileName);
- try {
- settings.load(settingsData);
- TF_MAIL_URL = getSetting(settings,"url.tfMail");
- FORM_MAIL_URL = getSetting(settings,"url.formMail");
- RECIPIENT = getSetting(settings,"recipient");
- }
- catch (Exception ex) {
- ExceptionInInitializerError err = new ExceptionInInitializerError("can not load grasshopper settings from: "+fileName);
- err.initCause(ex);
- throw err;
- }
- finally {
- try {
- if (settingsData != null) settingsData.close();
- }
- catch (Exception ignored) {
- }
- }
- }
- private static String getSetting(Properties prop, String name) throws Exception {
- String result = prop.getProperty(name);
- if (result==null) {
- throw new Exception("can not get setting for: "+name);
- }
- return result;
- }
-
- static ApplicationInfoProvider extraInfoProvider;
-
- public static void setApplicationInfoProvider(ApplicationInfoProvider aip) {
- extraInfoProvider = aip;
- }
-
- public static String generateSubject(String errorSignature) {
- // The errorSignature is added to the subject so that gmail or another email app can group simular bugs.
- return "GRASSHOPPER " + BugSystemInfo.appName + " " + BugSystemInfo.version + " - " + errorSignature;
- }
-
- /**
- * internal methods used by SimpleBug
- */
- static void submitBug(Object log, String errorSignature) {
- submitBug(log, null, errorSignature);
- }
-
- /**
- * internal method used by PopupBug
- */
- static boolean submitBug(Object log, String email, String errorSignature) {
- return submitBug(log, email, generateSubject(errorSignature), errorSignature, BugSystemInfo.appName, BugSystemInfo.version, BugSystemInfo.locale);
- }
-
- /**
- * public method for submitting a bug or anything else
- */
- public static boolean submitBug(Object log, String email,String subject,String errorSignature,
- String appName, String version, String locale
- ) {
- Map map = new java.util.Hashtable();
-
- if (extraInfoProvider!=null) {
- try {
- extraInfoProvider.addInfoForSubmit(map);
- }
- catch (Throwable th) {
- map.put("appInfoProviderError", getStackTrace(th) );
- }
- }
-
- if (log instanceof Map) {
- map.putAll((Map) log);
- }
- else {
- map.put("log", log==null?"null":log);
- }
-
- map.put("appName", String.valueOf(appName));
- map.put("appVersion", String.valueOf(version));
- map.put("appLocale", String.valueOf(locale));
-
- map.put("grasshopperVersion", BugManager.VER);
-
- map.putAll( BugSystemInfo.addSystemInfo() );
-
- if (!map.containsKey("recipient")) {
- map.put("recipient", RECIPIENT);
- }
- map.put("subject", subject);
-
- if (email != null) {
- map.put("email", email);
- }
- else if (!map.containsKey("email")) { // email may have been added by extraInfoProvider.addInfoForSubmit
- map.put("email", "no-email");
- }
-
- map.put("env_report","REMOTE_HOST,HTTP_USER_AGENT");
-
- if (errorSignature != null) {
- map.put("errorSignature", errorSignature);
- }
-
- try {
- BugSubmitterMultipart.send(TF_MAIL_URL, map);
- System.out.println("[grasshopper] send ok");
- return true;
- }
- catch (Throwable th) {
- try {
- map.put("grasshopperError", getStackTrace(th) );
- doPost(FORM_MAIL_URL, map);
- System.out.println("[grasshopper] send ok ish "+th);
- return true;
- }
- catch(Throwable th2) {
- System.out.println("[grasshopper] errors sending: "+th+" AND "+th2);
- return false;
- }
- }
- }
-
- public static String getStackTrace(Throwable th) {
- StringWriter error = new StringWriter();
- th.printStackTrace( new PrintWriter(error) );
- return error.toString();
- }
-
- /**
- * same value as cgi_post_max in FormMail.cgi
- */
- private static final int MAX_PAYLOAD_SIZE = 1000000;
-
- public static void doPost(String url, Map map) throws IOException {
-
- URLConnection conn = new URL(url).openConnection();
- conn.setDoOutput(true);
- OutputStreamWriter wr = new OutputStreamWriter(new LimitedOutputStream(conn.getOutputStream(), MAX_PAYLOAD_SIZE), "UTF-8");
-
- doPost(wr,map);
-
- wr.close();
-
- // Get the response
- int code = 200;
- if (conn instanceof HttpURLConnection) {
- code = ((HttpURLConnection)conn).getResponseCode();
- }
-
- //StringBuffer buffer = new StringBuffer();
- BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
- String line;
- while ((line = rd.readLine()) != null) {
- // buffer.append(line);
- // buffer.append("\n");
- }
-
- rd.close();
- //return buffer.toString();
- // do NOT read the responce into a buffer, as we do not need it anyway
-
- // TODO handle 301 redirect
-
- if (code / 100 != 2) {
- throw new IOException("http error " + code);
- }
- }
-
- public static void doPost(OutputStreamWriter getpostb, Map map) throws IOException {
-
- boolean firstDone=false;
-
- Iterator enu = getKeysLogTextLast(map).iterator();
- while(enu.hasNext()) {
-
- if (firstDone) {
- getpostb.append("&");
- }
- else {
- firstDone = true;
- }
-
- Object key = enu.next();
- getpostb.append(URLEncoder.encode(String.valueOf(key), "UTF-8"));
-
- getpostb.append("=");
-
- Object object = map.get(key);
- if (object instanceof LogText) {
- String line;
- while((line = ((LogText)object).readLine()) != null) {
- getpostb.append( URLEncoder.encode( line+"<br>\n" , "UTF-8") );
- }
- }
- else {
- String value = String.valueOf( object );
- value = value.replaceAll("\\n|\\r\\n", "<br>$0"); // add <br> to the end of every line
- getpostb.append( URLEncoder.encode( value , "UTF-8"));
- }
- }
- }
-
- public static List getKeysLogTextLast(final Map map) {
- List keys = new ArrayList(map.keySet());
- Collections.sort(keys, new Comparator() {
- public int compare(Object key1, Object key2) {
- Object value1 = map.get(key1);
- Object value2 = map.get(key2);
- if (value1 instanceof LogText && !(value2 instanceof LogText)) {
- return 1;
- }
- if (value2 instanceof LogText && !(value1 instanceof LogText)) {
- return -1;
- }
- return String.valueOf(key1).compareTo(String.valueOf(key2));
- }
- });
- return keys;
- }
-}
Deleted: Grasshopper/src/net/yura/grasshopper/BugSubmitterMultipart.java
===================================================================
--- Grasshopper/src/net/yura/grasshopper/BugSubmitterMultipart.java 2024-12-27 14:08:21 UTC (rev 1054)
+++ Grasshopper/src/net/yura/grasshopper/BugSubmitterMultipart.java 2024-12-27 15:20:16 UTC (rev 1055)
@@ -1,137 +0,0 @@
-package net.yura.grasshopper;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.net.HttpURLConnection;
-import java.net.URL;
-import java.net.URLConnection;
-import java.util.Iterator;
-import java.util.Map;
-import org.apache.http.entity.mime.MIME;
-import org.apache.http.entity.mime.MultipartEntity;
-import org.apache.http.entity.mime.content.AbstractContentBody;
-import org.apache.http.entity.mime.content.ByteArrayBody;
-import org.apache.http.entity.mime.content.StringBody;
-
-/**
- * @author Yura Mamyrin
- */
-public class BugSubmitterMultipart {
-
- private static final int MAX_PAYLOAD_SIZE = 5000000;
-
- static void send(String url, Map map) throws IOException {
-
- // create the multipart request and add the parts to it
- MultipartEntity requestContent = new MultipartEntity();
-
- // get Screenshots of windows first, so any paint errors will go into the logs
- ScreenShot[] images = BugUIInfo.getFrames();
-
- Iterator it = BugSubmitter.getKeysLogTextLast(map).iterator();
- while (it.hasNext()) {
- Object key = it.next();
- Object value = map.get(key);
-
- if (value instanceof LogText) {
-// can not use this as unknown length fails on Android
-// requestContent.addPart(key, new InputStreamBody( new FileInputStream( (File)value ) , null ) );
-// can not use this as length may not match when writing file
-// requestContent.addPart(key, new FileBody( (File)value ) {
-// public String getFilename() { return null; }
-// });
-
- final LogText logtext = (LogText)value;
- requestContent.addPart(String.valueOf(key), new AbstractContentBody("text/plain") {
- public long getContentLength() {
- return logtext.getContentLength();
- }
- public void writeTo(OutputStream out) throws IOException {
- logtext.writeTo(out);
- }
- public String getFilename() {
- return null;
- }
- public String getCharset() {
- return LogText.CHARSET;
- }
- public String getTransferEncoding() {
- return MIME.ENC_8BIT;
- }
- } );
- }
- else {
- requestContent.addPart(String.valueOf(key), new StringBody(String.valueOf(value)));
- }
- }
-
- for (int c=0;c<images.length;c++) {
- ScreenShot ss = images[c];
- byte[] data = ss.getEncodedData();
- if (data!=null) {
- // we need to use img0 - img9 for the name of this field as this is what we set up in default.trc
- // upload_img0: gif jpg jpeg png xxx
- // ...
- // upload_img9: gif jpg jpeg png xxx
- requestContent.addPart("img"+c, new ByteArrayBody(data, "frame_"+c+"."+ss.getFileType() ));
- }
- String error = ss.getError();
- if (error!=null) {
- requestContent.addPart("img"+c+"Error", new StringBody( error ));
- }
- }
-
- doPost(url, requestContent);
- }
-
- /**
- * this is a copy and paste from net.yura.domination.tools.mapeditor.MapsTools#doPost
- */
- public static void doPost(String url, MultipartEntity requestContent) throws IOException {
-
- URLConnection conn = new URL(url).openConnection();
- conn.setDoOutput(true);
-
- org.apache.http.Header contentType = requestContent.getContentType();
- conn.setRequestProperty(contentType.getName(), contentType.getValue());
-
- // this seems to be null and does not seem to be needed
- //org.apache.http.Header contentEncoding = requestContent.getContentEncoding();
- //conn.setRequestProperty(contentEncoding.getName(), contentEncoding.getValue());
-
- //conn.setRequestProperty("content-type","multipart/form-data");
- conn.setRequestProperty("Content-Length", String.valueOf(requestContent.getContentLength()) );
-
- OutputStream out = conn.getOutputStream();
-
- //System.out.println("sending " + requestContent.getContentLength());
-
- requestContent.writeTo( out );
- out.close();
-
- // Get the response
- int code = 200;
- if (conn instanceof HttpURLConnection) {
- code = ((HttpURLConnection)conn).getResponseCode();
- }
-
- //StringBuffer buffer = new StringBuffer();
- BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
- String line;
- while ((line = rd.readLine()) != null) {
- // buffer.append(line);
- // buffer.append("\n");
- }
- rd.close();
- //return buffer.toString();
- // do NOT read the responce into a buffer, as we do not need it anyway
-
- // TODO handle 301 redirect
-
- if (code / 100 != 2) {
- throw new IOException("http error " + code);
- }
- }
-}
Deleted: Grasshopper/src/net/yura/grasshopper/BugSystemInfo.java
===================================================================
--- Grasshopper/src/net/yura/grasshopper/BugSystemInfo.java 2024-12-27 14:08:21 UTC (rev 1054)
+++ Grasshopper/src/net/yura/grasshopper/BugSystemInfo.java 2024-12-27 15:20:16 UTC (rev 1055)
@@ -1,130 +0,0 @@
-package net.yura.grasshopper;
-
-import java.io.File;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Properties;
-
-/**
- * @author Yura Mamyrin
- */
-public class BugSystemInfo {
-
- public static String appName,version,locale;
-
- public static Map addSystemInfo() {
-
- String systemLocale,localhost,systemProperties,environment,lookandfeel,installDate,memoryInfo,diskInfo;
-
- try {
- systemLocale = java.util.Locale.getDefault().toString();
- }
- catch (Throwable th) {
- systemLocale = th.toString();
- }
-
- try {
- localhost = java.net.InetAddress.getLocalHost().toString();
- }
- catch (Throwable e) {
- localhost = e.toString();
- }
-
- try {
- Properties props = System.getProperties();
- Iterator i = props.entrySet().iterator();
- StringBuffer sb = new StringBuffer();
- while (i.hasNext()) {
- String line = String.valueOf(i.next());
- sb.append( line.replace("\n", "\\n").replace("\r", "\\r") );
- sb.append("\n");
- }
- systemProperties = sb.toString();
- }
- catch (Throwable e) {
- systemProperties = e.toString();
- }
-
- try {
- Map env = System.getenv();
- Iterator i = env.entrySet().iterator();
- StringBuffer sb = new StringBuffer();
- while (i.hasNext()) {
- String line = String.valueOf(i.next());
- sb.append( line.replace("\n", "\\n").replace("\r", "\\r") );
- sb.append("\n");
- }
- environment = sb.toString();
- }
- catch (Throwable e) {
- environment = e.toString();
- }
-
-
- try {
- lookandfeel = BugUIInfo.getLookAndFeel();
- }
- catch (Throwable e) {
- lookandfeel = e.toString();
- }
-
- try {
- installDate = new Date(new File(".").lastModified()).toString();
- }
- catch (Throwable e) {
- installDate = e.toString();
- }
-
- try {
- Runtime rt = Runtime.getRuntime();
-
- StringBuffer sb = new StringBuffer();
- final int mb = 1024 * 1024;
- sb.append("Free memory (MB): ");
- sb.append(rt.freeMemory() / mb);
- sb.append("\nTotal memory (MB): ");
- sb.append(rt.totalMemory() / mb);
- sb.append("\nMax memory (MB): ");
- sb.append(rt.maxMemory() / mb);
-
- memoryInfo = sb.toString();
- }
- catch (Throwable e) {
- memoryInfo = e.toString();
- }
-
- try {
- File[] roots = File.listRoots();
- StringBuffer sb = new StringBuffer();
- final int mb = 1024 * 1024;
- for (int c = 0; c < roots.length; c++) {
- File root = roots[c];
- sb.append(root);
- sb.append("\nFree Space (MB): ");
- sb.append(root.getFreeSpace() / mb);
- sb.append("\nTotal Space (MB): ");
- sb.append(root.getTotalSpace() / mb);
- sb.append("\nUsable Space (MB): ");
- sb.append(root.getUsableSpace() / mb);
- }
- diskInfo = sb.toString();
- }
- catch (Throwable e) {
- diskInfo = e.toString();
- }
-
- Map map = new java.util.Hashtable();
- map.put("systemLocale",systemLocale);
- map.put("localhost",localhost);
- map.put("systemProperties",systemProperties);
- map.put("environment",environment);
- map.put("lookandfeel",lookandfeel);
- map.put("installDate",installDate);
- map.put("memoryInfo", memoryInfo);
- map.put("diskInfo", diskInfo);
- map.put("submitDate",new java.util.Date().toString());
-
- return map;
- }
-}
Deleted: Grasshopper/src/net/yura/grasshopper/ColorFormatter.java
===================================================================
--- Grasshopper/src/net/yura/grasshopper/ColorFormatter.java 2024-12-27 14:08:21 UTC (rev 1054)
+++ Grasshopper/src/net/yura/grasshopper/ColorFormatter.java 2024-12-27 15:20:16 UTC (rev 1055)
@@ -1,87 +0,0 @@
-package net.yura.grasshopper;
-
-import java.util.logging.Formatter;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-
-/**
- * @author Yura Mamyrin
- */
-public class ColorFormatter extends Formatter {
-
- public static final String ANSI_RESET = "\u001B[0m";
-
- public static final String ANSI_BLACK = "\u001B[30m";
- public static final String ANSI_RED = "\u001B[31m";
- public static final String ANSI_GREEN = "\u001B[32m";
- public static final String ANSI_YELLOW = "\u001B[33m";
- public static final String ANSI_BLUE = "\u001B[34m";
- public static final String ANSI_PURPLE = "\u001B[35m";
- public static final String ANSI_CYAN = "\u001B[36m";
- public static final String ANSI_LIGHT_GARY = "\u001B[37m";
-
- public static final String ANSI_DARK_GRAY = "\u001B[1;30m";
- public static final String ANSI_LIGHT_RED = "\u001B[1;31m";
- public static final String ANSI_LIGHT_GREEN = "\u001B[1;32m";
- public static final String ANSI_LIGHT_YELLOW = "\u001B[1;33m";
- public static final String ANSI_LIGHT_BLUE = "\u001B[1;34m";
- public static final String ANSI_LIGHT_PURPLE = "\u001B[1;35m";
- public static final String ANSI_LIGHT_CYAN = "\u001B[1;36m";
- public static final String ANSI_WHITE = "\u001B[1;37m";
-
- private Formatter parent;
-
- public ColorFormatter(Formatter parent) {
- this.parent = parent;
- }
-
- public String format(LogRecord record) {
- return getColor( record.getLevel().intValue() ) + parent.format(record) + ANSI_RESET;
- }
-
- public static String getColor(int level) {
- if (level>=Level.SEVERE.intValue()) {
- return ANSI_RED;
- }
- if (level>=Level.WARNING.intValue()) {
- return ANSI_RED;
- }
- if (level>=Level.INFO.intValue()) {
- return ""; // default color, can be green or white
- }
- if (level>=Level.CONFIG.intValue()) {
- return ANSI_YELLOW;
- }
- if (level>=Level.FINE.intValue()) {
- return ANSI_PURPLE;
- }
- if (level>=Level.FINER.intValue()) {
- return ANSI_BLUE;
- }
- // if (level>=Level.FINEST.intValue())
- return ANSI_CYAN;
- }
-
- public static void main(String[] args) {
-
- System.out.println(
- ANSI_BLACK+"BLACK"+ANSI_RESET+"\n"+
- ANSI_RED+"RED"+ANSI_RESET+"\n"+
- ANSI_GREEN+"GREEN"+ANSI_RESET+"\n"+
- ANSI_YELLOW+"YELLOW"+ANSI_RESET+"\n"+
- ANSI_BLUE+"BLUE"+ANSI_RESET+"\n"+
- ANSI_PURPLE+"PURPLE"+ANSI_RESET+"\n"+
- ANSI_CYAN+"CYAN"+ANSI_RESET+"\n"+
- ANSI_LIGHT_GARY+"LIGHT_GRAY"+ANSI_RESET+"\n"+
- ANSI_DARK_GRAY+"DARK_GRAY"+ANSI_RESET+"\n"+
- ANSI_LIGHT_RED+"LIGHT_RED"+ANSI_RESET+"\n"+
- ANSI_LIGHT_GREEN+"LIGHT_GREEN"+ANSI_RESET+"\n"+
- ANSI_LIGHT_YELLOW+"LIGHT_YELLOW"+ANSI_RESET+"\n"+
- ANSI_LIGHT_BLUE+"LIGHT_BLUE"+ANSI_RESET+"\n"+
- ANSI_LIGHT_PURPLE+"LIGHT_PURPLE"+ANSI_RESET+"\n"+
- ANSI_LIGHT_CYAN+"LIGHT_CYAN"+ANSI_RESET+"\n"+
- ANSI_WHITE+"WHITE"+ANSI_RESET+"\n");
-
- }
-
-}
Deleted: Grasshopper/src/net/yura/grasshopper/LogFile.java
===================================================================
--- Grasshopper/src/net/yura/grasshopper/LogFile.java 2024-12-27 14:08:21 UTC (rev 1054)
+++ Grasshopper/src/net/yura/grasshopper/LogFile.java 2024-12-27 15:20:16 UTC (rev 1055)
@@ -1,66 +0,0 @@
-package net.yura.grasshopper;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-/**
- * @author Yura Mamyrin
- */
-public class LogFile implements LogText {
-
- File file;
- long length = -1;
-
- public LogFile(File file) {
- this.file = file;
- }
-
- public long getContentLength() {
- if (length == -1) {
- length = file.length();
- }
- return length;
- }
-
- public void writeTo(OutputStream out) throws IOException {
- if (out == null) {
- throw new IllegalArgumentException("Output stream may not be null");
- }
- InputStream in = new FileInputStream(this.file);
- try {
-
- long totalLength = getContentLength();
- long totalWritten = 0;
-
- byte[] tmp = new byte[2048]; // 4096
- int l;
- while ((l = in.read(tmp)) != -1) {
- if ( totalWritten+l > totalLength ) {
- out.write(tmp, 0, (int)(totalLength - totalWritten) );
- break;
- }
- else {
- totalWritten = totalWritten + l;
- out.write(tmp, 0, l);
- }
- }
- out.flush();
- }
- finally {
- in.close();
- }
- }
-
- BufferedReader br;
- public String readLine() throws IOException {
- if (br==null) {
- br = new BufferedReader(new FileReader( file ));
- }
- return br.readLine();
- }
-}
Deleted: Grasshopper/src/net/yura/grasshopper/LogList.java
===================================================================
--- Grasshopper/src/net/yura/grasshopper/LogList.java 2024-12-27 14:08:21 UTC (rev 1054)
+++ Grasshopper/src/net/yura/grasshopper/LogList.java 2024-12-27 15:20:16 UTC (rev 1055)
@@ -1,54 +0,0 @@
-package net.yura.grasshopper;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.List;
-
-/**
- * @author Yura Mamyrin
- */
-public class LogList implements LogText {
-
- List log;
- int size=-1;
-
- public LogList(List log) {
- this.log = log;
- }
-
- private int getListSize() {
- if (size == -1) {
- size = log.size();
- }
- return size;
- }
-
- public long getContentLength() {
- int s = getListSize();
- int length=0;
- for (int c=0;c<s;c++) {
- length = length + String.valueOf(log.get(c)).length() +1; // 1 is for the /n
- }
- return length;
- }
-
- public void writeTo(OutputStream out) throws IOException {
- int s = getListSize();
- for (int c=0;c<s;c++) {
- String line = String.valueOf(log.get(c));
- out.write( line.getBytes(CHARSET) );
- out.write('\n');
- }
- }
-
- int pos;
- public String readLine() {
- if (pos<log.size()) {
- String result = String.valueOf(log.get(pos));
- pos++;
- return result;
- }
- return null;
- }
-
-}
Deleted: Grasshopper/src/net/yura/grasshopper/LogText.java
===================================================================
--- Grasshopper/src/net/yura/grasshopper/LogText.java 2024-12-27 14:08:21 UTC (rev 1054)
+++ Grasshopper/src/net/yura/grasshopper/LogText.java 2024-12-27 15:20:16 UTC (rev 1055)
@@ -1,34 +0,0 @@
-package net.yura.grasshopper;
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-/**
- * @author Yura Mamyrin
- */
-public interface LogText {
-
- /**
- * we use US-ASCII instead of UTF-8 because logs are usually in plain text
- * and LogList works out the length of the data by counting string.length
- * ALSO, TFMail seems to ignore UTF-8 and always displays text as US-ASCII
- */
- public static final String CHARSET = "US-ASCII";
-
- /**
- * @return the length of the content encoded using {@see #CHARSET}
- */
- long getContentLength();
-
-
- /**
- * @param out write the content using {@see #CHARSET}
- */
- void writeTo(OutputStream out) throws IOException;
-
- /**
- * alternative method for getting content line by line (used as a fallback)
- */
- String readLine() throws IOException;
-
-}
Deleted: Grasshopper/src/net/yura/grasshopper/LoggingOutputStream.java
===================================================================
--- Grasshopper/src/net/yura/grasshopper/LoggingOutputStream.java 2024-12-27 14:08:21 UTC (rev 1054)
+++ Grasshopper/src/net/yura/grasshopper/LoggingOutputStream.java 2024-12-27 15:20:16 UTC (rev 1055)
@@ -1,108 +0,0 @@
-package net.yura.grasshopper;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-/**
- * An OutputStream that writes contents to a Logger upon each call to flush()
- * @see com.android.internal.os.AndroidPrintStream
- */
-class LoggingOutputStream extends ByteArrayOutputStream {
-
- private static final String lineSeparator = System.getProperty("line.separator");
- private static final Logger logger = Logger.getLogger("LOS");
-
- private Level level;
-
- /**
- * Constructor
- * @param logger Logger to write to
- * @param level Level at which to write the log message
- */
- public LoggingOutputStream(Level level) {
- super();
- this.level = level;
- }
-
- /**
- * upon flush() write the existing contents of the OutputStream
- * to the logger as a log record.
- * @throws java.io.IOException in case of error
- * @see BugManager#intercept()
- */
- public synchronized void flush() throws IOException {
- // TODO we use the system defualt encoding here, pass encoding to toString to use a specific encoding
- String record = this.toString();
-
- // only flush to logger if ends with a end of line char
- if (record.endsWith("\r\n") || record.endsWith("\n") || record.endsWith(lineSeparator)) {
- super.reset();
-
- if (record.endsWith("\r\n")) {
- record = record.substring(0, record.length()-2);
- }
- else if (record.endsWith("\n")) {
- record = record.substring(0, record.length()-1);
- }
- else {
- record = record.substring(0, record.length()-lineSeparator.length());
- }
-
- StackTraceElement source = level == StdOutErrLevel.STDERR ? findSourceStackElement() : null;
-
- // sourceClass and sourceMethod are ALWAYS "LoggingOutputStream flush" so we do not care
- logger.logp(level, source == null ? null : source.getClassName(), source == null ? null : source.getMethodName(), record);
- }
- }
-
- private static StackTraceElement findSourceStackElement() {
-
- // [0] = Thread.getStackTrace
- // [1] = LoggingOutputStream.findSourceStackElement
- // [2] = LoggingOutputStream.flush
- // [3] = PrintStream.write
- // ... = (some internal JVM methods)
- // [?] = OutputStreamWriter.flushBuffer
- // [?] = PrintStream.newLine
- // [?] = PrintStream.println
- // [?] = Throwable$WrappedPrintStream.println <~~ printElement
- // [?] = Throwable.printStackTrace
- // [?] = Throwable.printStackTrace
- // [?] = Throwable.printStackTrace
- // [?] = ActualClass.actualMethod <~~ the culprit
-
- try {
-
- StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace();
-
- boolean printStackTraceFound = false;
- boolean printStreamFound = false;
- StackTraceElement printElement = null; // the method that called the PrintStream
-
- for (int c = 0; c < stackTraceElements.length; c++) {
- StackTraceElement stackTraceElement = stackTraceElements[c];
- if ("java.lang.Throwable".equals(stackTraceElement.getClassName()) && "printStackTrace".equals(stackTraceElement.getMethodName())) {
- printStackTraceFound = true;
- }
- else if (printStackTraceFound) {
- return stackTraceElement;
- }
-
- // this is just a bit of a guess, we are looking for the last method that called a PrintStream
- boolean lastPrintStreamFound = printStreamFound;
- printStreamFound = "java.io.PrintStream".equals(stackTraceElement.getClassName());
- if (lastPrintStreamFound && !printStreamFound) {
- printElement = stackTraceElement;
- }
- }
-
- return printElement;
- }
- catch (Throwable th) {
- // we should never fail here, if we return no value then its ok
- return null;
- }
- }
-}
Deleted: Grasshopper/src/net/yura/grasshopper/ReallySimpleFormatter.java
===================================================================
--- Grasshopper/src/net/yura/grasshopper/ReallySimpleFormatter.java 2024-12-27 14:08:21 UTC (rev 1054)
+++ Grasshopper/src/net/yura/grasshopper/ReallySimpleFormatter.java 2024-12-27 15:20:16 UTC (rev 1055)
@@ -1,49 +0,0 @@
-package net.yura.grasshopper;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.logging.Formatter;
-import java.util.logging.LogRecord;
-
-/**
- * @author Yura Mamyrin
- */
-public class ReallySimpleFormatter extends Formatter {
-
- // Line separator string. This is the value of the line.separator
- // property at the moment that the SimpleFormatter was created.
- private String lineSeparator = System.getProperty("line.separator");
-
- /**
- * Format the given LogRecord.
- * @param record the log record to be formatted.
- * @return a formatted log record
- */
- public synchronized String format(LogRecord record) {
- StringBuffer sb = new StringBuffer();
-
- sb.append(record.getLevel().getName()); // getLocalizedName
- sb.append(": ");
-
- String message = formatMessage(record);
- if (message!=null || record.getThrown()==null) {
- sb.append(message);
- sb.append(lineSeparator);
- }
-
-
- if (record.getThrown() != null) {
- try {
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- record.getThrown().printStackTrace(pw);
- pw.close();
- sb.append(sw.toString());
- } catch (Exception ex) {
- }
- }
-
- return sb.toString();
- }
-}
-
Deleted: Grasshopper/src/net/yura/grasshopper/ScreenShot.java
===================================================================
--- Grasshopper/src/net/yura/grasshopper/ScreenShot.java 2024-12-27 14:08:21 UTC (rev 1054)
+++ Grasshopper/src/net/yura/grasshopper/ScreenShot.java 2024-12-27 15:20:16 UTC (rev 1055)
@@ -1,39 +0,0 @@
-package net.yura.grasshopper;
-
-/**
- * @author Yura Mamyrin
- */
-public class ScreenShot {
-
- private byte[] encodedData;
- private String fileType;
- private String error;
-
- public ScreenShot() {
-
- }
-
- public void setEncodedData(byte[] encodedData) {
- this.encodedData = encodedData;
- }
-
- public void setFileType(String fileType) {
- this.fileType = fileType;
- }
-
- public void setError(String error) {
- this.error = error;
- }
-
- public byte[] getEncodedData() {
- return encodedData;
- }
-
- public String getFileType() {
- return fileType;
- }
-
- public String getError() {
- return error;
- }
-}
Modified: Grasshopper/src/net/yura/grasshopper/SimpleBug.java
===================================================================
--- Grasshopper/src/net/yura/grasshopper/SimpleBug.java 2024-12-27 14:08:21 UTC (rev 1054)
+++ Grasshopper/src/net/yura/grasshopper/SimpleBug.java 2024-12-27 15:20:16 UTC (rev 1055)
@@ -1,5 +1,8 @@
package net.yura.grasshopper;
+import net.yura.grasshopper.info.BugSystemInfo;
+import net.yura.grasshopper.info.LogFile;
+import net.yura.grasshopper.submitter.BugSubmitter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
@@ -25,12 +28,10 @@
instance = this;
}
-
private void doSubmit(String errorSignature) {
BugSubmitter.submitBug(toString(), errorSignature);
}
-
/**
* keeps the full log in memory
*/
@@ -43,7 +44,6 @@
if (instance==null) {
new SimpleBug();
}
-
}
/**
@@ -82,7 +82,6 @@
catch (IOException ex) {
throw new RuntimeException(ex);
}
-
}
private static boolean canWrite(File file) {
@@ -97,5 +96,4 @@
catch (Exception ex) { }
return false;
}
-
}
Deleted: Grasshopper/src/net/yura/grasshopper/StdOutErrLevel.java
===================================================================
--- Grasshopper/src/net/yura/grasshopper/StdOutErrLevel.java 2024-12-27 14:08:21 UTC (rev 1054)
+++ Grasshopper/src/net/yura/grasshopper/StdOutErrLevel.java 2024-12-27 15:20:16 UTC (rev 1055)
@@ -1,44 +0,0 @@
-package net.yura.grasshopper;
-
-import java.io.InvalidObjectException;
-import java.io.ObjectStreamException;
-import java.util.logging.Level;
-
-/**
- * Class defining 2 new Logging levels, one for STDOUT, one for STDERR,
- * used when multiplexing STDOUT and STDERR into the same rolling log file
- * via the Java Logging APIs.
- */
-public class StdOutErrLevel extends Level {
-
- /**
- * Private constructor
- */
- private StdOutErrLevel(String name, int value) {
- super(name, value);
- }
- /**
- * Level for STDOUT activity.
- */
- public static Level STDOUT = new StdOutErrLevel("OUT", Level.INFO.intValue()+10);
- /**
- * Level for STDERR activity
- */
- public static Level STDERR = new StdOutErrLevel("ERR", Level.WARNING.intValue()+10);
-
- /**
- * Method to avoid creating duplicate instances when deserializing the
- * object.
- * @return the singleton instance of this <code>Level</code> value in this
- * classloader
- * @throws ObjectStreamException If unable to deserialize
- */
- protected Object readResolve() throws ObjectStreamException {
- if (this.intValue() == STDOUT.intValue())
- return STDOUT;
- if (this.intValue() == STDERR.intValue())
- return STDERR;
- throw new InvalidObjectException("Unknown instance :" + this);
- }
-
-}
Deleted: Grasshopper/src/net/yura/grasshopper/TextHandler.java
===================================================================
--- Grasshopper/src/net/yura/grasshopper/TextHandler.java 2024-12-27 14:08:21 UTC (rev 1054)
+++ Grasshopper/src/net/yura/grasshopper/TextHandler.java 2024-12-27 15:20:16 UTC (rev 1055)
@@ -1,163 +0,0 @@
-package net.yura.grasshopper;
-
-import java.io.Writer;
-import java.util.Arrays;
-import java.util.logging.ErrorManager;
-import java.util.logging.Handler;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-
-/**
- * @author Yura Mamyrin
- */
-public class TextHandler extends Handler {
-
- private boolean doneHeader;
- private Writer writer;
- private Level pushLevel;
- private BugManager sps;
- private boolean printStackTrace;
-
- public TextHandler(Writer writer,Level pushLevel,BugManager sps) {
- this.writer = writer;
- this.pushLevel = pushLevel;
- this.sps = sps;
- setFormatter( new ReallySimpleFormatter() );
- }
-
- public void publish(LogRecord record) {
- if (!isLoggable(record)) {
- return;
- }
- String msg;
- try {
- msg = getFormatter().format(record);
- }
- catch (Exception ex) {
- // We don't want to throw an exception here, but we
- // report the exception to any registered ErrorManager.
- reportError(null, ex, ErrorManager.FORMAT_FAILURE);
- return;
- }
-
- try {
- if (!doneHeader) {
- writer.write(getFormatter().getHead(this));
- doneHeader = true;
- }
- writer.write(msg);
- writer.flush(); // in case this is used for files, we want to flush each record
- }
- catch (Exception ex) {
- // We don't want to throw an exception here, but we
- // report the exception to any registered ErrorManager.
- reportError(null, ex, ErrorManager.WRITE_FAILURE);
- }
-
- boolean previousPrintStackTrace = printStackTrace;
- printStackTrace = StdOutErrLevel.STDERR.equals(record.getLevel());
-
- if (record.getLevel().intValue() >= pushLevel.intValue()) {
-
- try {
- if (previousPrintStackTrace && printStackTrace && record.getMessage() != null &&
- (record.getMessage().startsWith("\tat ") || record.getMessage().matches("\\t\\.\\.\\. \\d+ more"))) {
- return;
- }
-
- if (BugSubmitter.extraInfoProvider != null && BugSubmitter.extraInfoProvider.ignoreError(record) ) {
- return;
- }
- }
- catch(Exception ex) {
- reportError(null, ex, ErrorManager.GENERIC_FAILURE);
- }
-
- String errorSignature = null;
- try {
- errorSignature = generateErrorSignature(record);
- }
- catch (Exception ex) {
- reportError(null, ex, ErrorManager.GENERIC_FAILURE);
- }
-
- // we really want to avoid any possibility of throwing from this method
- // as we have no idea what we may be messing up, as anything can call the logger
- try {
- BugManager.action(sps, errorSignature);
- }
- catch (Exception ex) {
- reportError(null, ex, ErrorManager.GENERIC_FAILURE);
- }
- }
- }
-
- String generateErrorSignature(LogRecord record) {
-
- Throwable throwable = record.getThrown();
- if (throwable != null) {
- while (throwable.getCause() != null) {
- throwable = throwable.getCause();
- }
- StackTraceElement[] stackTrace = throwable.getStackTrace();
- StringBuilder sig = new StringBuilder();
- for (int c = 0; c < stackTrace.length; c++) {
- StackTraceElement line = stackTrace[c];
- if (line.getLineNumber() > 0 && !isSystemClass(line.getClassName())) {
- sig.append(line);
- sig.append(" ");
- }
- }
- if (sig.length() > 0) {
- return sig.substring(0, Math.min(1000, sig.length() - 1)); // remove space from the end
- }
- }
-
- String sourceClassName = record.getSourceClassName();
- String sourceMethodName = record.getSourceMethodName();
- Object[] param = record.getParameters();
-
- return record.getLoggerName() + " "
- + (sourceClassName != null || sourceMethodName != null ? "(" + sourceClassName + " " + sourceMethodName + ") " : "")
- + record.getLevel() + " "
- + record.getMessage() + (param == null ? "" : " " + Arrays.asList(param).toString()) + " "
- + record.getResourceBundleName();
- }
-
- boolean isSystemClass(String aClass) {
- return aClass.startsWith("java.")
- || aClass.startsWith("javax.swing.")
- || aClass.startsWith("android.")
- || aClass.startsWith("com.android.")
- || aClass.startsWith("libcore.")
- || aClass.startsWith("dalvik.");
- }
-
- public void flush() {
-// we flush after each record is written, so we do not need to flush here
-// try {
-// writer.flush();
-// } catch (Exception ex) {
-// // We don't want to throw an exception here, but we
-// // report the exception to any registered ErrorManager.
-// reportError(null, ex, ErrorManager.FLUSH_FAILURE);
-// }
- }
-
- public void close() throws SecurityException {
- try {
- if (!doneHeader) {
- writer.write(getFormatter().getHead(this));
- doneHeader = true;
- }
- writer.write(getFormatter().getTail(this));
- writer.flush();
- writer.close();
- } catch (Exception ex) {
- // We don't want to throw an exception here, but we
- // report the exception to any registered ErrorManager.
- reportError(null, ex, ErrorManager.CLOSE_FAILURE);
- }
- writer = null;
- }
-}
Copied: Grasshopper/src/net/yura/grasshopper/info/ApplicationInfoProvider.java (from rev 1054, Grasshopper/src/net/yura/grasshopper/ApplicationInfoProvider.java)
===================================================================
--- Grasshopper/src/net/yura/grasshopper/info/ApplicationInfoProvider.java (rev 0)
+++ Grasshopper/src/net/yura/grasshopper/info/ApplicationInfoProvider.java 2024-12-27 15:20:16 UTC (rev 1055)
@@ -0,0 +1,14 @@
+package net.yura.grasshopper.info;
+
+import java.util.Map;
+import java.util.logging.LogRecord;
+
+/**
+ * @author Yura Mamyrin
+ */
+public interface ApplicationInfoProvider {
+
+ boolean ignoreError(LogRecord record);
+ void addInfoForSubmit(Map map);
+
+}
Copied: Grasshopper/src/net/yura/grasshopper/info/BugSystemInfo.java (from rev 1054, Grasshopper/src/net/yura/grasshopper/BugSystemInfo.java)
===================================================================
--- Grasshopper/src/net/yura/grasshopper/info/BugSystemInfo.java (rev 0)
+++ Grasshopper/src/net/yura/grasshopper/info/BugSystemInfo.java 2024-12-27 15:20:16 UTC (rev 1055)
@@ -0,0 +1,131 @@
+package net.yura.grasshopper.info;
+
+import java.io.File;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+import net.yura.grasshopper.BugUIInfo;
+
+/**
+ * @author Yura Mamyrin
+ */
+public class BugSystemInfo {
+
+ public static String appName,version,locale;
+
+ public static Map addSystemInfo() {
+
+ String systemLocale,localhost,systemProperties,environment,lookandfeel,installDate,memoryInfo,diskInfo;
+
+ try {
+ systemLocale = java.util.Locale.getDefault().toString();
+ }
+ catch (Throwable th) {
+ systemLocale = th.toString();
+ }
+
+ try {
+ localhost = java.net.InetAddress.getLocalHost().toString();
+ }
+ catch (Throwable e) {
+ localhost = e.toString();
+ }
+
+ try {
+ Properties props = System.getProperties();
+ Iterator i = props.entrySet().iterator();
+ StringBuffer sb = new StringBuffer();
+ while (i.hasNext()) {
+ String line = String.valueOf(i.next());
+ sb.append( line.replace("\n", "\\n").replace("\r", "\\r") );
+ sb.append("\n");
+ }
+ systemProperties = sb.toString();
+ }
+ catch (Throwable e) {
+ systemProperties = e.toString();
+ }
+
+ try {
+ Map env = System.getenv();
+ Iterator i = env.entrySet().iterator();
+ StringBuffer sb = new StringBuffer();
+ while (i.hasNext()) {
+ String line = String.valueOf(i.next());
+ sb.append( line.replace("\n", "\\n").replace("\r", "\\r") );
+ sb.append("\n");
+ }
+ environment = sb.toString();
+ }
+ catch (Throwable e) {
+ environment = e.toString();
+ }
+
+
+ try {
+ lookandfeel = BugUIInfo.getLookAndFeel();
+ }
+ catch (Throwable e) {
+ lookandfeel = e.toString();
+ }
+
+ try {
+ installDate = new Date(new File(".").lastModified()).toString();
+ }
+ catch (Throwable e) {
+ installDate = e.toString();
+ }
+
+ try {
+ Runtime rt = Runtime.getRuntime();
+
+ StringBuffer sb = new StringBuffer();
+ final int mb = 1024 * 1024;
+ sb.append("Free memory (MB): ");
+ sb.append(rt.freeMemory() / mb);
+ sb.append("\nTotal memory (MB): ");
+ sb.append(rt.totalMemory() / mb);
+ sb.append("\nMax memory (MB): ");
+ sb.append(rt.maxMemory() / mb);
+
+ memoryInfo = sb.toString();
+ }
+ catch (Throwable e) {
+ memoryInfo = e.toString();
+ }
+
+ try {
+ File[] roots = File.listRoots();
+ StringBuffer sb = new StringBuffer();
+ final int mb = 1024 * 1024;
+ for (int c = 0; c < roots.length; c++) {
+ File root = roots[c];
+ sb.append(root);
+ sb.append("\nFree Space (MB): ");
+ sb.append(root.getFreeSpace() / mb);
+ sb.append("\nTotal Space (MB): ");
+ sb.append(root.getTotalSpace() / mb);
+ sb.append("\nUsable Space (MB): ");
+ sb.append(root.getUsableSpace() / mb);
+ }
+ diskInfo = sb.toString();
+ }
+ catch (Throwable e) {
+ diskInfo = e.toString();
+ }
+
+ Map map = new java.util.Hashtable();
+ map.put("systemLocale",systemLocale);
+ map.put("localhost",localhost);
+ map.put("systemProperties",systemProperties);
+ map.put("environment",environment);
+ map.put("lookandfeel",lookandfeel);
+ map.put("installDate",installDate);
+ map.put("memoryInfo", memoryInfo);
+ map.put("diskInfo", diskInfo);
+ map.put("submitDate",new java.util.Date().toString());
+
+ return map;
+ }
+}
Copied: Grasshopper/src/net/yura/grasshopper/info/LogFile.java (from rev 1054, Grasshopper/src/net/yura/grasshopper/LogFile.java)
===================================================================
--- Grasshopper/src/net/yura/grasshopper/info/LogFile.java (rev 0)
+++ Grasshopper/src/net/yura/grasshopper/info/LogFile.java 2024-12-27 15:20:16 UTC (rev 1055)
@@ -0,0 +1,66 @@
+package net.yura.grasshopper.info;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * @author Yura Mamyrin
+ */
+public class LogFile implements LogText {
+
+ File file;
+ long length = -1;
+
+ public LogFile(File file) {
+ this.file = file;
+ }
+
+ public long getContentLength() {
+ if (length == -1) {
+ length = file.length();
+ }
+ return length;
+ }
+
+ public void writeTo(OutputStream out) throws IOException {
+ if (out == null) {
+ throw new IllegalArgumentException("Output stream may not be null");
+ }
+ InputStream in = new FileInputStream(this.file);
+ try {
+
+ long totalLength = getContentLength();
+ long totalWritten = 0;
+
+ byte[] tmp = new byte[2048]; // 4096
+ int l;
+ while ((l = in.read(tmp)) != -1) {
+ if ( totalWritten+l > totalLength ) {
+ out.write(tmp, 0, (int)(totalLength - totalWritten) );
+ break;
+ }
+ else {
+ totalWritten = totalWritten + l;
+ out.write(tmp, 0, l);
+ }
+ }
+ out.flush();
+ }
+ finally {
+ in.close();
+ }
+ }
+
+ BufferedReader br;
+ public String readLine() throws IOException {
+ if (br==null) {
+ br = new BufferedReader(new FileReader( file ));
+ }
+ return br.readLine();
+ }
+}
Copied: Grasshopper/src/net/yura/grasshopper/info/LogList.java (from rev 1054, Grasshopper/src/net/yura/grasshopper/LogList.java)
===================================================================
--- Grasshopper/src/net/yura/grasshopper/info/LogList.java (rev 0)
+++ Grasshopper/src/net/yura/grasshopper/info/LogList.java 2024-12-27 15:20:16 UTC (rev 1055)
@@ -0,0 +1,54 @@
+package net.yura.grasshopper.info;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.List;
+
+/**
+ * @author Yura Mamyrin
+ */
+public class LogList implements LogText {
+
+ List log;
+ int size=-1;
+
+ public LogList(List log) {
+ this.log = log;
+ }
+
+ private int getListSize() {
+ if (size == -1) {
+ size = log.size();
+ }
+ return size;
+ }
+
+ public long getContentLength() {
+ int s = getListSize();
+ int length=0;
+ for (int c=0;c<s;c++) {
+ length = length + String.valueOf(log.get(c)).length() +1; // 1 is for the /n
+ }
+ return length;
+ }
+
+ public void writeTo(OutputStream out) throws IOException {
+ int s = getListSize();
+ for (int c=0;c<s;c++) {
+ String line = String.valueOf(log.get(c));
+ out.write( line.getBytes(CHARSET) );
+ out.write('\n');
+ }
+ }
+
+ int pos;
+ public String readLine() {
+ if (pos<log.size()) {
+ String result = String.valueOf(log.get(pos));
+ pos++;
+ return result;
+ }
+ return null;
+ }
+
+}
Copied: Grasshopper/src/net/yura/grasshopper/info/LogText.java (from rev 1054, Grasshopper/src/net/yura/grasshopper/LogText.java)
===================================================================
--- Grasshopper/src/net/yura/grasshopper/info/LogText.java (rev 0)
+++ Grasshopper/src/net/yura/grasshopper/info/LogText.java 2024-12-27 15:20:16 UTC (rev 1055)
@@ -0,0 +1,34 @@
+package net.yura.grasshopper.info;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+/**
+ * @author Yura Mamyrin
+ */
+public interface LogText {
+
+ /**
+ * we use US-ASCII instead of UTF-8 because logs are usually in plain text
+ * and LogList works out the length of the data by counting string.length
+ * ALSO, TFMail seems to ignore UTF-8 and always displays text as US-ASCII
+ */
+ public static final String CHARSET = "US-ASCII";
+
+ /**
+ * @return the length of the content encoded using {@see #CHARSET}
+ */
+ long getContentLength();
+
+
+ /**
+ * @param out write the content using {@see #CHARSET}
+ */
+ void writeTo(OutputStream out) throws IOException;
+
+ /**
+ * alternative method for getting content line by line (used as a fallback)
+ */
+ String readLine() throws IOException;
+
+}
Copied: Grasshopper/src/net/yura/grasshopper/info/ScreenShot.java (from rev 1054, Grasshopper/src/net/yura/grasshopper/ScreenShot.java)
===================================================================
--- Grasshopper/src/net/yura/grasshopper/info/ScreenShot.java (rev 0)
+++ Grasshopper/src/net/yura/grasshopper/info/ScreenShot.java 2024-12-27 15:20:16 UTC (rev 1055)
@@ -0,0 +1,39 @@
+package net.yura.grasshopper.info;
+
+/**
+ * @author Yura Mamyrin
+ */
+public class ScreenShot {
+
+ private byte[] encodedData;
+ private String fileType;
+ private String error;
+
+ public ScreenShot() {
+
+ }
+
+ public void setEncodedData(byte[] encodedData) {
+ this.encodedData = encodedData;
+ }
+
+ public void setFileType(String fileType) {
+ this.fileType = fileType;
+ }
+
+ public void setError(String error) {
+ this.error = error;
+ }
+
+ public byte[] getEncodedData() {
+ return encodedData;
+ }
+
+ public String getFileType() {
+ return fileType;
+ }
+
+ public String getError() {
+ return error;
+ }
+}
Copied: Grasshopper/src/net/yura/grasshopper/submitter/BugSubmitter.java (from rev 1054, Grasshopper/src/net/yura/grasshopper/BugSubmitter.java)
===================================================================
--- Grasshopper/src/net/yura/grasshopper/submitter/BugSubmitter.java (rev 0)
+++ Grasshopper/src/net/yura/grasshopper/submitter/BugSubmitter.java 2024-12-27 15:20:16 UTC (rev 1055)
@@ -0,0 +1,277 @@
+package net.yura.grasshopper.submitter;
+
+import net.yura.grasshopper.util.LimitedOutputStream;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.net.HttpURLConnection;
+import java....
[truncated message content] |