stagedObject.put("user_generated", photo.getUserGenerated()); } catch (final JSONException ex) { String message = ex.getLocalizedMessage(); if (message == null) { message = "Error staging photo.";
Log.e(TAG, e.getLocalizedMessage()); } catch (JSONException e) { Log.e(TAG, e.getLocalizedMessage()); } finally { if (br != null) {
public static boolean exportRules(Context ctx, final String fileName) { boolean res = false; File sdCard = Environment.getExternalStorageDirectory(); if (isExternalStorageWritable()) { File dir = new File(sdCard.getAbsolutePath() + "/afwall/"); dir.mkdirs(); File file = new File(dir, fileName); try { FileOutputStream fOut = new FileOutputStream(file); OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut); //default Profile - current one JSONObject obj = new JSONObject(getCurrentRulesAsMap(ctx)); JSONArray jArray = new JSONArray("[" + obj.toString() + "]"); myOutWriter.append(jArray.toString()); res = true; myOutWriter.close(); fOut.close(); } catch (FileNotFoundException e) { Log.e(TAG, e.getLocalizedMessage()); } catch (JSONException e) { Log.e(TAG, e.getLocalizedMessage()); } catch (IOException e) { Log.e(TAG, e.getLocalizedMessage()); } } return res; }
private static Map<String, JSONObject> getCurrentRulesAsMap(Context ctx) { List<PackageInfoData> apps = getApps(ctx, null); // Builds a pipe-separated list of names Map<String, JSONObject> exportMap = new HashMap<>(); try { for (int i = 0; i < apps.size(); i++) { if (apps.get(i).selected_wifi) { updateExportPackage(exportMap, apps.get(i).pkgName, WIFI_EXPORT); } if (apps.get(i).selected_3g) { updateExportPackage(exportMap, apps.get(i).pkgName, DATA_EXPORT); } if (apps.get(i).selected_roam) { updateExportPackage(exportMap, apps.get(i).pkgName, ROAM_EXPORT); } if (apps.get(i).selected_vpn) { updateExportPackage(exportMap, apps.get(i).pkgName, VPN_EXPORT); } if (apps.get(i).selected_lan) { updateExportPackage(exportMap, apps.get(i).pkgName, LAN_EXPORT); } if (apps.get(i).selected_tor) { updateExportPackage(exportMap, apps.get(i).pkgName, TOR_EXPORT); } } } catch (JSONException e) { Log.e(TAG, e.getLocalizedMessage()); } return exportMap; }
Log.e(TAG, e.getLocalizedMessage()); } catch (JSONException e) { Log.e(TAG, e.getLocalizedMessage()); } finally { if (br != null) {
Log.d(TAG, e.getLocalizedMessage()); } catch (JSONException e) { Log.d(TAG, e.getLocalizedMessage()); } catch (Exception e) { Log.d(TAG, e.getLocalizedMessage());
callBack.onFailure(e.getLocalizedMessage());
public static void putFloatArray(SharedPreferences.Editor editor, String key, float[] array) { try { JSONArray json = new JSONArray(); for (float f : array) { json.put(f); } editor.putString(key, json.toString()); } catch (JSONException e) { Log.e(TAG, "putFloatArray: " + e.getClass() + ": " + e.getLocalizedMessage()); } }
@Override public void write(Writer writer) throws IOException { try { writer.write(getJsonText()); } catch (JSONException e) { IOException ioe = new IOException(e.getLocalizedMessage()); ioe.initCause(e.getCause()); throw ioe; } } }
public static void saveScenariosJSONObjectToFile(JSONObject scenariousJSON) { try { openme.openme_store_json_file(scenariousJSON, cachedScenariosFilePath); } catch (JSONException e) { AppLogger.logMessage("ERROR could save scenarios to file " + cachedScenariosFilePath + " because of the error " + e.getLocalizedMessage()); return; } }
@Test(expected = AssertionError.class) public void assertJsonEquals_forSimpleUnequalObjects_fails() { String simpleJson = "{\"key\": \"value\"}"; String differentJson = "{\"key2\": \"value2\"}"; try { JSONObject first = new JSONObject(simpleJson); JSONObject second = new JSONObject(differentJson); JsonTestUtils.assertJsonEquals(first, second); } catch (JSONException dataException) { fail("Test data failure: " + dataException.getLocalizedMessage()); } }
@Test(expected = AssertionError.class) public void assertJsonEquals_forSimpleUnequalObjectsWithSameKey_fails() { String simpleJson = "{\"key\": \"value\"}"; String differentJson = "{\"key\": \"value2\"}"; try { JSONObject first = new JSONObject(simpleJson); JSONObject second = new JSONObject(differentJson); JsonTestUtils.assertJsonEquals(first, second); } catch (JSONException dataException) { fail("Test data failure: " + dataException.getLocalizedMessage()); } }
@Test public void putAdditionalFieldsIntoJsonObject_whenNoFieldsArePassed_doesNothing() { JSONObject jsonObject = new JSONObject(); try { jsonObject.put("a", "a_value"); } catch (JSONException unexpected) { fail("Unexpected error: " + unexpected.getLocalizedMessage()); } Map<String, Object> emptyMap = new HashMap<>(); putAdditionalFieldsIntoJsonObject(jsonObject, emptyMap); assertEquals(1, jsonObject.length()); }
@Test public void assertJsonEquals_forSimpleObjectsWithNumbers_passes() { String simpleJson = "{\"key\": \"value\", \"key2\": 100}"; try { JSONObject first = new JSONObject(simpleJson); JSONObject second = new JSONObject(simpleJson); JsonTestUtils.assertJsonEquals(first, second); } catch (JSONException dataException) { fail("Test data failure: " + dataException.getLocalizedMessage()); } }
@Test(expected = AssertionError.class) public void assertJsonEquals_forSimpleObjectsOfDifferentSize_fails() { String simpleJson = "{\"key\": \"value\"}"; String differentJson = "{\"key\": \"value\", \"key2\": \"value2\"}"; try { JSONObject first = new JSONObject(simpleJson); JSONObject second = new JSONObject(differentJson); JsonTestUtils.assertJsonEquals(first, second); } catch (JSONException dataException) { fail("Test data failure: " + dataException.getLocalizedMessage()); } }
@Test public void fromJsonString_backToJson_createsIdenticalElement() { try { JSONObject rawConversion = new JSONObject(EXAMPLE_JSON_ADDRESS); assertJsonEquals(rawConversion, mAddress.toJson()); } catch (JSONException jsonException) { fail("Test Data failure: " + jsonException.getLocalizedMessage()); } }
@Test public void fromJsonString_backToJson_createsIdenticalElement() { try { JSONObject rawConversion = new JSONObject(EXAMPLE_JSON_REDIRECT); assertJsonEquals(rawConversion, mSourceRedirect.toJson()); } catch (JSONException jsonException) { fail("Test Data failure: " + jsonException.getLocalizedMessage()); } }
@Test public void fromJsonStringWithoutNulls_backToJson_createsIdenticalElement() { try { JSONObject rawConversion = new JSONObject(EXAMPLE_JSON_OWNER_WITHOUT_NULLS); assertJsonEquals(rawConversion, mSourceOwner.toJson()); } catch (JSONException jsonException) { fail("Test Data failure: " + jsonException.getLocalizedMessage()); } }
@Test public void fromJsonString_backToJson_createsIdenticalElement() { try { JSONObject rawConversion = new JSONObject(EXAMPLE_PAYMENT_INTENT_SOURCE); JSONObject actualObject = mPaymentIntent.toJson(); assertJsonEqualsExcludingNulls(rawConversion, actualObject); } catch (JSONException jsonException) { fail("Test Data failure: " + jsonException.getLocalizedMessage()); } }
@Test public void fromJsonString_backToJson_createsIdenticalElement() { try { JSONObject rawConversion = new JSONObject(EXAMPLE_JSON_RECEIVER); assertJsonEquals(rawConversion, mSourceReceiver.toJson()); } catch (JSONException jsonException) { fail("Test Data failure: " + jsonException.getLocalizedMessage()); } }