refactore exceptionhandler to have one line file writer
This commit is contained in:
		
							parent
							
								
									9ce2cfa3d2
								
							
						
					
					
						commit
						e1cf7b8cb6
					
				| @ -47,7 +47,10 @@ public class DNSHelper { | |||||||
| 
 | 
 | ||||||
| 	protected static Client client = new Client(); | 	protected static Client client = new Client(); | ||||||
| 
 | 
 | ||||||
|  | 	protected static Context context; | ||||||
|  | 
 | ||||||
| 	public static Bundle getSRVRecord(final Jid jid, Context context) throws IOException { | 	public static Bundle getSRVRecord(final Jid jid, Context context) throws IOException { | ||||||
|  | 		DNSHelper.context = context; | ||||||
|         final String host = jid.getDomainpart(); |         final String host = jid.getDomainpart(); | ||||||
| 		final List<InetAddress> servers = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? getDnsServers(context) : getDnsServersPreLollipop(); | 		final List<InetAddress> servers = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? getDnsServers(context) : getDnsServersPreLollipop(); | ||||||
| 		Bundle b = new Bundle(); | 		Bundle b = new Bundle(); | ||||||
|  | |||||||
| @ -27,19 +27,7 @@ public class ExceptionHandler implements UncaughtExceptionHandler { | |||||||
| 		ex.printStackTrace(printWriter); | 		ex.printStackTrace(printWriter); | ||||||
| 		String stacktrace = result.toString(); | 		String stacktrace = result.toString(); | ||||||
| 		printWriter.close(); | 		printWriter.close(); | ||||||
| 		try { | 		ExceptionHelper.writeToStacktraceFile(context, stacktrace); | ||||||
| 			OutputStream os = context.openFileOutput("stacktrace.txt", |  | ||||||
| 					Context.MODE_PRIVATE); |  | ||||||
| 			os.write(stacktrace.getBytes()); |  | ||||||
| 			os.flush(); |  | ||||||
| 			os.close(); |  | ||||||
| 		} catch (FileNotFoundException e) { |  | ||||||
| 			// TODO Auto-generated catch block |  | ||||||
| 			e.printStackTrace(); |  | ||||||
| 		} catch (IOException e) { |  | ||||||
| 			// TODO Auto-generated catch block |  | ||||||
| 			e.printStackTrace(); |  | ||||||
| 		} |  | ||||||
| 		this.defaultHandler.uncaughtException(thread, ex); | 		this.defaultHandler.uncaughtException(thread, ex); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -14,8 +14,10 @@ import android.util.Log; | |||||||
| 
 | 
 | ||||||
| import java.io.BufferedReader; | import java.io.BufferedReader; | ||||||
| import java.io.FileInputStream; | import java.io.FileInputStream; | ||||||
|  | import java.io.FileNotFoundException; | ||||||
| import java.io.IOException; | import java.io.IOException; | ||||||
| import java.io.InputStreamReader; | import java.io.InputStreamReader; | ||||||
|  | import java.io.OutputStream; | ||||||
| import java.util.List; | import java.util.List; | ||||||
| 
 | 
 | ||||||
| import eu.siacs.conversations.Config; | import eu.siacs.conversations.Config; | ||||||
| @ -118,4 +120,14 @@ public class ExceptionHelper { | |||||||
| 			return false; | 			return false; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
|  | 	public static void writeToStacktraceFile(Context context, String msg) { | ||||||
|  | 		try { | ||||||
|  | 			OutputStream os = context.openFileOutput("stacktrace.txt", Context.MODE_PRIVATE); | ||||||
|  | 			os.write(msg.getBytes()); | ||||||
|  | 			os.flush(); | ||||||
|  | 			os.close(); | ||||||
|  | 		} catch (IOException ignored) { | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Daniel Gultsch
						Daniel Gultsch