Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/engine/JSONPrefs.java

Issue 29603697: Issue 5931 - Create tests for util package (Closed)
Patch Set: Created Nov. 10, 2017, 2:23 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 package org.adblockplus.sbrowser.contentblocker.engine;
19
20 import java.io.IOException;
21 import java.io.InputStream;
22
23 import org.json.JSONException;
24 import org.json.JSONObject;
25
26 final class JSONPrefs
27 {
28 private final JSONObject jsonObject;
29
30 private JSONPrefs(JSONObject object)
31 {
32 this.jsonObject = object;
33 }
34
35 public String getDefaults(final String key)
36 {
37 try
38 {
39 final JSONObject defaults = this.jsonObject.getJSONObject("defaults");
40 return defaults != null && defaults.has(key) ? defaults.getString(key) : n ull;
41 }
42 catch (final JSONException e)
43 {
44 return null;
45 }
46 }
47
48 public static JSONPrefs create(final InputStream instream) throws IOException
49 {
50 try
51 {
52 return new JSONPrefs(new JSONObject(Engine.readFileAsString(instream)));
53 }
54 catch (JSONException e)
55 {
56 throw new IOException("Failed to parse JSON", e);
57 }
58 }
59 }
OLDNEW

Powered by Google App Engine
This is Rietveld