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.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.ModuleMetadataParser.java

License:Apache License

private List<VariantCapability> consumeCapabilities(JsonReader reader) throws IOException {
    ImmutableList.Builder<VariantCapability> capabilities = ImmutableList.builder();
    reader.beginArray();/*  ww w . jav  a  2 s  .  com*/
    while (reader.peek() != END_ARRAY) {
        reader.beginObject();
        String group = null;
        String name = null;
        String version = null;
        while (reader.peek() != END_OBJECT) {
            String val = reader.nextName();
            if (val.equals("group")) {
                group = reader.nextString();
            } else if (val.equals("name")) {
                name = reader.nextString();
            } else if (val.equals("version")) {
                version = reader.nextString();
            }
        }
        capabilities.add(new VariantCapability(group, name, version));
        reader.endObject();
    }
    reader.endArray();
    return capabilities.build();
}

From source file:org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.ModuleMetadataParser.java

License:Apache License

private List<ModuleDependencyConstraint> consumeDependencyConstraints(JsonReader reader) throws IOException {
    List<ModuleDependencyConstraint> dependencies = new ArrayList<ModuleDependencyConstraint>();
    reader.beginArray();//from   w ww. j  av  a2 s  . c  o  m
    while (reader.peek() != END_ARRAY) {
        reader.beginObject();
        String group = null;
        String module = null;
        String reason = null;
        VersionConstraint version = null;
        ImmutableAttributes attributes = ImmutableAttributes.EMPTY;
        while (reader.peek() != END_OBJECT) {
            String name = reader.nextName();
            if (name.equals("group")) {
                group = reader.nextString();
            } else if (name.equals("module")) {
                module = reader.nextString();
            } else if (name.equals("version")) {
                version = consumeVersion(reader);
            } else if (name.equals("reason")) {
                reason = reader.nextString();
            } else if (name.equals("attributes")) {
                attributes = consumeAttributes(reader);
            } else {
                consumeAny(reader);
            }
        }
        dependencies.add(new ModuleDependencyConstraint(group, module, version, reason, attributes));
        reader.endObject();
    }
    reader.endArray();
    return dependencies;
}

From source file:org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.ModuleMetadataParser.java

License:Apache License

private ImmutableVersionConstraint consumeVersion(JsonReader reader) throws IOException {
    reader.beginObject();/*from   w w w .  ja  v a  2  s .c o m*/
    String requiredVersion = "";
    String preferredVersion = "";
    String strictVersion = "";
    List<String> rejects = Lists.newArrayList();
    while (reader.peek() != END_OBJECT) {
        // At this stage, 'requires' implies 'prefers', 'strictly' implies 'requires'.
        String cst = reader.nextName();
        if ("prefers".equals(cst)) {
            preferredVersion = reader.nextString();
        } else if ("requires".equals(cst)) {
            requiredVersion = reader.nextString();
            preferredVersion = requiredVersion;
        } else if ("strictly".equals(cst)) {
            strictVersion = reader.nextString();
            requiredVersion = strictVersion;
            preferredVersion = strictVersion;
        } else if ("rejects".equals(cst)) {
            reader.beginArray();
            while (reader.peek() != END_ARRAY) {
                rejects.add(reader.nextString());
            }
            reader.endArray();
        }
    }
    reader.endObject();
    return DefaultImmutableVersionConstraint.of(preferredVersion, requiredVersion, strictVersion, rejects);
}

From source file:org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.ModuleMetadataParser.java

License:Apache License

private ImmutableList<ExcludeMetadata> consumeExcludes(JsonReader reader) throws IOException {
    ImmutableList.Builder<ExcludeMetadata> builder = new ImmutableList.Builder<ExcludeMetadata>();
    reader.beginArray();/* w  w w  .  j  a  v a 2 s.co  m*/
    while (reader.peek() != END_ARRAY) {
        reader.beginObject();
        String group = null;
        String module = null;
        while (reader.peek() != END_OBJECT) {
            String name = reader.nextName();
            if (name.equals("group")) {
                group = reader.nextString();
            } else if (name.equals("module")) {
                module = reader.nextString();
            } else {
                consumeAny(reader);
            }
        }
        reader.endObject();
        ExcludeMetadata exclude = excludeRuleConverter.createExcludeRule(group, module);
        builder.add(exclude);
    }
    reader.endArray();
    return builder.build();
}

From source file:org.gradle.api.internal.artifacts.ivyservice.ivyresolve.parser.ModuleMetadataParser.java

License:Apache License

