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:cc.kave.commons.utils.json.legacy.UsageTypeAdapter.java

License:Open Source License

@Override
public Usage read(JsonReader in) throws IOException {

    if (in.peek() == JsonToken.STRING) {
        String val = in.nextString();
        Asserts.assertEquals("NoUsage", val, "Invalid JSON. Expected 'NoUsage', but found '" + val + "'.");
        return new NoUsage();
    }//from w  w  w  . j  av a  2 s. co  m

    Query q = new Query();
    q.setAllCallsites(null);

    in.beginObject();
    while (in.hasNext()) {
        String name = in.nextName();
        if (TYPE.equals(name)) {
            q.setType(CoReTypeName.get(in.nextString()));
        } else if (CLASS_CTX.equals(name)) {
            q.setClassContext(CoReTypeName.get(in.nextString()));
        } else if (METHOD_CTX.equals(name)) {
            q.setMethodContext(CoReMethodName.get(in.nextString()));
        } else if (DEFINITION.equals(name)) {
            q.setDefinition(readDefinition(in));
        } else if (SITES.equals(name)) {
            q.setAllCallsites(readCallSites(in));
        } else {
            // skip value (most likely $type key from .net serialization)
            in.nextString();
        }
    }
    in.endObject();
    return q;
}

From source file:cc.kave.commons.utils.json.legacy.UsageTypeAdapter.java

License:Open Source License

private DefinitionSite readDefinition(JsonReader in) throws IOException {
    DefinitionSite def = DefinitionSites.createUnknownDefinitionSite();
    def.setKind(null);/*from w  w  w. jav a2  s .  c  o  m*/

    in.beginObject();
    while (in.hasNext()) {
        String name = in.nextName();
        if (DEF_KIND.equals(name)) {
            def.setKind(DefinitionSiteKind.valueOf(in.nextString()));
        } else if (DEF_ARG.equals(name)) {
            def.setArgIndex(in.nextInt());
        } else if (DEF_FIELD.equals(name)) {
            def.setField(CoReFieldName.get(in.nextString()));
        } else if (DEF_METHOD.equals(name)) {
            def.setMethod(CoReMethodName.get(in.nextString()));
        }
    }
    in.endObject();

    return def;
}

From source file:cc.kave.commons.utils.json.legacy.UsageTypeAdapter.java

License:Open Source License

private CallSite readCallSite(JsonReader in) throws IOException {
    CallSite site = CallSites.createReceiverCallSite("LT.m()V");
    site.setKind(null);//ww  w.ja  va  2  s .c  om
    site.setMethod(null);

    in.beginObject();
    while (in.hasNext()) {
        String name = in.nextName();
        if (CS_ARG.equals(name)) {
            site.setArgIndex(in.nextInt());
        } else if (CS_CALL.equals(name)) {
            site.setMethod(CoReMethodName.get(in.nextString()));
        } else if (CS_KIND.equals(name)) {
            site.setKind(CallSiteKind.valueOf(in.nextString()));
        }
    }
    in.endObject();
    return site;
}

From source file:cc.recommenders.utils.gson.UsageTypeAdapter.java

License:Open Source License

@Override
public Usage read(JsonReader in) throws IOException {
    Query q = new Query();
    q.setAllCallsites(null);/*from w  w w  . j  a v a  2s  . co  m*/

    in.beginObject();
    while (in.hasNext()) {
        String name = in.nextName();
        if (TYPE.equals(name)) {
            q.setType(VmTypeName.get(in.nextString()));
        } else if (CLASS_CTX.equals(name)) {
            q.setClassContext(VmTypeName.get(in.nextString()));
        } else if (METHOD_CTX.equals(name)) {
            q.setMethodContext(VmMethodName.get(in.nextString()));
        } else if (DEFINITION.equals(name)) {
            q.setDefinition(readDefinition(in));
        } else if (SITES.equals(name)) {
            q.setAllCallsites(readCallSites(in));
        } else {
            // skip value (most likely $type key from .net serialization)
            in.nextString();
        }
    }
    in.endObject();
    return q;
}

From source file:cc.recommenders.utils.gson.UsageTypeAdapter.java

License:Open Source License

private DefinitionSite readDefinition(JsonReader in) throws IOException {
    DefinitionSite def = DefinitionSites.createUnknownDefinitionSite();
    def.setKind(null);/*from   w ww  .ja  v a2 s.c  o m*/

    in.beginObject();
    while (in.hasNext()) {
        String name = in.nextName();
        if (DEF_KIND.equals(name)) {
            def.setKind(DefinitionSiteKind.valueOf(in.nextString()));
        } else if (DEF_ARG.equals(name)) {
            def.setArgIndex(in.nextInt());
        } else if (DEF_FIELD.equals(name)) {
            def.setField(VmFieldName.get(in.nextString()));
        } else if (DEF_METHOD.equals(name)) {
            def.setMethod(VmMethodName.get(in.nextString()));
        }
    }
    in.endObject();

    return def;
}

