List of usage examples for com.google.gson.stream JsonReader beginArray
public void beginArray() throws IOException
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 ww . j a v a2 s . com*/ 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 w w w .jav 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(); } } }
From source file:vogar.ExpectationStore.java
License:Apache License
private void readStrings(JsonReader reader, Set<String> output) throws IOException { reader.beginArray(); while (reader.hasNext()) { output.add(reader.nextString()); }//from w w w .j av a 2s .c o m reader.endArray(); }
From source file:vogar.ExpectationStore.java
License:Apache License
private Set<ModeId> readModes(JsonReader reader) throws IOException { Set<ModeId> result = EnumSet.noneOf(ModeId.class); reader.beginArray(); while (reader.hasNext()) { result.add(ModeId.valueOf(reader.nextString().toUpperCase())); }//from w w w .jav a 2 s . c o m reader.endArray(); return result; }
From source file:vogar.ExpectationStore.java
License:Apache License
/** * Expected format: mode_variants: [["host", "X32"], ["host", "X64"]] *//*from www . j a va2s . co m*/ private Map<ModeId, Set<Variant>> readModesAndVariants(JsonReader reader) throws IOException { Map<ModeId, Set<Variant>> result = new EnumMap<ModeId, Set<Variant>>(ModeId.class); reader.beginArray(); while (reader.hasNext()) { reader.beginArray(); ModeId mode = ModeId.valueOf(reader.nextString().toUpperCase()); Set<Variant> set = result.get(mode); if (set == null) { set = EnumSet.noneOf(Variant.class); result.put(mode, set); } set.add(Variant.valueOf(reader.nextString().toUpperCase())); // Note that the following checks that we are at the end of the array. reader.endArray(); } reader.endArray(); return result; }
From source file:yong.dealer.shopping.ShoppingActivity.java
License:Apache License
public void fetchAndParseData() { JsonReader reader; InputStream inputStream = null; try {// www .j av a 2 s . c o m inputStream = getResources() .openRawResource(getResources().getIdentifier("raw/itemlist", "raw", getPackageName())); } catch (Exception e) { } if (inputStream != null) { try { Gson gson = new Gson(); reader = new JsonReader(new InputStreamReader(inputStream, "UTF-8")); reader.beginArray(); while (reader.hasNext()) { ShoppingItem product = gson.fromJson(reader, ShoppingItem.class); //log.info("COINAPTYPE::" + Product.getType()); products.add(product); } reader.endArray(); reader.close(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); return; //this means the network connection is not good or IO } } }
From source file:zack.yovel.clear.infrastructure.model.datapoints.ForecastIoParser.java
License:Apache License
private ArrayList<Alert> parseAlerts(JsonReader reader) throws IOException { ArrayList<Alert> output = new ArrayList<Alert>(); reader.beginArray(); boolean exit = false; while (!exit && reader.hasNext()) { JsonToken token = reader.peek(); switch (token) { case BEGIN_OBJECT: output.add(parseAlert(reader)); break; case END_ARRAY: exit = true;// w ww. j a v a2 s .c o m break; default: reader.skipValue(); } } reader.endArray(); return output; }
From source file:zack.yovel.clear.infrastructure.model.datapoints.ForecastIoParser.java
License:Apache License
private ArrayList<DataPoint> getDataPointList(JsonReader reader) throws IOException { ArrayList<DataPoint> output = new ArrayList<DataPoint>(); reader.beginArray(); while (reader.hasNext()) { JsonToken token = reader.peek(); switch (token) { case BEGIN_OBJECT: output.add(parseDataPoint(reader)); break; default:/*from w ww. ja v a 2 s. com*/ reader.skipValue(); } } reader.endArray(); return output; }