Example usage for android.util Log getStackTraceString

List of usage examples for android.util Log getStackTraceString

Introduction

In this page you can find the example usage for android.util Log getStackTraceString.

Prototype

public static String getStackTraceString(Throwable tr) 

Source Link

Document

Handy function to get a loggable stack trace from a Throwable

Usage

From source file:org.alfresco.mobile.android.api.services.impl.AbstractDocumentFolderServiceImpl.java

/** {@inheritDoc} */
@Override//from  w w  w  . j ava 2  s .  co m
public org.alfresco.mobile.android.api.model.ContentStream getContentStream(Document document) {
    if (isObjectNull(document)) {
        throw new IllegalArgumentException(String
                .format(Messagesl18n.getString("ErrorCodeRegistry.GENERAL_INVALID_ARG_NULL"), "document"));
    }

    try {
        if (document.getContentStreamLength() <= 0) {
            return null;
        }

        ObjectService objectService = cmisSession.getBinding().getObjectService();
        org.alfresco.mobile.android.api.model.ContentStream cf = new ContentStreamImpl(document.getName(),
                objectService.getContentStream(session.getRepositoryInfo().getIdentifier(),
                        document.getIdentifier(), null, null, null, null));
        if (cf.getLength() == -1) {
            return new ContentStreamImpl(document.getName(), cf.getInputStream(), cf.getMimeType(),
                    document.getContentStreamLength());
        }
        return cf;
    } catch (Exception e) {
        Log.d(TAG, Log.getStackTraceString(e));
        convertException(e);
    }
    return null;
}

From source file:org.alfresco.mobile.android.api.services.impl.onpremise.OnPremiseWorkflowServiceImpl.java

/** {@inheritDoc} */
public Task completeTask(Task task, Map<String, Serializable> variables) {
    if (isObjectNull(task)) {
        throw new IllegalArgumentException(
                String.format(Messagesl18n.getString("ErrorCodeRegistry.GENERAL_INVALID_ARG_NULL"), "task"));
    }//w ww  .j  a v a  2 s.  c o  m

    Map<String, Serializable> internalVariables = new HashMap<String, Serializable>();
    if (variables != null) {
        internalVariables.putAll(variables);
    }
    Task resultTask = task;
    try {
        String link = OnPremiseUrlRegistry.getFormTaskUrl(session, task.getIdentifier());
        UrlBuilder url = new UrlBuilder(link);

        // prepare json data
        JSONObject jo = new JSONObject();

        // TRANSITION
        if (!internalVariables.containsKey(WorkflowModel.PROP_TRANSITIONS_VALUE)) {
            String transitionIdentifier = "";
            if (task.getIdentifier().startsWith(WorkflowModel.KEY_PREFIX_ACTIVITI)) {
                transitionIdentifier = WorkflowModel.TRANSITION_NEXT;
            }
            internalVariables.put(WorkflowModel.PROP_TRANSITIONS_VALUE, transitionIdentifier);
        }

        // VARIABLES
        if (internalVariables != null && !internalVariables.isEmpty()) {
            for (Entry<String, Serializable> entry : internalVariables.entrySet()) {
                if (ALFRESCO_TO_WORKFLOW.containsKey(entry.getKey())) {
                    jo.put(ALFRESCO_TO_WORKFLOW.get(entry.getKey()), entry.getValue());
                }
            }
        }

        final JsonDataWriter dataWriter = new JsonDataWriter(jo);

        // send
        Response resp = post(url, dataWriter.getContentType(), new Output() {
            public void write(OutputStream out) throws IOException {
                dataWriter.write(out);
            }
        }, ErrorCodeRegistry.WORKFLOW_GENERIC);

        Map<String, Object> json = JsonUtils.parseObject(resp.getStream(), resp.getCharset());
        String data = JSONConverter.getString(json, OnPremiseConstant.PERSISTEDOBJECT_VALUE);

        // WorkflowInstance[id=activiti$18328,active=true,def=WorkflowDefinition[
        String taskId = data.split("\\[")[1].split(",")[0].split("=")[1];

        resultTask = getTask(taskId);
    } catch (Exception e) {
        Log.e(TAG, Log.getStackTraceString(e));
        convertException(e);
    }

    return resultTask;
}

