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:org.openstreetmap.josm.plugins.openstreetcam.service.photo.adapter.ReaderUtil.java

License:LGPL

/**
 * Reads a geometry that has the following format: [[lat1,lon1], [lat2,lon2],...[latn,lonn]].
 *
 * @param reader a {@code JsonReader} object
 * @return a list of {@code LatLon} objects
 * @throws IOException if the read operation failed
 *//*w w w . j  a  va2s .com*/
static List<LatLon> readGeometry(final JsonReader reader) throws IOException {
    final List<LatLon> geometry = new ArrayList<>();
    if (reader.peek() == JsonToken.NULL) {
        reader.nextNull();
    } else {
        reader.beginArray();
        while (reader.hasNext()) {
            reader.beginArray();
            final Double lat = reader.nextDouble();
            final Double lon = reader.nextDouble();
            geometry.add(new LatLon(lat, lon));
            reader.endArray();
        }
        reader.endArray();
    }
    return geometry;
}

From source file:org.sonar.server.computation.AnalysisReportService.java

License:Open Source License

@VisibleForTesting
void saveIssues(ComputeEngineContext context) {
    IssueStorage issueStorage = issueStorageFactory.newComputeEngineIssueStorage(context.getProject());

    File issuesFile = new File(context.getReportDirectory(), "issues.json");
    List<DefaultIssue> issues = new ArrayList<>(MAX_ISSUES_SIZE);

    try {//from w  ww . java2 s.  com
        InputStream issuesStream = new FileInputStream(issuesFile);
        JsonReader reader = new JsonReader(new InputStreamReader(issuesStream));
        reader.beginArray();
        while (reader.hasNext()) {
            ReportIssue reportIssue = gson.fromJson(reader, ReportIssue.class);
            DefaultIssue defaultIssue = toIssue(context, reportIssue);
            issues.add(defaultIssue);
            if (shouldPersistIssues(issues, reader)) {
                issueStorage.save(issues);
                issues.clear();
            }
        }

        reader.endArray();
        reader.close();
    } catch (IOException e) {
        throw new IllegalStateException("Failed to read issues", e);
    }
}

From source file:org.spongepowered.plugin.meta.gson.ModMetadataAdapter.java

License:MIT License

@Override
public PluginMetadata read(JsonReader in) throws IOException {
    in.beginObject();/*from  w ww.  j a  v a  2s .c  om*/

    final Set<String> processedKeys = new HashSet<>();

    final PluginMetadata result = new PluginMetadata("unknown");
    String id = null;

    while (in.hasNext()) {
        final String name = in.nextName();
        if (!processedKeys.add(name)) {
            throw new JsonParseException("Duplicate key '" + name + "' in " + in);
        }

        switch (name) {
        case "modid":
            id = in.nextString();
            result.setId(id);
            break;
        case "name":
            result.setName(in.nextString());
            break;
        case "version":
            result.setVersion(in.nextString());
            break;
        case "description":
            result.setDescription(in.nextString());
            break;
        case "url":
            result.setUrl(in.nextString());
            break;
        case "authorList":
            in.beginArray();
            while (in.hasNext()) {
                result.addAuthor(in.nextString());
            }
            in.endArray();
            break;
        case "requiredMods":
            in.beginArray();
            while (in.hasNext()) {
                result.addRequiredDependency(ModDependencyAdapter.INSTANCE.read(in));
            }
            in.endArray();
            break;
        case "dependencies":
            in.beginArray();
            while (in.hasNext()) {
                result.loadAfter(ModDependencyAdapter.INSTANCE.read(in));
            }
            in.endArray();
            break;
        case "dependants":
            in.beginArray();
            while (in.hasNext()) {
                result.loadBefore(ModDependencyAdapter.INSTANCE.read(in));
            }
            in.endArray();
            break;
        default:
            result.setExtension(name, this.gson.fromJson(in, getExtension(name)));
        }
    }

    in.endObject();

    if (id == null) {
        throw new JsonParseException("Mod metadata is missing required element 'modid'");
    }

    return result;
}

From source file:org.spongepowered.plugin.meta.gson.ModMetadataCollectionAdapter.java

License:MIT License

@Override
public List<PluginMetadata> read(JsonReader in) throws IOException {
    in.beginArray();/*w ww  . j  ava  2  s . c o m*/
    ImmutableList.Builder<PluginMetadata> result = ImmutableList.builder();
    while (in.hasNext()) {
        result.add(this.metadataAdapter.read(in));
    }
    in.endArray();
    return result.build();
}

