Search in sources :

Example 6 with BFInputDataException

use of com.capgemini.ntc.test.core.exceptions.BFInputDataException in project devonfw-testing by devonfw.

the class JsonReader method readJson.

/**
 * Reads JSON file and return it's
 *
 * @param jsonFile
 * @return
 */
public static JSONObject readJson(File jsonFile) {
    JSONObject jsonObject = null;
    try {
        InputStream jsonStream = new FileInputStream(jsonFile);
        String genreJson = IOUtils.toString(jsonStream);
        try {
            jsonObject = new JSONObject(genreJson);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } catch (IOException e) {
        throw new BFInputDataException("Unable to read JSON file: " + jsonFile.getName());
    }
    return jsonObject;
}
Also used : JSONObject(org.json.JSONObject) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JSONException(org.json.JSONException) IOException(java.io.IOException) BFInputDataException(com.capgemini.ntc.test.core.exceptions.BFInputDataException) FileInputStream(java.io.FileInputStream)

Aggregations

BFInputDataException (com.capgemini.ntc.test.core.exceptions.BFInputDataException)6 File (java.io.File)2 IOException (java.io.IOException)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 CSVParser (org.apache.commons.csv.CSVParser)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1