From source file:org.proninyaroslav.libretorrent.fragments.DetailTorrentFragment.java

private void saveErrorTorrentFileDialog(Exception e) {
    sentError = e;//from   w  w w . jav a2  s  .  c  om

    if (getFragmentManager().findFragmentByTag(TAG_SAVE_ERR_TORRENT_FILE_DIALOG) == null) {
        ErrorReportAlertDialog errDialog = ErrorReportAlertDialog.newInstance(activity.getApplicationContext(),
                getString(R.string.error), getString(R.string.error_save_torrent_file),
                (e != null ? Log.getStackTraceString(e) : null), R.style.BaseTheme_Dialog, this);

        errDialog.show(getFragmentManager(), TAG_SAVE_ERR_TORRENT_FILE_DIALOG);
    }
}

From source file:com.morphoss.acal.service.connector.AcalRequestor.java

/**
 * Do a new HTTP <method> request with these headers and entity (request body) against
 * this path (or the current path, if null).  The headers & entity may also be null in
 * some simple cases.//w  w  w.j a v a  2 s  .  com
 *
 * If the server requests Digest or Basic authentication a second request will be made
 * supplying these (if possible).  Likewise the method will follow up to five redirects
 * before giving up on a request.
 * @param method
 * @param pathOrUrl
 * @param headers
 * @param entity
 * @return
 * @throws SendRequestFailedException
 * @throws SSLException
 * @throws ConnectionFailedException
 */
public InputStream doRequest(String method, String pathOrUrl, Header[] headers, String entity)
        throws SendRequestFailedException, SSLException, ConnectionFailedException {

    if (Constants.LOG_DEBUG || debugThisRequest)
        Log.println(Constants.LOGD, TAG, String.format("%s request on %s", method, fullUrl()));

    InputStream result = null;
    interpretUriString(pathOrUrl);
    this.method = method;
    do {
        try {
            result = sendRequest(headers, entity);
        } catch (SSLHandshakeException e) {
            throw e;
        } catch (SSLException e) {
            throw e;
        } catch (SendRequestFailedException e) {
            throw e;
        } catch (ConnectionFailedException e) {
            throw e;
        } catch (AuthenticationFailure e1) {
            statusCode = 401;
        } catch (Exception e) {
            Log.e(TAG, Log.getStackTraceString(e));
        }

        if (statusCode == 401) {
            // In this case we didn't send auth credentials the first time, so
            // we need to try again after we interpret the auth request.
            try {
                interpretRequestedAuth(getAuthHeader());
                return sendRequest(headers, entity);
            } catch (AuthenticationFailure e1) {
                throw new SendRequestFailedException("Authentication Failed: " + e1.getMessage());
            } catch (Exception e) {
                Log.e(TAG, Log.getStackTraceString(e));
            }
        }

        if ((statusCode >= 300 && statusCode <= 303) || statusCode == 307) {
            /**
             * Other than 301/302 these are all pretty unlikely
             *      300:  Multiple choices, but we take the one in the Location header anyway
             *      301:  Moved permanently
             *      302:  Found (was 'temporary redirect' once in prehistory)
             *      303:  See other
             *      307:  Temporary redirect. Meh.
             */
            if (redirectCount++ < redirectLimit) {
                String oldUrl = fullUrl();
                interpretUriString(getLocationHeader());
                if (debugThisRequest)
                    Log.println(Constants.LOGD, TAG, method + " " + oldUrl + " redirected to: " + fullUrl());

                continue;
            }
        } else
            break;
    } while (redirectCount < redirectLimit);

    return result;
}

From source file:org.proninyaroslav.libretorrent.fragments.DetailTorrentFragment.java

private void initRequest() {
    if (!bound || serviceCallback == null) {
        return;//from   w ww .j  a va 2 s  . co  m
    }

    try {
        ipc.sendGetTorrentInfo(serviceCallback, clientCallback, torrentId);
        ipc.sendGetSpeedLimit(serviceCallback, clientCallback, torrentId);

    } catch (RemoteException e) {
        Log.e(TAG, Log.getStackTraceString(e));
    }
}