From source file:cc.recommenders.utils.gson.UsageTypeAdapter.java

License:Open Source License

private CallSite readCallSite(JsonReader in) throws IOException {
    CallSite site = CallSites.createReceiverCallSite("LT.m()V");
    site.setKind(null);/*from  w  ww. j  a  v a 2 s .co m*/
    site.setMethod(null);

    in.beginObject();
    while (in.hasNext()) {
        String name = in.nextName();
        if (CS_ARG.equals(name)) {
            site.setArgIndex(in.nextInt());
        } else if (CS_CALL.equals(name)) {
            site.setMethod(VmMethodName.get(in.nextString()));
        } else if (CS_KIND.equals(name)) {
            site.setKind(CallSiteKind.valueOf(in.nextString()));
        }
    }
    in.endObject();
    return site;
}

From source file:cern.molr.inspector.json.MissionTypeAdapter.java

License:Apache License

@Override
public Mission read(JsonReader in) throws IOException {
    in.beginObject();//from   w  w w  .ja v  a 2s . c  om
    in.nextName();
    final String agentName = in.nextString();
    in.nextName();
    final String className = in.nextString();
    in.nextName();
    final String entryPointsString = in.nextString();
    in.endObject();

    return new MissionImpl(agentName, className, Arrays.asList(entryPointsString.split(LIST_SEPARATOR)));
}

From source file:ch.cyberduck.core.importer.ExpandriveBookmarkCollection.java

License:Open Source License

@Override
protected void parse(final Local file) throws AccessDeniedException {
    try {/*from   w  w  w .  j  a  v  a  2  s .  c  om*/
        final JsonReader reader = new JsonReader(new InputStreamReader(file.getInputStream(), "UTF-8"));
        reader.beginArray();
        while (reader.hasNext()) {
            reader.beginObject();
            final Host current = new Host(new FTPProtocol(),
                    PreferencesFactory.get().getProperty("connection.hostname.default"));
            while (reader.hasNext()) {
                final String name = reader.nextName();
                switch (name) {
                case "server":
                    current.setHostname(reader.nextString());
                    break;
                case "username":
                    current.getCredentials().setUsername(reader.nextString());
                    break;
                case "private_key_file":
                    current.getCredentials().setIdentity(LocalFactory.get(reader.nextString()));
                    break;
                case "remotePath":
                    current.setDefaultPath(reader.nextString());
                    break;
                case "type":
                    final Protocol type = ProtocolFactory.forName(reader.nextString());
                    if (null != type) {
                        current.setProtocol(type);
                    }
                    break;
                case "protocol":
                    final Protocol protocol = ProtocolFactory.forName(reader.nextString());
                    if (null != protocol) {
                        current.setProtocol(protocol);
                        // Reset port to default
                        current.setPort(-1);
                    }
                    break;
                case "name":
                    current.setNickname(reader.nextString());
                    break;
                case "region":
                    current.setRegion(reader.nextString());
                    break;
                default:
                    log.warn(String.format("Ignore property %s", name));
                    reader.skipValue();
                    break;
                }
            }
            reader.endObject();
            this.add(current);
        }
        reader.endArray();
    } catch (IllegalStateException | IOException e) {
        throw new LocalAccessDeniedException(e.getMessage(), e);
    }
}

From source file:ch.cyberduck.core.importer.JsonBookmarkCollection.java

License:Open Source License

protected String readNext(final String name, final JsonReader reader) throws IOException {
    if (reader.peek() != JsonToken.NULL) {
        return reader.nextString();
    } else {//from  w w w.  j a  v  a  2 s . c  o m
        reader.skipValue();
        log.warn(String.format("No value for key %s", name));
        return null;
    }
}

From source file:ch.cyberduck.core.s3.S3SessionCredentialsRetriever.java

License:Open Source License

protected AWSCredentials parse(final InputStream in) throws BackgroundException {
    try {/*from  w ww. ja v a 2 s  .c  om*/
        final JsonReader reader = new JsonReader(new InputStreamReader(in, "UTF-8"));
        reader.beginObject();
        String key = null;
        String secret = null;
        String token = null;
        while (reader.hasNext()) {
            final String name = reader.nextName();
            final String value = reader.nextString();
            switch (name) {
            case "AccessKeyId":
                key = value;
                break;
            case "SecretAccessKey":
                secret = value;
                break;
            case "Token":
                token = value;
                break;
            }
        }
        reader.endObject();
        return new AWSSessionCredentials(key, secret, token);
    } catch (UnsupportedEncodingException e) {
        throw new BackgroundException(e);
    } catch (MalformedJsonException e) {
        throw new InteroperabilityException("Invalid JSON response", e);
    } catch (IOException e) {
        throw new DefaultIOExceptionMappingService().map(e);
    }
}