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:com.aliyun.openservices.odps.console.common.JobDetailInfo.java

License:Apache License

private FuxiTask getFuxiTaskFromJson(JsonReader reader) throws IOException {
    FuxiTask task = new FuxiTask();

    reader.beginObject();/*w  ww  .  jav a  2  s .  c  o  m*/
    while (reader.hasNext()) {
        String nameInTask = reader.nextName();
        if (nameInTask.equals("name")) {
            task.name = reader.nextString();
        } else if (nameInTask.equals("instances")) {
            task.instances = new ArrayList<FuxiInstance>();
            task.upTasks = new ArrayList<FuxiTask>();
            task.downTasks = new ArrayList<FuxiTask>();
            reader.beginArray();
            while (reader.hasNext()) {
                task.instances.add(getFuxiInstanceFromJson(reader));
            }
            reader.endArray();
        } else {
            reader.skipValue();
        }
    }
    reader.endObject();
    return task;
}

From source file:com.aliyun.openservices.odps.console.common.JobDetailInfo.java

License:Apache License

private FuxiInstance getFuxiInstanceFromJson(JsonReader reader) throws IOException {
    FuxiInstance inst = new FuxiInstance();

    reader.beginObject();//from w  w w.ja  v  a 2s. c  o m
    long endTime = 0;
    while (reader.hasNext()) {
        String nameInInstance = reader.nextName();
        if (nameInInstance.equals("id")) {
            inst.id = reader.nextString();
        } else if (nameInInstance.equals("logId")) {
            inst.logid = reader.nextString();
            inst.IpAndPath = this.decodeLogId(inst.logid);
        } else if (nameInInstance.equals("startTime")) {
            inst.startTime = reader.nextLong();
        } else if (nameInInstance.equals("endTime")) {
            endTime = reader.nextLong();
        } else if (nameInInstance.equals("status")) {
            inst.status = reader.nextString();
        } else {
            reader.skipValue();
        }
    }
    inst.duration = (int) (endTime - inst.startTime);
    reader.endObject();
    return inst;
}

From source file:com.android.build.gradle.external.gson.PlainFileGsonTypeAdaptor.java

License:Apache License

@Override
public File read(JsonReader jsonReader) throws IOException {
    String path = jsonReader.nextString();
    return new File(path);
}

From source file:com.android.build.gradle.internal.gson.FileGsonTypeAdaptor.java

License:Apache License

@Override
public File read(JsonReader jsonReader) throws IOException {
    String path = jsonReader.nextString();
    return fileResolver.resolve(path);
}

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

License:Apache License

@Override
public Message read(JsonReader in) throws IOException {
    in.beginObject();// ww w .  j  a  va 2s.co m
    Message.Kind kind = Message.Kind.UNKNOWN;
    String text = "";
    String rawMessage = null;
    Optional<String> toolName = Optional.absent();
    ImmutableList.Builder<SourceFilePosition> positions = new ImmutableList.Builder<SourceFilePosition>();
    SourceFile legacyFile = SourceFile.UNKNOWN;
    SourcePosition legacyPosition = SourcePosition.UNKNOWN;
    while (in.hasNext()) {
        String name = in.nextName();
        if (name.equals(KIND)) {
            //noinspection StringToUpperCaseOrToLowerCaseWithoutLocale
            Message.Kind theKind = KIND_STRING_ENUM_MAP.inverse().get(in.nextString().toLowerCase());
            kind = (theKind != null) ? theKind : Message.Kind.UNKNOWN;
        } else if (name.equals(TEXT)) {
            text = in.nextString();
        } else if (name.equals(RAW_MESSAGE)) {
            rawMessage = in.nextString();
        } else if (name.equals(TOOL_NAME)) {
            toolName = Optional.of(in.nextString());
        } else if (name.equals(SOURCE_FILE_POSITIONS)) {
            switch (in.peek()) {
            case BEGIN_ARRAY:
                in.beginArray();
                while (in.hasNext()) {
                    positions.add(mSourceFilePositionTypeAdapter.read(in));
                }
                in.endArray();
                break;
            case BEGIN_OBJECT:
                positions.add(mSourceFilePositionTypeAdapter.read(in));
                break;
            default:
                in.skipValue();
                break;
            }
        } else if (name.equals(LEGACY_SOURCE_PATH)) {
            legacyFile = new SourceFile(new File(in.nextString()));
        } else if (name.equals(LEGACY_POSITION)) {
            legacyPosition = mSourcePositionTypeAdapter.read(in);
        } else {
            in.skipValue();
        }
    }
    in.endObject();

    if (legacyFile != SourceFile.UNKNOWN || legacyPosition != SourcePosition.UNKNOWN) {
        positions.add(new SourceFilePosition(legacyFile, legacyPosition));
    }
    if (rawMessage == null) {
        rawMessage = text;
    }
    ImmutableList<SourceFilePosition> sourceFilePositions = positions.build();
    if (!sourceFilePositions.isEmpty()) {
        return new Message(kind, text, rawMessage, toolName, sourceFilePositions);
    } else {
        return new Message(kind, text, rawMessage, toolName, ImmutableList.of(SourceFilePosition.UNKNOWN));
    }
}

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