private List<ModuleFile> consumeFiles(JsonReader reader) throws IOException {
    List<ModuleFile> files = new ArrayList<ModuleFile>();
    reader.beginArray();//from   w ww .  j  a va  2  s  .co m
    while (reader.peek() != END_ARRAY) {
        reader.beginObject();
        String fileName = null;
        String fileUri = null;
        while (reader.peek() != END_OBJECT) {
            String name = reader.nextName();
            if (name.equals("name")) {
                fileName = reader.nextString();
            } else if (name.equals("url")) {
                fileUri = reader.nextString();
            } else {
                consumeAny(reader);
            }
        }
        reader.endObject();
        files.add(new ModuleFile(fileName, fileUri));
    }
    reader.endArray();
    return files;
}

From source file:org.gradle.nativeplatform.toolchain.internal.msvcpp.version.CommandLineToolVersionLocator.java

License:Apache License

private List<VisualStudioInstallCandidate> parseJson(String json) {
    List<VisualStudioInstallCandidate> installs = Lists.newArrayList();
    JsonReader reader = new JsonReader(new StringReader(json));
    try {/*from   w w  w . j a v  a2  s .co  m*/
        try {
            reader.beginArray();
            while (reader.hasNext()) {
                VisualStudioInstallCandidate candidate = readInstall(reader);

                if (candidate != null) {
                    installs.add(candidate);
                }
            }
            reader.endArray();
        } finally {
            reader.close();
        }
    } catch (IOException e) {
        throw UncheckedException.throwAsUncheckedException(e);
    }

    return installs;
}

From source file:org.gw2InfoViewer.services.json.JsonConversionService.java

License:Open Source License

public static EventList parseEventListWithoutNames(InputStream json) throws IOException {
    List<Event> events;

    events = new ArrayList<Event>();

    JsonReader reader = new JsonReader(new InputStreamReader(json));
    reader.beginObject();/*from w w w  .j  a  v a2  s .co m*/
    if (reader.nextName().equals("events")) {
        reader.beginArray();
        while (reader.peek() != JsonToken.END_ARRAY) {
            Event event = gsonBuilder.create().fromJson(reader, Event.class);
            events.add(event);
        }
        reader.endArray();
        reader.endObject();
    }
    return new EventList(events);
}

From source file:org.hillview.table.rows.GuessSchema.java

License:Open Source License

/**
 * Throws if the value is not valid JSON
 * The gson parser is not strict enough: it parses
 * unquoted strings as JSON.String, so we have to do this manually.
 * Returns true if this is a complex json value, false otherwise.
 *//*from w  w  w. j  a  v  a  2  s.co  m*/
private static boolean isJsonValid(final JsonReader jsonReader) throws IOException {
    JsonToken token;
    boolean isComplex = false;
    loop: while ((token = jsonReader.peek()) != JsonToken.END_DOCUMENT && token != null) {
        switch (token) {
        case BEGIN_ARRAY:
            isComplex = true;
            jsonReader.beginArray();
            break;
        case END_ARRAY:
            isComplex = true;
            jsonReader.endArray();
            break;
        case BEGIN_OBJECT:
            isComplex = true;
            jsonReader.beginObject();
            break;
        case END_OBJECT:
            isComplex = true;
            jsonReader.endObject();
            break;
        case NAME:
            jsonReader.nextName();
            break;
        case STRING:
        case NUMBER:
        case BOOLEAN:
        case NULL:
            jsonReader.skipValue();
            break;
        case END_DOCUMENT:
            break loop;
        default:
            throw new AssertionError(token);
        }
    }
    return isComplex;
}

From source file:org.jboss.tools.aerogear.hybrid.core.plugin.registry.CordovaPluginRegistryManager.java

License:Open Source License

private void parseMaintainers(JsonReader reader, CordovaRegistryPluginInfo plugin) throws IOException {
    reader.beginArray();//from   w  w  w . j  av  a  2s  .c  o  m
    String name = null, email = null;
    JsonToken token = reader.peek();

    while (token != JsonToken.END_ARRAY) {
        switch (token) {
        case BEGIN_OBJECT:
            reader.beginObject();
            name = email = null;
            break;
        case END_OBJECT:
            reader.endObject();
            plugin.addMaintainer(email, name);
            break;
        case NAME:
            String tagName = reader.nextName();
            if ("name".equals(tagName)) {
                name = reader.nextString();
                break;
            }
            if ("email".equals(tagName)) {
                email = reader.nextString();
                break;
            }
        default:
            Assert.isTrue(false, "Unexpected token");
            break;
        }
        token = reader.peek();
    }
    reader.endArray();
}

From source file:org.jboss.tools.aerogear.hybrid.core.plugin.registry.CordovaPluginRegistryManager.java

License:Open Source License

private void parseKeywords(JsonReader reader, CordovaRegistryPluginInfo plugin) throws IOException {
    reader.beginArray();//  w w  w . j  a  v a 2s .c  o m
    while (reader.hasNext()) {
        plugin.addKeyword(reader.nextString());
    }
    reader.endArray();
}