use of org.eyeseetea.malariacare.domain.exception.ConfigJsonIOException in project pictureapp by EyeSeeTea.
the class CredentialsReader method readJson.
private void readJson() throws ConfigJsonIOException {
if (mJSONObject != null) {
return;
}
InputStream inputStream = null;
try {
inputStream = PreferencesState.getInstance().getContext().getResources().openRawResource(R.raw.config);
// json is UTF-8 by default
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
mJSONObject = new JSONObject(sb.toString());
} catch (IOException e) {
throw new ConfigJsonIOException(e);
} catch (JSONException e) {
throw new ConfigJsonIOException(e);
} finally {
try {
if (inputStream != null)
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
throw new ConfigJsonIOException(e);
}
}
}
Aggregations