License:Apache License

@Override
public SourceFile read(JsonReader in) throws IOException {
    switch (in.peek()) {
    case BEGIN_OBJECT:
        in.beginObject();/*from   w  w w  .  j  av a  2 s  .c om*/
        String filePath = null;
        String description = null;
        while (in.hasNext()) {
            String name = in.nextName();
            if (name.equals(PATH)) {
                filePath = in.nextString();
            } else if (DESCRIPTION.equals(name)) {
                description = in.nextString();
            } else {
                in.skipValue();
            }
        }
        in.endObject();
        if (!Strings.isNullOrEmpty(filePath)) {
            File file = new File(filePath);
            if (!Strings.isNullOrEmpty(description)) {
                return new SourceFile(file, description);
            } else {
                return new SourceFile(file);
            }
        } else {
            if (!Strings.isNullOrEmpty(description)) {
                return new SourceFile(description);
            } else {
                return SourceFile.UNKNOWN;
            }
        }
    case STRING:
        String fileName = in.nextString();
        if (Strings.isNullOrEmpty(fileName)) {
            return SourceFile.UNKNOWN;
        }
        return new SourceFile(new File(fileName));
    default:
        return SourceFile.UNKNOWN;
    }

}

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

License:Apache License

@Override
public Message read(JsonReader in) throws IOException {
    in.beginObject();/*from   www.j a v a2  s  . co m*/
    Message.Kind kind = Message.Kind.UNKNOWN;
    String text = "";
    String rawMessage = null;
    ImmutableList.Builder<SourceFilePosition> positions = new ImmutableList.Builder<SourceFilePosition>();
    SourceFile legacyFile = SourceFile.UNKNOWN;
    SourcePosition legacyPosition = SourcePosition.UNKNOWN;
    while (in.hasNext()) {
        String name = in.nextName();
        if (name.equals(KIND)) {
            //noinspection StringToUpperCaseOrToLowerCaseWithoutLocale
            Message.Kind theKind = KIND_STRING_ENUM_MAP.inverse().get(in.nextString().toLowerCase());
            kind = (theKind != null) ? theKind : Message.Kind.UNKNOWN;
        } else if (name.equals(TEXT)) {
            text = in.nextString();
        } else if (name.equals(RAW_MESSAGE)) {
            rawMessage = in.nextString();
        } else if (name.equals(SOURCE_FILE_POSITIONS)) {
            switch (in.peek()) {
            case BEGIN_ARRAY:
                in.beginArray();
                while (in.hasNext()) {
                    positions.add(mSourceFilePositionTypeAdapter.read(in));
                }
                in.endArray();
                break;
            case BEGIN_OBJECT:
                positions.add(mSourceFilePositionTypeAdapter.read(in));
                break;
            default:
                in.skipValue();
                break;
            }
        } else if (name.equals(LEGACY_SOURCE_PATH)) {
            legacyFile = new SourceFile(new File(in.nextString()));
        } else if (name.equals(LEGACY_POSITION)) {
            legacyPosition = mSourcePositionTypeAdapter.read(in);
        } else {
            in.skipValue();
        }
    }
    in.endObject();

    if (legacyFile != SourceFile.UNKNOWN || legacyPosition != SourcePosition.UNKNOWN) {
        positions.add(new SourceFilePosition(legacyFile, legacyPosition));
    }
    if (rawMessage == null) {
        rawMessage = text;
    }
    ImmutableList<SourceFilePosition> sourceFilePositions = positions.build();
    if (!sourceFilePositions.isEmpty()) {
        return new Message(kind, text, rawMessage, sourceFilePositions);
    } else {
        return new Message(kind, text, rawMessage, ImmutableList.of(SourceFilePosition.UNKNOWN));
    }
}