From source file:org.proninyaroslav.libretorrent.fragments.DetailTorrentFragment.java

private void changeFilesPriorityRequest(ArrayList<Integer> priorities) {
    if (!bound || serviceCallback == null || priorities == null || torrentId == null) {
        return;//www .  j  a va  2  s  . c  o  m
    }

    try {
        ipc.sendChangeFilesPriority(serviceCallback, torrentId, priorities);

    } catch (RemoteException e) {
        Log.e(TAG, Log.getStackTraceString(e));
    }
}

From source file:android_network.hetnet.vpn_service.Util.java

private static StringBuilder getLogcat() {
    StringBuilder builder = new StringBuilder();
    Process process1 = null;/* w  w  w  . j  av a 2s. c  om*/
    Process process2 = null;
    BufferedReader br = null;
    try {
        String[] command1 = new String[] { "logcat", "-d", "-v", "threadtime" };
        process1 = Runtime.getRuntime().exec(command1);
        br = new BufferedReader(new InputStreamReader(process1.getInputStream()));
        int count = 0;
        String line;
        while ((line = br.readLine()) != null) {
            count++;
            builder.append(line).append("\r\n");
        }
        Log.i(TAG, "Logcat lines=" + count);

    } catch (IOException ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    } finally {
        if (br != null)
            try {
                br.close();
            } catch (IOException ignored) {
            }
        if (process2 != null)
            try {
                process2.destroy();
            } catch (Throwable ex) {
                Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
            }
        if (process1 != null)
            try {
                process1.destroy();
            } catch (Throwable ex) {
                Log.w(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
            }
    }
    return builder;
}

From source file:com.hichinaschool.flashcards.async.Connection.java

/**
 * Downloads any missing media files according to the mediaURL deckvar.
 * /*from  w  w w. ja va  2  s . c  o m*/
 * @param data
 * @return The return type contains data.resultType and an array of Integer in data.data. data.data[0] is the number
 *         of total missing media, data.data[1] is the number of downloaded ones.
 */
private Payload doInBackgroundDownloadMissingMedia(Payload data) {
    // Log.i(AnkiDroidApp.TAG, "DownloadMissingMedia");
    HashMap<String, String> missingPaths = new HashMap<String, String>();
    HashMap<String, String> missingSums = new HashMap<String, String>();

    Decks deck = (Decks) data.data[0];
    data.result = deck; // pass it to the return object so we close the deck in the deck picker
    String syncName = "";// deck.getDeckName();

    data.success = false;
    data.data = new Object[] { 0, 0, 0 };
    // if (!deck.hasKey("mediaURL")) {
    // data.success = true;
    // return data;
    // }
    String urlbase = "";// deck.getVar("mediaURL");
    if (urlbase.equals("")) {
        data.success = true;
        return data;
    }

    String mdir = "";// deck.mediaDir(true);
    int totalMissing = 0;
    int missing = 0;
    int grabbed = 0;

    Cursor cursor = null;
    try {
        cursor = null;// deck.getDB().getDatabase().rawQuery("SELECT filename, originalPath FROM media", null);
        String path = null;
        String f = null;
        while (cursor.moveToNext()) {
            f = cursor.getString(0);
            path = mdir + "/" + f;
            File file = new File(path);
            if (!file.exists()) {
                missingPaths.put(f, path);
                missingSums.put(f, cursor.getString(1));
                // Log.i(AnkiDroidApp.TAG, "Missing file: " + f);
            }
        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }

    totalMissing = missingPaths.size();
    data.data[0] = new Integer(totalMissing);
    if (totalMissing == 0) {
        data.success = true;
        return data;
    }
    publishProgress(Boolean.FALSE, new Integer(totalMissing), new Integer(0), syncName);

    URL url = null;
    HttpURLConnection connection = null;
    String path = null;
    String sum = null;
    int readbytes = 0;
    byte[] buf = new byte[4096];
    for (String file : missingPaths.keySet()) {

        try {
            android.net.Uri uri = android.net.Uri.parse(Uri.encode(urlbase, ":/@%") + Uri.encode(file));
            url = new URI(uri.toString()).toURL();
            connection = (HttpURLConnection) url.openConnection();
            connection.connect();
            if (connection.getResponseCode() == 200) {
                path = missingPaths.get(file);
                InputStream is = connection.getInputStream();
                BufferedInputStream bis = new BufferedInputStream(is, 4096);
                FileOutputStream fos = new FileOutputStream(path);
                while ((readbytes = bis.read(buf, 0, 4096)) != -1) {
                    fos.write(buf, 0, readbytes);
                    // Log.i(AnkiDroidApp.TAG, "Downloaded " + readbytes + " file: " + path);
                }
                fos.close();

                // Verify with checksum
                sum = missingSums.get(file);
                if (true) {// sum.equals("") || sum.equals(Utils.fileChecksum(path))) {
                    grabbed++;
                } else {
                    // Download corrupted, delete file
                    // Log.i(AnkiDroidApp.TAG, "Downloaded media file " + path + " failed checksum.");
                    File f = new File(path);
                    f.delete();
                    missing++;
                }
            } else {
                Log.e(AnkiDroidApp.TAG, "Connection error (" + connection.getResponseCode()
                        + ") while retrieving media file " + urlbase + file);
                Log.e(AnkiDroidApp.TAG, "Connection message: " + connection.getResponseMessage());
                if (missingSums.get(file).equals("")) {
                    // Ignore and keep going
                    missing++;
                } else {
                    data.success = false;
                    data.data = new Object[] { file };
                    return data;
                }
            }
            connection.disconnect();
        } catch (URISyntaxException e) {
            Log.e(AnkiDroidApp.TAG, Log.getStackTraceString(e));
        } catch (MalformedURLException e) {
            Log.e(AnkiDroidApp.TAG, Log.getStackTraceString(e));
            Log.e(AnkiDroidApp.TAG, "MalformedURLException while download media file " + path);
            if (missingSums.get(file).equals("")) {
                // Ignore and keep going
                missing++;
            } else {
                data.success = false;
                data.data = new Object[] { file };
                return data;
            }
        } catch (IOException e) {
            Log.e(AnkiDroidApp.TAG, Log.getStackTraceString(e));
            Log.e(AnkiDroidApp.TAG, "IOException while download media file " + path);
            if (missingSums.get(file).equals("")) {
                // Ignore and keep going
                missing++;
            } else {
                data.success = false;
                data.data = new Object[] { file };
                return data;
            }
        } finally {
            if (connection != null) {
                connection.disconnect();
            }
        }
        publishProgress(Boolean.TRUE, new Integer(totalMissing), new Integer(grabbed + missing), syncName);
    }

    data.data[1] = new Integer(grabbed);
    data.data[2] = new Integer(missing);
    data.success = true;
    return data;
}

From source file:org.proninyaroslav.libretorrent.fragments.DetailTorrentFragment.java

private void addTrackersRequest(ArrayList<String> trackers, boolean replace) {
    if (!bound || serviceCallback == null || trackers == null || torrentId == null) {
        return;/*from   www  .  ja  va2 s.c om*/
    }

    try {
        if (replace) {
            ipc.sendReplaceTrackers(serviceCallback, torrentId, trackers);
        } else {
            ipc.sendAddTrackers(serviceCallback, torrentId, trackers);
        }

    } catch (RemoteException e) {
        Log.e(TAG, Log.getStackTraceString(e));
    }
}

From source file:org.proninyaroslav.libretorrent.fragments.DetailTorrentFragment.java

private void deleteTorrentRequest(boolean withFiles) {
    if (!bound || serviceCallback == null) {
        return;//from   w  w  w.  jav a 2  s.  c  om
    }

    ArrayList<String> list = new ArrayList<>();
    list.add(torrentId);

    try {
        ipc.sendDeleteTorrents(serviceCallback, list, withFiles);

    } catch (RemoteException e) {
        Log.e(TAG, Log.getStackTraceString(e));
    }
}