List of usage examples for com.google.gson.stream JsonReader close
public void close() throws IOException
From source file:project.latex.balloon.TransmittedDataKeysResource.java
final void loadTransmittedDataKeys(String filePath) throws IOException { if (filePath == null) { throw new IllegalArgumentException("Cannot load keys from null file"); }/*from ww w .j a v a 2 s . c om*/ JsonReader reader = null; try { List<String> dataKeys = new ArrayList<>(); reader = new JsonReader(new FileReader(filePath)); reader.beginObject(); while (reader.hasNext()) { reader.nextName(); reader.beginArray(); while (reader.hasNext()) { dataKeys.add(reader.nextString()); } reader.endArray(); } reader.endObject(); reader.close(); this.transmittedDataKeys = dataKeys; } finally { if (reader != null) { reader.close(); } } }
From source file:se.ekonomipuls.proxy.configuration.AbstractConfiguratorProxy.java
License:Apache License
/** * {@inheritDoc}// w w w . jav a 2s .c o m * * @throws IOException */ public List<AddCategoryAction> getCategories() throws IOException { final JsonReader reader = getConfiguration(ConfigurationType.CATEGORIES); final List<AddCategoryAction> categories = remapUtil.mapCategories(reader, sourceMapping.get(ConfigurationType.CATEGORIES)); reader.close(); return categories; }
From source file:se.ekonomipuls.proxy.configuration.AbstractConfiguratorProxy.java
License:Apache License
/** {@inheritDoc} */ public Map<String, List<AddTagAction>> getTags() throws IOException { final JsonReader reader = getConfiguration(ConfigurationType.TAGS); final Map<String, List<AddTagAction>> tags = remapUtil.mapTags(reader, sourceMapping.get(ConfigurationType.TAGS)); reader.close(); return tags;//from w w w.j a v a2 s. c om }
From source file:se.ekonomipuls.proxy.configuration.AbstractConfiguratorProxy.java
License:Apache License
/** * {@inheritDoc}/*www.j a v a 2s .c o m*/ * * @throws IOException */ public Map<String, List<AddFilterRuleAction>> getFilterRules() throws IOException { final JsonReader reader = getConfiguration(ConfigurationType.FILTER_RULES); final Map<String, List<AddFilterRuleAction>> filterRules = remapUtil.mapFilterRules(reader, sourceMapping.get(ConfigurationType.FILTER_RULES)); reader.close(); return filterRules; }
From source file:se.oskardevelopment.reqa.simple.utility.OutputHelper.java
License:Open Source License
/** * getSavedList gets a list of objects located in the file. * @param klazz Class of the objects contained in the list read from the file. * @return List of all objects read from file. * @throws IOException thrown if reading the file failed. *///from ww w . j a va2s . c o m protected <T> List<T> getSavedList(Class<T> klazz) throws IOException { ArrayList<T> outcome = null; JsonReader reader = null; try { reader = new JsonReader(getReader()); reader.setLenient(true); Type type = new TypeToken<ArrayList<T>>() { }.getType(); outcome = (ArrayList<T>) gson.fromJson(reader, type); } catch (IOException exception) { LOGGER.warn("Exception {} when reading file: {}", exception, FILE_NAME); } finally { if (reader != null) { reader.close(); } } return outcome; }
From source file:tv.loilo.promise.http.ResponseJsonConverter.java
License:Apache License
@NonNull public static JsonElement parse(@NonNull final Reader json) throws JsonIOException, JsonSyntaxException, IOException { final JsonReader jsonReader = new JsonReader(json); try {/*ww w . j av a2 s.c o m*/ return parse(jsonReader); } finally { jsonReader.close(); } }
From source file:vaeke.restcountries.v0.rest.CountryService.java
License:Mozilla Public License
private void initialize() throws IOException { LOG.debug("Loading JSON Database v0"); InputStream is = this.getClass().getClassLoader().getResourceAsStream("countries.json"); Gson gson = new Gson(); JsonReader reader = new JsonReader(new InputStreamReader(is, "UTF-8")); countries = new ArrayList<Country>(); reader.beginArray();/*from ww w.j ava2 s . c o m*/ while (reader.hasNext()) { Country country = gson.fromJson(reader, Country.class); countries.add(country); } reader.endArray(); reader.close(); }
From source file:vaeke.restcountries.v1.rest.CountryService.java
License:Mozilla Public License
private void initialize() { LOG.debug("Loading JSON Database v1"); InputStream is = this.getClass().getClassLoader().getResourceAsStream("countriesV1.json"); Gson gson = new Gson(); JsonReader reader; try {/*from w w w .ja v a 2 s . com*/ reader = new JsonReader(new InputStreamReader(is, "UTF-8")); countries = new ArrayList<Country>(); reader.beginArray(); while (reader.hasNext()) { Country country = gson.fromJson(reader, Country.class); countries.add(country); } reader.endArray(); reader.close(); } catch (Exception e) { LOG.error("Could not load JSON Database v1 "); } }
From source file:vaeke.restcountries.v1.service.JsonFileCountryService.java
License:Mozilla Public License
private void initialize() { LOG.debug("Loading JSON Database v1"); InputStream is = this.getClass().getClassLoader().getResourceAsStream("countriesV1.json"); Gson gson = new Gson(); JsonReader reader; try {/*from w w w .j a v a2s . c om*/ reader = new JsonReader(new InputStreamReader(is, "UTF-8")); countries = new ArrayList<>(); reader.beginArray(); while (reader.hasNext()) { Country country = gson.fromJson(reader, Country.class); countries.add(country); } reader.endArray(); reader.close(); } catch (Exception e) { LOG.error("Could not load JSON Database v1 "); } }
From source file:vogar.ExpectationStore.java
License:Apache License
public void parse(File expectationsFile, ModeId mode, Variant variant) throws IOException { log.verbose("loading expectations file " + expectationsFile); int count = 0; JsonReader reader = null; try {/*from www .j a v a 2 s .c o m*/ reader = new JsonReader(new FileReader(expectationsFile)); reader.setLenient(true); reader.beginArray(); while (reader.hasNext()) { readExpectation(reader, mode, variant); count++; } reader.endArray(); log.verbose("loaded " + count + " expectations from " + expectationsFile); } finally { if (reader != null) { reader.close(); } } }