From source file:com.atlauncher.adapter.ColorTypeAdapter.java

License:Open Source License

@Override
public Color read(JsonReader reader) throws IOException {
    reader.beginObject();/*from   www.  ja  va  2s .c  o m*/
    String next = reader.nextName();
    if (!next.equalsIgnoreCase("value")) {
        throw new JsonParseException("Key " + next + " isnt a valid key");
    }
    String hex = reader.nextString();
    reader.endObject();
    int[] rgb = toRGB(clamp(hex.substring(1)));
    return new Color(rgb[0], rgb[1], rgb[2]);
}

From source file:com.atlauncher.workers.EnumTypeAdapterFactory.java

License:Creative Commons License

@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
    if (!type.getRawType().isEnum())
        return null;
    final Map<String, T> map = new HashMap<String, T>();
    for (T c : (T[]) type.getRawType().getEnumConstants()) {
        map.put(c.toString().toLowerCase(Locale.US), c);
    }//from   www .j a va 2  s. co  m

    return new TypeAdapter<T>() {
        @Override
        public T read(JsonReader reader) throws IOException {
            if (reader.peek() == JsonToken.NULL) {
                reader.nextNull();
                return null;
            }
            String name = reader.nextString();
            if (name == null)
                return null;
            return map.get(name.toLowerCase(Locale.US));
        }

        @Override
        public void write(JsonWriter writer, T value) throws IOException {
            if (value == null) {
                writer.nullValue();
            } else {
                writer.value(value.toString().toLowerCase(Locale.US));
            }
        }
    };
}

From source file:com.bzcentre.dapiPush.ReceipientTypeAdapter.java

License:Open Source License

@Override
public Receipient read(JsonReader in)
        throws IOException, IllegalStateException, JsonParseException, NumberFormatException {
    NginxClojureRT.log.debug(TAG + " invoked...");
    Receipient receipient = new Receipient();
    if (in.peek() == JsonToken.NULL) {
        in.nextNull();//from   w  w  w  .  jav  a  2s  . c o m
        return null;
    }

    in.beginObject();
    while (in.hasNext()) {
        switch (in.nextName()) {
        case "apns_token":
            if (in.peek() == JsonToken.NULL) {
                in.nextNull();
            } else
                receipient.setApns_Token(in.nextString());
            break;
        case "fcm_token":
            if (in.peek() == JsonToken.NULL) {
                in.nextNull();
            } else
                receipient.setFcm_Token(in.nextString());
            break;
        case "payload":
            receipient.setPayload(extractPayload(in));
            break;
        }
    }
    in.endObject();

    NginxClojureRT.log.debug(TAG + "Deserializing and adding receipient of "
            + (receipient.getApns_Token() == null ? "fcm--" + receipient.getFcm_Token()
                    : "apns--" + receipient.getApns_Token()));
    return receipient;
}