]> iEval git - fonbot.git/blob - RemoteCrashdumpHandler.java
56911b68b59d8c48e736a7d6b7c609b7838ce02c
[fonbot.git] / RemoteCrashdumpHandler.java
1 package ro.ieval.fonbot;
2
3 import static ro.ieval.fonbot.Utils.toNonNull;
4
5 import java.io.ByteArrayOutputStream;
6 import java.io.IOException;
7 import java.io.PrintStream;
8 import java.lang.Thread.UncaughtExceptionHandler;
9 import java.util.Collections;
10
11 import org.eclipse.jdt.annotation.Nullable;
12
13 import android.content.Context;
14
15 /*
16 * Copyright © 2013 Marius Gavrilescu
17 *
18 * This file is part of FonBot.
19 *
20 * FonBot is free software: you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation, either version 3 of the License, or
23 * (at your option) any later version.
24 *
25 * FonBot is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with FonBot. If not, see <http://www.gnu.org/licenses/>.
32 */
33
34 /**
35 * UncaughtExceptionHandler that sends exceptions to the server.
36 *
37 * @author Marius Gavrilescu <marius@ieval.ro>
38 */
39 final class RemoteCrashdumpHandler implements UncaughtExceptionHandler {
40 /** Context instance */
41 private final Context context;
42
43 /**
44 * Constructs a RemoteCrashdumpHandler with a given Context instance.
45 *
46 * @param context Context instance
47 */
48 public RemoteCrashdumpHandler(final Context context) {
49 this.context=context;
50 }
51
52 @Override
53 public void uncaughtException(final @Nullable Thread thread, final @Nullable Throwable ex) {
54 if(ex==null)
55 return;
56
57 final ByteArrayOutputStream baos=new ByteArrayOutputStream(16384);
58 final PrintStream pw=new PrintStream(baos);
59 ex.printStackTrace(pw);
60 pw.close();
61
62 new HttpCallExecutableRunnable("/crashdump", toNonNull(Collections.<Header>emptyList()),
63 toNonNull(context), null, false, toNonNull(baos.toByteArray())).execute();
64
65 try {
66 baos.close();
67 } catch (IOException e) {//NOPMD close exceptions are unimportant
68 //ignored
69 }
70 }
71
72 }
This page took 0.04399 seconds and 3 git commands to generate.