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

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

Introduction

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

Prototype

public int nextInt() throws IOException 

Source Link

Document

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

Usage

From source file:at.orz.arangodb.entity.CollectionStatusTypeAdapter.java

License:Apache License

@Override
public CollectionStatus read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();// www.j a v  a 2 s .c om
        return null;
    }

    CollectionStatus ret = CollectionStatus.valueOf(in.nextInt());
    return ret;
}

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);// w w w.  j  a va  2  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);//from   w ww  .  jav  a2 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(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

private DefinitionSite readDefinition(JsonReader in) throws IOException {
    DefinitionSite def = DefinitionSites.createUnknownDefinitionSite();
    def.setKind(null);/*from  ww w. ja v  a  2  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);/* w w  w. j a  va2  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(VmMethodName.get(in.nextString()));
        } else if (CS_KIND.equals(name)) {
            site.setKind(CallSiteKind.valueOf(in.nextString()));
        }
    }
    in.endObject();
    return site;
}

From source file:co.cask.cdap.format.StructuredRecordStringConverter.java

License:Apache License

private static Object readJson(JsonReader reader, Schema schema) throws IOException {
    switch (schema.getType()) {
    case NULL:/*from ww  w .  j a  v  a2s .c  om*/
        reader.nextNull();
        return null;
    case BOOLEAN:
        return reader.nextBoolean();
    case INT:
        return reader.nextInt();
    case LONG:
        return reader.nextLong();
    case FLOAT:
        // Force down cast
        return (float) reader.nextDouble();
    case DOUBLE:
        return reader.nextDouble();
    case BYTES:
        return readBytes(reader);
    case STRING:
        return reader.nextString();
    case ENUM:
        // Currently there is no standard container to represent enum type
        return reader.nextString();
    case ARRAY:
        return readArray(reader, schema.getComponentSchema());
    case MAP:
        return readMap(reader, schema.getMapSchema());
    case RECORD:
        return readRecord(reader, schema);
    case UNION:
        return readUnion(reader, schema);
    }

    throw new IOException("Unsupported schema: " + schema);
}

From source file:co.cask.cdap.format.StructuredRecordStringConverter.java

License:Apache License

private static byte[] readBytes(JsonReader reader) throws IOException {
    ByteArrayOutputStream os = new ByteArrayOutputStream(128);
    reader.beginArray();/*from w ww.j  av  a2 s  . c  o  m*/
    while (reader.peek() != JsonToken.END_ARRAY) {
        os.write(reader.nextInt());
    }
    reader.endArray();
    return os.toByteArray();
}

From source file:com.android.common.ide.common.blame.SourcePositionJsonTypeAdapter.java

License:Apache License

@Override
public SourcePosition read(JsonReader in) throws IOException {
    int startLine = -1, startColumn = -1, startOffset = -1;
    int endLine = -1, endColumn = -1, endOffset = -1;
    in.beginObject();/* ww w  .j a v  a2  s .  c o  m*/
    while (in.hasNext()) {
        String name = in.nextName();
        if (name.equals(START_LINE)) {
            startLine = in.nextInt();
        } else if (name.equals(START_COLUMN)) {
            startColumn = in.nextInt();
        } else if (name.equals(START_OFFSET)) {
            startOffset = in.nextInt();
        } else if (name.equals(END_LINE)) {
            endLine = in.nextInt();
        } else if (name.equals(END_COLUMN)) {
            endColumn = in.nextInt();
        } else if (name.equals(END_OFFSET)) {
            endOffset = in.nextInt();
        } else {
            in.skipValue();
        }
    }
    in.endObject();

    endLine = (endLine != -1) ? endLine : startLine;
    endColumn = (endColumn != -1) ? endColumn : startColumn;
    endOffset = (endOffset != -1) ? endOffset : startOffset;
    return new SourcePosition(startLine, startColumn, startOffset, endLine, endColumn, endOffset);
}

From source file:com.dangdang.ddframe.job.api.config.impl.AbstractJobConfigurationGsonTypeAdapter.java

License:Apache License

