Search in sources :

Example 1 with ConfigJsonIOException

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);
        }
    }
}
Also used : ConfigJsonIOException(org.eyeseetea.malariacare.domain.exception.ConfigJsonIOException) InputStreamReader(java.io.InputStreamReader) JSONObject(org.json.JSONObject) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) JSONException(org.json.JSONException) IOException(java.io.IOException) ConfigJsonIOException(org.eyeseetea.malariacare.domain.exception.ConfigJsonIOException)

Aggregations

BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 ConfigJsonIOException (org.eyeseetea.malariacare.domain.exception.ConfigJsonIOException)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1