From source file:org.terasology.rendering.gui.components.UITextWrap.java

License:Apache License

public void showFromJson() throws IOException {
    int maxlines = getLineCount();
    int screenlines = getScreenLines();
    long beginpos, endpos, counter;
    if (screenlines > maxlines) {
        beginpos = -1;/* w w  w  . ja va 2 s  .c  o m*/
    } else {
        if (currentpos < 0) {
            currentpos = 0;
        }
        if (currentpos > maxlines - screenlines) {
            currentpos = maxlines - screenlines;
        }
        beginpos = maxlines - (screenlines + currentpos) - 1;
    }
    endpos = beginpos + screenlines + 1;
    //if(endpos >maxlines){endpos = maxlines +1;}
    counter = 0;
    Gson gson = new Gson();
    JsonReader reader = new JsonReader(new FileReader(".\\data\\console\\consolelog.json"));
    reader.beginArray();
    _text = "";
    while (reader.hasNext()) {
        if (counter > beginpos && counter < endpos) {
            _text += gson.fromJson(reader, String.class);
        } else {
            gson.fromJson(reader, String.class);
        }
        counter++;
    }
    reader.endArray();
    reader.close();

}

From source file:org.terasology.rendering.gui.components.UITextWrap.java

License:Apache License

public void loadHelp() throws IOException {
    Gson gson = new Gson();
    JsonReader reader = new JsonReader(new FileReader(".\\data\\console\\help.json"));
    reader.beginArray();/*w  ww .j a  v  a2s  .co m*/
    _text = "";
    while (reader.hasNext()) {
        _text += gson.fromJson(reader, String.class) + newLine;
    }
    reader.endArray();
    reader.close();
}

From source file:org.terasology.rendering.gui.components.UITextWrap.java

License:Apache License

public void loadError() throws IOException {
    Gson gson = new Gson();
    JsonReader reader = new JsonReader(new FileReader(".\\data\\console\\error.json"));
    reader.beginArray();/*from   ww  w .  j  a v  a2 s . c  om*/
    _text = "";
    while (reader.hasNext()) {
        _text += gson.fromJson(reader, String.class) + newLine;
    }
    reader.endArray();
    reader.close();
}

From source file:org.terasology.rendering.gui.components.UITextWrap.java

License:Apache License

public int getLineCount() throws IOException {
    Gson gson = new Gson();
    JsonReader reader = new JsonReader(new FileReader(".\\data\\console\\consolelog.json"));
    int counter = 0;
    reader.beginArray();//from   w w w .  java  2s .  co m
    while (reader.hasNext()) {
        counter++;
        gson.fromJson(reader, String.class);
    }
    reader.endArray();
    reader.close();
    return counter;
}

From source file:org.translator.java.AppInventorProperties.java

License:Apache License

protected AppInventorProperties(JsonReader reader) throws IOException {
    reader.beginObject();/*from   www.  ja  va 2  s  .  co m*/

    while (reader.peek() == JsonToken.NAME) {
        String name = reader.nextName();
        if (name.equals("$Components")) {
            reader.beginArray();

            while (reader.peek() == JsonToken.BEGIN_OBJECT)
                components.add(new AppInventorProperties(reader));

            reader.endArray();
        } else {
            String n = reader.nextString();
            if (n.matches("True|False"))
                n = n.toLowerCase();
            properties.put(name, n);
        }
    }

    reader.endObject();
}

From source file:org.ttrssreader.net.JSONConnector.java

License:Open Source License

private Set<String> parseAttachments(JsonReader reader) throws IOException {
    Set<String> ret = new HashSet<>();
    reader.beginArray();/*w  w w.  j  a v a  2 s .  com*/
    while (reader.hasNext()) {

        String attId = null;
        String attUrl = null;

        reader.beginObject();
        while (reader.hasNext()) {

            try {
                switch (reader.nextName()) {
                case CONTENT_URL:
                    attUrl = reader.nextString();
                    break;
                case ID:
                    attId = reader.nextString();
                    break;
                default:
                    reader.skipValue();
                    break;
                }
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
                reader.skipValue();
            }

        }
        reader.endObject();

        if (attId != null && attUrl != null)
            ret.add(attUrl);
    }
    reader.endArray();
    return ret;
}