@Override
public T read(final JsonReader in) throws IOException {
    String jobName = "";
    String cron = "";
    int shardingTotalCount = 0;
    String shardingItemParameters = "";
    String jobParameter = "";
    boolean failover = false;
    boolean misfire = failover;
    String description = "";
    JobProperties jobProperties = new JobProperties();
    JobEventConfiguration[] jobEventConfigs = null;
    JobType jobType = null;//  w w  w .j a  va 2  s .  co m
    String jobClass = "";
    DataflowJobConfiguration.DataflowType dataflowType = null;
    boolean streamingProcess = false;
    int concurrentDataProcessThreadCount = 0;
    String scriptCommandLine = "";
    Map<String, Object> customizedValueMap = new HashMap<>(32, 1);
    in.beginObject();
    while (in.hasNext()) {
        String jsonName = in.nextName();
        switch (jsonName) {
        case "jobName":
            jobName = in.nextString();
            break;
        case "cron":
            cron = in.nextString();
            break;
        case "shardingTotalCount":
            shardingTotalCount = in.nextInt();
            break;
        case "shardingItemParameters":
            shardingItemParameters = in.nextString();
            break;
        case "jobParameter":
            jobParameter = in.nextString();
            break;
        case "failover":
            failover = in.nextBoolean();
            break;
        case "misfire":
            misfire = in.nextBoolean();
            break;
        case "description":
            description = in.nextString();
            break;
        case "jobProperties":
            jobProperties = getJobProperties(in);
            break;
        case "jobEventConfigs":
            jobEventConfigs = getJobEventConfigs(in);
            break;
        case "jobType":
            jobType = JobType.valueOf(in.nextString());
            break;
        case "jobClass":
            jobClass = in.nextString();
            break;
        case "dataflowType":
            dataflowType = DataflowJobConfiguration.DataflowType.valueOf(in.nextString());
            break;
        case "streamingProcess":
            streamingProcess = in.nextBoolean();
            break;
        case "concurrentDataProcessThreadCount":
            concurrentDataProcessThreadCount = in.nextInt();
            break;
        case "scriptCommandLine":
            scriptCommandLine = in.nextString();
            break;
        default:
            addToCustomizedValueMap(jsonName, in, customizedValueMap);
            break;
        }
    }
    in.endObject();
    JobCoreConfiguration coreConfig = getJobCoreConfiguration(jobName, cron, shardingTotalCount,
            shardingItemParameters, jobParameter, failover, misfire, description, jobProperties,
            jobEventConfigs);
    JobTypeConfiguration typeConfig = getJobTypeConfiguration(coreConfig, jobType, jobClass, dataflowType,
            streamingProcess, concurrentDataProcessThreadCount, scriptCommandLine);
    return getJobRootConfiguration(typeConfig, customizedValueMap);
}

From source file:com.dangdang.ddframe.job.util.AbstractJobConfigurationGsonTypeAdapter.java

License:Apache License

@Override
public T read(final JsonReader in) throws IOException {
    String jobName = "";
    String cron = "";
    int shardingTotalCount = 0;
    String shardingItemParameters = "";
    String jobParameter = "";
    boolean failover = false;
    boolean misfire = failover;
    String description = "";
    JobProperties jobProperties = new JobProperties();
    JobEventConfiguration[] jobEventConfigs = null;
    JobType jobType = null;/*from  w  w  w.  ja  v  a  2s  .co  m*/
    String jobClass = "";
    boolean streamingProcess = false;
    String scriptCommandLine = "";
    Map<String, Object> customizedValueMap = new HashMap<>(32, 1);
    in.beginObject();
    while (in.hasNext()) {
        String jsonName = in.nextName();
        switch (jsonName) {
        case "jobName":
            jobName = in.nextString();
            break;
        case "cron":
            cron = in.nextString();
            break;
        case "shardingTotalCount":
            shardingTotalCount = in.nextInt();
            break;
        case "shardingItemParameters":
            shardingItemParameters = in.nextString();
            break;
        case "jobParameter":
            jobParameter = in.nextString();
            break;
        case "failover":
            failover = in.nextBoolean();
            break;
        case "misfire":
            misfire = in.nextBoolean();
            break;
        case "description":
            description = in.nextString();
            break;
        case "jobProperties":
            jobProperties = getJobProperties(in);
            break;
        case "jobEventConfigs":
            jobEventConfigs = getJobEventConfigs(in);
            break;
        case "jobType":
            jobType = JobType.valueOf(in.nextString());
            break;
        case "jobClass":
            jobClass = in.nextString();
            break;
        case "streamingProcess":
            streamingProcess = in.nextBoolean();
            break;
        case "scriptCommandLine":
            scriptCommandLine = in.nextString();
            break;
        default:
            addToCustomizedValueMap(jsonName, in, customizedValueMap);
            break;
        }
    }
    in.endObject();
    JobCoreConfiguration coreConfig = getJobCoreConfiguration(jobName, cron, shardingTotalCount,
            shardingItemParameters, jobParameter, failover, misfire, description, jobProperties,
            jobEventConfigs);
    JobTypeConfiguration typeConfig = getJobTypeConfiguration(coreConfig, jobType, jobClass, streamingProcess,
            scriptCommandLine);
    return getJobRootConfiguration(typeConfig, customizedValueMap);
}