} catch (IOException e) {
log.error("Problems manipulating input stream and byte array.", e);
}
if (byteArray == null) {
return new ScanCheckResultBean(ScanImportStatus.WRONG_FORMAT_ERROR);
}
String jsonString = new String(byteArray);
// Check the first character to avoid a possible exception
if (jsonString.trim().startsWith("[")) {
try {
JSONArray array = new JSONArray(jsonString);
done = true;
log.info("Scan is using the old JSON output format.");
if (array.length() > 0) {
hasFindings = true;
JSONObject oneFinding = array.getJSONObject(0);
if (oneFinding != null) {
correctFormat = oneFinding.get("location") != null &&
oneFinding.get("file") != null &&
oneFinding.get("message") != null &&
oneFinding.get("confidence") != null &&
oneFinding.get("code") != null &&
oneFinding.get("warning_type") != null;
}
}
} catch (JSONException e) {
log.warn("Encountered JSONException.", e);
}
}
// Output Version 2
// Check the first character to avoid a possible exception
if (!done && jsonString.trim().startsWith("{")) {
try {
JSONObject object = new JSONObject(jsonString);
log.info("Scan is using the new JSON output format.");
testDate = getDate(jsonString);
hasDate = testDate != null;
JSONArray array = object.getJSONArray("warnings");
if (array.length() > 0) {
hasFindings = true;
JSONObject oneFinding = array.getJSONObject(0);
if (oneFinding != null) {
correctFormat = oneFinding.get("location") != null &&
oneFinding.get("file") != null &&
oneFinding.get("message") != null &&
oneFinding.get("confidence") != null &&
oneFinding.get("code") != null &&
oneFinding.get("user_input") != null &&
oneFinding.get("line") != null &&
oneFinding.get("warning_type") != null;
}
}
} catch (JSONException e) {
log.warn("Encountered JSONException.", e);
}
}
return new ScanCheckResultBean(getTestStatus(), testDate);
}