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

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

Introduction

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

Prototype

public String nextString() throws IOException 

Source Link

Document

Returns the com.google.gson.stream.JsonToken#STRING string value of the next token, consuming it.

Usage

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

License:Apache License

private List<ModuleDependency> consumeDependencies(JsonReader reader) throws IOException {
    List<ModuleDependency> dependencies = new ArrayList<ModuleDependency>();
    reader.beginArray();/*from  w ww  . j ava 2  s.co  m*/
    while (reader.peek() != END_ARRAY) {
        reader.beginObject();
        String group = null;
        String module = null;
        String reason = null;
        ImmutableAttributes attributes = ImmutableAttributes.EMPTY;
        VersionConstraint version = DefaultImmutableVersionConstraint.of();
        ImmutableList<ExcludeMetadata> excludes = ImmutableList.of();
        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("excludes")) {
                excludes = consumeExcludes(reader);
            } else if (name.equals("reason")) {
                reason = reader.nextString();
            } else if (name.equals("attributes")) {
                attributes = consumeAttributes(reader);
            } else {
                consumeAny(reader);
            }
        }
        dependencies.add(new ModuleDependency(group, module, version, excludes, 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 List<VariantCapability> consumeCapabilities(JsonReader reader) throws IOException {
    ImmutableList.Builder<VariantCapability> capabilities = ImmutableList.builder();
    reader.beginArray();/*from  w  w  w  . j ava  2  s  .co m*/
    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 w w .  j a  v a  2 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 ww  w .  jav a2s .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 va  2  s  . com
    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  www.  j a v  a 2 s .  c o  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.api.internal.artifacts.ivyservice.ivyresolve.parser.ModuleMetadataParser.java

License:Apache License

private ImmutableAttributes consumeAttributes(JsonReader reader) throws IOException {
    ImmutableAttributes attributes = ImmutableAttributes.EMPTY;
    reader.beginObject();/*from w w  w  .  j  a va  2  s  . co m*/
    while (reader.peek() != END_OBJECT) {
        String attrName = reader.nextName();
        if (reader.peek() == BOOLEAN) {
            boolean attrValue = reader.nextBoolean();
            attributes = attributesFactory.concat(attributes, Attribute.of(attrName, Boolean.class), attrValue);
        } else {
            String attrValue = reader.nextString();
            attributes = attributesFactory.concat(attributes, Attribute.of(attrName, String.class),
                    new CoercingStringValueSnapshot(attrValue, instantiator));
        }
    }
    reader.endObject();
    return attributes;
}

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

License:Apache License

private VisualStudioInstallCandidate readInstall(JsonReader reader) throws IOException {
    String visualStudioInstallPath = null;
    String visualStudioVersion = null;

    reader.beginObject();//from   w  w  w  .  ja  v a2s .  c o  m
    while (reader.hasNext()) {
        String key = reader.nextName();
        if (key.equals(INSTALLATION_PATH_KEY)) {
            visualStudioInstallPath = reader.nextString();
        } else if (key.equals(INSTALLATION_VERSION_KEY)) {
            visualStudioVersion = reader.nextString();
        } else {
            reader.skipValue();
        }
    }
    reader.endObject();

    File visualStudioInstallDir = new File(visualStudioInstallPath);
    VisualCppInstallCandidate visualCppMetadata = findVisualCppMetadata(visualStudioInstallDir,
            visualStudioVersion);

    if (visualCppMetadata == null) {
        LOGGER.debug("Ignoring candidate Visual Studio version " + visualStudioVersion + " at "
                + visualStudioInstallPath + " because it does not appear to be a valid installation");
        return null;
    } else {
        return new VisualStudioMetadataBuilder().installDir(visualStudioInstallDir)
                .visualCppDir(visualCppMetadata.getVisualCppDir())
                .version(VersionNumber.parse(visualStudioVersion))
                .visualCppVersion(visualCppMetadata.getVersion()).build();
    }
}

From source file:org.guvnor.ala.openshift.access.OpenShiftRuntimeId.java

License:Apache License

public static OpenShiftRuntimeId fromString(String s) {
    String project = null;/*from w w w  .  ja v a 2s  .co m*/
    String service = null;
    String application = null;
    try {
        JsonReader jr = new JsonReader(new StringReader(s));
        jr.beginObject();
        while (jr.hasNext()) {
            String n = jr.nextName();
            if (PROJECT.equals(n)) {
                project = jr.nextString();
            } else if (SERVICE.equals(n)) {
                service = jr.nextString();
            } else if (APPLICATION.equals(n)) {
                application = jr.nextString();
            } else {
                jr.skipValue();
            }
        }
        jr.endObject();
        jr.close();
    } catch (IOException ex) {
        throw new RuntimeException(ex.getMessage(), ex);
    }
    return new OpenShiftRuntimeId(project, service, application);
}

From source file:org.gw2InfoViewer.services.json.typeadaptors.EventAdapter.java

License:Open Source License

@Override
public Event read(JsonReader reader) throws IOException {
    if (reader.peek() == JsonToken.NULL) {
        reader.nextNull();/*from   w  ww .  j  ava 2  s .c om*/
        return null;
    }

    Event event = new Event();

    reader.beginObject();
    reader.nextName(); //world id
    event.setWorldId(reader.nextInt());
    reader.nextName(); //map id
    event.setMapId(reader.nextInt());
    reader.nextName(); //event id
    event.setEventId(reader.nextString());
    reader.nextName();
    event.setState(EventState.valueOf(reader.nextString())); //state
    reader.endObject();

    return event;
}