use of com.google.gson.stream.JsonReader in project Engine by VoltzEngine-Project.
the class JsonLoader method loadJson.
/**
* Loads a json file from a reader
*
* @param fileName - file the reader loaded from, used only for error logs
* @param reader - reader with the data
* @param entries - place to put json entries into
*/
public static void loadJson(String fileName, Reader reader, HashMap<String, List<JsonEntry>> entries) {
try {
JsonReader jsonReader = new JsonReader(reader);
JsonElement element = Streams.parse(jsonReader);
loadJsonElement(fileName, element, entries);
} catch (Exception e) {
throw new RuntimeException("Failed to parse file '" + fileName + "'", e);
}
}
use of com.google.gson.stream.JsonReader in project intellij-community by JetBrains.
the class StudyProjectGenerator method getCourseInfo.
/**
* Parses course json meta file and finds course name
*
* @return information about course or null if course file is invalid
*/
@Nullable
private static CourseInfo getCourseInfo(File courseFile) {
if (courseFile.isDirectory()) {
File[] courseFiles = courseFile.listFiles((dir, name) -> name.equals(EduNames.COURSE_META_FILE));
if (courseFiles == null || courseFiles.length != 1) {
LOG.info("More than one or without course files");
return null;
}
courseFile = courseFiles[0];
}
CourseInfo courseInfo = null;
BufferedReader reader = null;
try {
if (courseFile.getName().equals(EduNames.COURSE_META_FILE)) {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(courseFile), "UTF-8"));
JsonReader r = new JsonReader(reader);
JsonParser parser = new JsonParser();
JsonElement el = parser.parse(r);
String courseName = el.getAsJsonObject().get(COURSE_NAME_ATTRIBUTE).getAsString();
String courseDescription = el.getAsJsonObject().get(COURSE_DESCRIPTION).getAsString();
JsonArray courseAuthors = el.getAsJsonObject().get(AUTHOR_ATTRIBUTE).getAsJsonArray();
String language = el.getAsJsonObject().get(LANGUAGE_ATTRIBUTE).getAsString();
courseInfo = new CourseInfo();
courseInfo.setName(courseName);
courseInfo.setDescription(courseDescription);
courseInfo.setType("pycharm " + language);
final ArrayList<StepicUser> authors = new ArrayList<>();
for (JsonElement author : courseAuthors) {
final JsonObject authorAsJsonObject = author.getAsJsonObject();
final StepicUser stepicUser = new StepicUser();
stepicUser.setFirstName(authorAsJsonObject.get("first_name").getAsString());
stepicUser.setLastName(authorAsJsonObject.get("last_name").getAsString());
authors.add(stepicUser);
}
courseInfo.setAuthors(authors);
}
} catch (Exception e) {
//error will be shown in UI
} finally {
StudyUtils.closeSilently(reader);
}
return courseInfo;
}
use of com.google.gson.stream.JsonReader in project Minechem by iopleke.
the class ElementHandler method readFromStream.
private static void readFromStream(InputStream stream) {
JsonReader jReader = new JsonReader(new InputStreamReader(stream));
JsonParser parser = new JsonParser();
Set<Map.Entry<String, JsonElement>> elementsSet = parser.parse(jReader).getAsJsonObject().entrySet();
int count = 0;
for (Map.Entry<String, JsonElement> elementEntry : elementsSet) {
if (!elementEntry.getValue().isJsonObject()) {
continue;
}
JsonObject elementObject = elementEntry.getValue().getAsJsonObject();
ElementRegistry.getInstance().registerElement(Integer.parseInt(elementEntry.getKey()), elementObject.get("longName").getAsString(), elementObject.get("shortName").getAsString(), elementObject.get("form").getAsString(), elementObject.get("type").getAsString(), Integer.parseInt(elementObject.get("neutrons").getAsString()));
count++;
}
LogHelper.info("Total of " + count + " elements registered");
}
use of com.google.gson.stream.JsonReader in project gerrit by GerritCodeReview.
the class ChangeEditIT method readContentFromJson.
private <T> T readContentFromJson(RestResponse r, Class<T> clazz) throws Exception {
r.assertOK();
JsonReader jsonReader = new JsonReader(r.getReader());
jsonReader.setLenient(true);
return newGson().fromJson(jsonReader, clazz);
}
use of com.google.gson.stream.JsonReader in project gerrit by GerritCodeReview.
the class ChangeReviewersIT method readContentFromJson.
private static <T> T readContentFromJson(RestResponse r, int expectedStatus, Class<T> clazz) throws Exception {
r.assertStatus(expectedStatus);
JsonReader jsonReader = new JsonReader(r.getReader());
jsonReader.setLenient(true);
return newGson().fromJson(jsonReader, clazz);
}
Aggregations