Example usage for com.google.gson.stream JsonReader endArray

List of usage examples for com.google.gson.stream JsonReader endArray

Introduction

In this page you can find the example usage for com.google.gson.stream JsonReader endArray.

Prototype

public void endArray() throws IOException 

Source Link

Document

Consumes the next token from the JSON stream and asserts that it is the end of the current array.

Usage

From source file:vogar.ExpectationStore.java

License:Apache License

private void readStrings(JsonReader reader, Set<String> output) throws IOException {
    reader.beginArray();//from w  w  w . ja v  a 2 s  . c o  m
    while (reader.hasNext()) {
        output.add(reader.nextString());
    }
    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();// www  . java  2s .c  o  m
    while (reader.hasNext()) {
        result.add(ModeId.valueOf(reader.nextString().toUpperCase()));
    }
    reader.endArray();
    return result;
}

From source file:vogar.ExpectationStore.java

License:Apache License

/**
 * Expected format: mode_variants: [["host", "X32"], ["host", "X64"]]
 *//*from w  ww  . ja  va  2  s .c o  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 {//  w  w  w  .jav  a2s.co  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();//from www.j a  v  a 2  s . c om
    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;
            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();/*www .j  a  v a 2s . co m*/
    while (reader.hasNext()) {
        JsonToken token = reader.peek();
        switch (token) {
        case BEGIN_OBJECT:
            output.add(parseDataPoint(reader));
            break;
        default:
            reader.skipValue();
        }
    }
    reader.endArray();
    return output;
}