Search in sources :

Example 51 with JSONException

use of org.json.JSONException in project core by s4.

the class LoadGenerator method createEventTypeInfo.

@SuppressWarnings("unchecked")
public void createEventTypeInfo(JSONObject classInfo) {
    String className = "";
    try {
        for (Iterator it = classInfo.keys(); it.hasNext(); ) {
            className = (String) it.next();
            JSONObject jsonEventTypeInfo = classInfo.getJSONObject(className);
            int classIndex = (Integer) jsonEventTypeInfo.getInt("classIndex");
            String streamName = jsonEventTypeInfo.getString("streamName");
            Class clazz = Class.forName(className);
            Schema schema = new Schema(clazz);
            eventTypeInfoMap.put(classIndex, new EventTypeInfo(schema, streamName));
        }
    } catch (JSONException je) {
        je.printStackTrace();
    } catch (ClassNotFoundException cnfe) {
        System.err.println("Count not locate class " + className);
    }
}
Also used : BigInteger(java.math.BigInteger) JSONObject(org.json.JSONObject) Schema(io.s4.schema.Schema) Iterator(java.util.Iterator) JSONException(org.json.JSONException)

Example 52 with JSONException

use of org.json.JSONException in project core by s4.

the class LoadGenerator method makeList.

public Object makeList(Property property, JSONArray jsonArray) {
    Property componentProperty = property.getComponentProperty();
    int size = jsonArray.length();
    List<Object> list = new ArrayList<Object>(size);
    try {
        for (int i = 0; i < size; i++) {
            Object value = jsonArray.get(i);
            list.add(makeSettableValue(componentProperty, value));
        }
    } catch (JSONException je) {
        throw new RuntimeException(je);
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) Property(io.s4.schema.Schema.Property)

Example 53 with JSONException

use of org.json.JSONException in project Conversations by siacs.

the class MemorizingTrustManager method getPoshFingerprintsFromServer.

private List<String> getPoshFingerprintsFromServer(String domain, String url, int maxTtl, boolean followUrl) {
    Log.d("mtm", "downloading json for " + domain + " from " + url);
    try {
        List<String> results = new ArrayList<>();
        HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection();
        connection.setConnectTimeout(5000);
        connection.setReadTimeout(5000);
        BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        String inputLine;
        StringBuilder builder = new StringBuilder();
        while ((inputLine = in.readLine()) != null) {
            builder.append(inputLine);
        }
        JSONObject jsonObject = new JSONObject(builder.toString());
        in.close();
        int expires = jsonObject.getInt("expires");
        if (expires <= 0) {
            return new ArrayList<>();
        }
        if (maxTtl >= 0) {
            expires = Math.min(maxTtl, expires);
        }
        String redirect;
        try {
            redirect = jsonObject.getString("url");
        } catch (JSONException e) {
            redirect = null;
        }
        if (followUrl && redirect != null && redirect.toLowerCase().startsWith("https")) {
            return getPoshFingerprintsFromServer(domain, redirect, expires, false);
        }
        JSONArray fingerprints = jsonObject.getJSONArray("fingerprints");
        for (int i = 0; i < fingerprints.length(); i++) {
            JSONObject fingerprint = fingerprints.getJSONObject(i);
            String sha256 = fingerprint.getString("sha-256");
            if (sha256 != null) {
                results.add(sha256);
            }
        }
        writeFingerprintsToCache(domain, results, 1000L * expires + System.currentTimeMillis());
        return results;
    } catch (Exception e) {
        Log.d("mtm", "error fetching posh " + e.getMessage());
        return new ArrayList<>();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) URL(java.net.URL) KeyStoreException(java.security.KeyStoreException) JSONException(org.json.JSONException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) JSONObject(org.json.JSONObject) BufferedReader(java.io.BufferedReader) HttpsURLConnection(javax.net.ssl.HttpsURLConnection)

Example 54 with JSONException

use of org.json.JSONException in project platform_frameworks_base by android.

the class FingerprintService method dumpInternal.

private void dumpInternal(PrintWriter pw) {
    JSONObject dump = new JSONObject();
    try {
        dump.put("service", "Fingerprint Manager");
        JSONArray sets = new JSONArray();
        for (UserInfo user : UserManager.get(getContext()).getUsers()) {
            final int userId = user.getUserHandle().getIdentifier();
            final int N = mFingerprintUtils.getFingerprintsForUser(mContext, userId).size();
            PerformanceStats stats = mPerformanceMap.get(userId);
            PerformanceStats cryptoStats = mCryptoPerformanceMap.get(userId);
            JSONObject set = new JSONObject();
            set.put("id", userId);
            set.put("count", N);
            set.put("accept", (stats != null) ? stats.accept : 0);
            set.put("reject", (stats != null) ? stats.reject : 0);
            set.put("acquire", (stats != null) ? stats.acquire : 0);
            set.put("lockout", (stats != null) ? stats.lockout : 0);
            // cryptoStats measures statistics about secure fingerprint transactions
            // (e.g. to unlock password storage, make secure purchases, etc.)
            set.put("acceptCrypto", (cryptoStats != null) ? cryptoStats.accept : 0);
            set.put("rejectCrypto", (cryptoStats != null) ? cryptoStats.reject : 0);
            set.put("acquireCrypto", (cryptoStats != null) ? cryptoStats.acquire : 0);
            set.put("lockoutCrypto", (cryptoStats != null) ? cryptoStats.lockout : 0);
            sets.put(set);
        }
        dump.put("prints", sets);
    } catch (JSONException e) {
        Slog.e(TAG, "dump formatting failure", e);
    }
    pw.println(dump);
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) UserInfo(android.content.pm.UserInfo) Fingerprint(android.hardware.fingerprint.Fingerprint)

Example 55 with JSONException

use of org.json.JSONException in project chromeview by pwnall.

the class JellyBeanAccessibilityInjector method sendActionToAndroidVox.

/**
     * Packs an accessibility action into a JSON object and sends it to AndroidVox.
     *
     * @param action The action identifier.
     * @param arguments The action arguments, if applicable.
     * @return The result of the action.
     */
private boolean sendActionToAndroidVox(int action, Bundle arguments) {
    if (mCallback == null)
        return false;
    if (mAccessibilityJSONObject == null) {
        mAccessibilityJSONObject = new JSONObject();
    } else {
        // Remove all keys from the object.
        final Iterator<?> keys = mAccessibilityJSONObject.keys();
        while (keys.hasNext()) {
            keys.next();
            keys.remove();
        }
    }
    try {
        mAccessibilityJSONObject.accumulate("action", action);
        if (arguments != null) {
            if (action == AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY || action == AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY) {
                final int granularity = arguments.getInt(AccessibilityNodeInfo.ACTION_ARGUMENT_MOVEMENT_GRANULARITY_INT);
                mAccessibilityJSONObject.accumulate("granularity", granularity);
            } else if (action == AccessibilityNodeInfo.ACTION_NEXT_HTML_ELEMENT || action == AccessibilityNodeInfo.ACTION_PREVIOUS_HTML_ELEMENT) {
                final String element = arguments.getString(AccessibilityNodeInfo.ACTION_ARGUMENT_HTML_ELEMENT_STRING);
                mAccessibilityJSONObject.accumulate("element", element);
            }
        }
    } catch (JSONException ex) {
        return false;
    }
    final String jsonString = mAccessibilityJSONObject.toString();
    final String jsCode = String.format(ACCESSIBILITY_ANDROIDVOX_TEMPLATE, jsonString);
    return mCallback.performAction(mContentViewCore, jsCode);
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException)

Aggregations

JSONException (org.json.JSONException)1904 JSONObject (org.json.JSONObject)1422 JSONArray (org.json.JSONArray)638 IOException (java.io.IOException)338 ArrayList (java.util.ArrayList)211 HashMap (java.util.HashMap)145 Test (org.junit.Test)128 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)98 File (java.io.File)77 Bundle (android.os.Bundle)75 VolleyError (com.android.volley.VolleyError)67 Intent (android.content.Intent)63 DefaultGNSTest (edu.umass.cs.gnsserver.utils.DefaultGNSTest)62 Response (com.android.volley.Response)59 URL (java.net.URL)57 Map (java.util.Map)48 TextView (android.widget.TextView)46 View (android.view.View)45 RandomString (edu.umass.cs.gnscommon.utils.RandomString)44 MalformedURLException (java.net.MalformedURLException)44