1 package ro
.ieval
.fonbot
;
3 import static ro
.ieval
.fonbot
.Utils
.toNonNull
;
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
;
11 import org
.eclipse
.jdt
.annotation
.Nullable
;
13 import android
.content
.Context
;
16 * Copyright © 2013 Marius Gavrilescu
18 * This file is part of FonBot.
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.
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.
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/>.
35 * UncaughtExceptionHandler that sends exceptions to the server.
37 * @author Marius Gavrilescu <marius@ieval.ro>
39 final class RemoteCrashdumpHandler
implements UncaughtExceptionHandler
{
40 /** Context instance */
41 private final Context context
;
44 * Constructs a RemoteCrashdumpHandler with a given Context instance.
46 * @param context Context instance
48 public RemoteCrashdumpHandler(final Context context
) {
53 public void uncaughtException(final @Nullable Thread thread
, final @Nullable Throwable ex
) {
57 final ByteArrayOutputStream baos
=new ByteArrayOutputStream(16384);
58 final PrintStream pw
=new PrintStream(baos
);
59 ex
.printStackTrace(pw
);
62 new HttpCallExecutableRunnable("/crashdump", toNonNull(Collections
.<Header
>emptyList()),
63 toNonNull(context
), null, false, toNonNull(baos
.toByteArray())).execute();
67 } catch (IOException e
) {//NOPMD close exceptions are unimportant