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

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

Introduction

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

Prototype

public void beginArray() throws IOException 

Source Link

Document

Consumes the next token from the JSON stream and asserts that it is the beginning of a new array.

Usage

From source file:net.evecom.android.MainOneActivity.java

License:Open Source License

/**
 * getTreeThree/*from w  w  w .j  a v  a2 s  . co m*/
 */
private void getTreeThree(final String sbd_id) {
    progressDialog_getInfo = ProgressDialog.show(MainOneActivity.this, "", "...");
    list_jd.removeAll(list_jd);
    msg_listData = new Message();

    new Thread(new Runnable() {
        @Override
        public void run() {
            String strUrl = HttpUtil.BASE_URL + "teventAndroid/queryChildTree?pid=" + sbd_id;
            String strResult = null;
            try {
                strResult = connServerForResult(strUrl);
            } catch (Exception e) {
                msg_listData.what = MESSAGETYPE_02;
                handler3.sendMessage(msg_listData);
                if (null != e) {
                    e.printStackTrace();
                }
                return;
            }
            if (null == strResult || "".equals(strResult)) {
                return;
            }
            // System.out.println(strResult);
            StringReader reader = new StringReader(strResult);
            JsonReader jsonReader = new JsonReader(reader);

            try {
                jsonReader.beginArray();
                while (jsonReader.hasNext()) {
                    jsonReader.beginObject();
                    SysBaseDict dict = new SysBaseDict();
                    while (jsonReader.hasNext()) {
                        String nextName = jsonReader.nextName();
                        String nextValue = "";
                        if (nextName.equals("id")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdCode(nextValue);
                        } else if (nextName.equals("name")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdName(nextValue);
                        } else if (nextName.equals("isparent")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdType(nextValue);
                        } else if (nextName.equals("pid")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdPid(nextValue);
                        } else if (nextName.equals("type")) {
                            nextValue = jsonReader.nextString();
                            dict.setSbdType(nextValue);
                        }
                    }
                    list_jd.add(dict);
                    dict = null;
                    jsonReader.endObject();
                }
                jsonReader.endArray();
            } catch (IOException e) {
                if (null != e) {
                    e.printStackTrace();
                }
            }
            if (null == list_jd || list_jd.size() < 1) {
                msg_listData.what = MESSAGETYPE_02;
            } else {
                msg_listData.what = MESSAGETYPE_01;
            }
            handler3.sendMessage(msg_listData);
        }
    }).start();

}

From source file:net.evecom.android.Welcome.java

License:Open Source License

/**
 * /* w  w w .j a va  2 s  .  co  m*/
 */
private void getEventTypeFromDictAndParse2ListAndSave2DataBase() {
    new Thread(new Runnable() {
        @Override
        public void run() {
            String strUrl = HttpUtil.BASE_URL + "teventAndroid/addItem";
            Message msg = Message.obtain();
            try {
                eventType_json = connServerForResult(strUrl);
            } catch (Exception e) {
                msg.what = MESSAGETYPE_02;
                handler1.sendMessage(msg);

                if (null != e) {
                    e.printStackTrace();
                }
                return;
            }
            if (null == eventType_json || "".equals(eventType_json)) {
                msg.what = MESSAGETYPE_02;
                handler1.sendMessage(msg);
                return;
            }
            StringReader reader = new StringReader(eventType_json);
            JsonReader jsonReader = new JsonReader(reader);
            try {
                jsonReader.beginArray();
                while (jsonReader.hasNext()) {
                    jsonReader.beginObject();
                    EOS_DICT_ENTRY dict = new EOS_DICT_ENTRY();
                    while (jsonReader.hasNext()) {
                        String nextName = jsonReader.nextName();
                        String nextValue = "";
                        if (nextName.equals("DICTID")) {
                            nextValue = jsonReader.nextString();
                            dict.setDICTID(nextValue);
                        } else if (nextName.equals("PARENTID")) {
                            nextValue = jsonReader.nextString();
                            dict.setPARENTID(nextValue);
                        } else if (nextName.equals("DICTTYPEID")) {
                            nextValue = jsonReader.nextString();
                            dict.setDICTTYPEID(nextValue);
                        } else if (nextName.equals("DICTNAME")) {
                            nextValue = jsonReader.nextString();
                            dict.setDICTNAME(nextValue);
                        }
                    }
                    dict_ENTRYs.add(dict);
                    dict = null;
                    jsonReader.endObject();

                }
                jsonReader.endArray();
            } catch (IOException e) {
                msg.what = MESSAGETYPE_02;
                handler1.sendMessage(msg);
                if (null != e) {
                    e.printStackTrace();
                }
                return;
            }
            if (null == dict_ENTRYs || dict_ENTRYs.size() < 1) {
                msg.what = MESSAGETYPE_02;
            } else {
                msg.what = MESSAGETYPE_01;
            }
            handler1.sendMessage(msg);
            return;
        }
    }).start();
}

From source file:net.minecraftforge.gradle.util.json.forgeversion.ForgeArtifactAdapter.java

License:Open Source License

@Override
public ForgeArtifact read(JsonReader in) throws IOException {
    ForgeArtifact out = new ForgeArtifact();

    in.beginArray();

    out.ext = in.nextString();/*from   w ww  .  ja  v a  2  s. c o  m*/
    out.classifier = in.nextString();
    out.hash = in.nextString();

    in.endArray();

    return out;
}

From source file:net.visualillusionsent.newu.StationTracker.java

License:Open Source License

private void loadStations() {
    try {// w  w w.j  av a 2  s .c  om
        File stationsJSON = new File(NewU.cfgDir, "stations.json");
        if (!stationsJSON.exists()) {
            stationsJSON.createNewFile();
            return;
        }

        JsonReader reader = new JsonReader(new FileReader(stationsJSON));
        reader.beginObject(); // Begin main object
        while (reader.hasNext()) {
            String name = reader.nextName();
            if (name.equals("Station")) {
                NewUStation temp = null;
                reader.beginObject(); // Begin Station
                String foundName = null;
                while (reader.hasNext()) {
                    name = reader.nextName();
                    if (name.equals("Name")) {
                        foundName = reader.nextString();
                        continue;
                    } else if (name.equals("Location")) {
                        reader.beginObject(); // Begin Location
                        temp = new NewUStation(foundName, reader); // Pass reader into NewUStation object for parsing
                        reader.endObject(); // End Location
                    } else if (name.equals("Discoverers")) {
                        reader.beginArray(); // Begin Discoverers
                        while (reader.hasNext()) {
                            if (temp != null) {
                                temp.addDiscoverer(reader.nextString());
                            }
                        }
                        reader.endArray(); // End Discoverers
                    } else {
                        reader.skipValue(); // UNKNOWN THING
                    }
                }
                if (temp != null) {
                    stations.put(temp.getName(), temp);
                }
                reader.endObject(); //End Station
            }
        }

        reader.endObject(); // End main object
        reader.close();
    } catch (IOException e) {
        logger.log(Level.SEVERE, "Failed to load stations...");
    }
}

From source file:ninja.leaping.configurate.gson.GsonConfigurationLoader.java

License:Apache License

private void parseArray(JsonReader parser, ConfigurationNode node) throws IOException {
    parser.beginArray();
    JsonToken token;//ww w.  j  a v  a 2  s  .c  om
    while ((token = parser.peek()) != null) {
        switch (token) {
        case END_ARRAY:
            parser.endArray();
            return;
        default:
            parseValue(parser, node.getAppendedNode());
        }
    }
    throw new JsonParseException("Reached end of stream with unclosed array at!");

}

From source file:org.apache.accumulo.core.client.impl.BulkSerialize.java

License:Apache License

/**
 * Read Json array of Bulk.Mapping into LoadMappingIterator
 */// w  w  w .  ja va 2 s  . co m
public static LoadMappingIterator readLoadMapping(String bulkDir, Table.ID tableId, Input input)
        throws IOException {
    final Path lmFile = new Path(bulkDir, Constants.BULK_LOAD_MAPPING);
    JsonReader reader = new JsonReader(new BufferedReader(new InputStreamReader(input.open(lmFile), UTF_8)));
    reader.beginArray();
    return new LoadMappingIterator(tableId, reader);
}

From source file:org.apache.airavata.workflow.core.parser.JsonWorkflowParser.java

License:Apache License

private void readApplications(JsonReader jsonReader) throws IOException, ParserException {
    jsonReader.beginArray();
    ApplicationNode appNode = null;//from ww w .  j a  v  a2 s. c o  m
    while (jsonReader.hasNext()) {
        appNode = readApplication(jsonReader);
        applications.add(appNode);
    }
    jsonReader.endArray();
}

From source file:org.apache.airavata.workflow.core.parser.JsonWorkflowParser.java

License:Apache License

private void readWorkflowInputs(JsonReader jsonReader) throws ParserException, IOException {
    JsonToken peek = jsonReader.peek();//from   www .  java  2  s  .c o  m
    InputNode inputNode;
    NodeModel nodeModel;
    ComponentStatus status;
    String name;
    if (peek == JsonToken.NULL) {
        throw new ParserException("Error! workflow inputs can't be null");
    } else if (peek == JsonToken.BEGIN_ARRAY) {
        jsonReader.beginArray();
        while (jsonReader.hasNext()) {
            jsonReader.beginObject();
            nodeModel = new NodeModel();
            status = new ComponentStatus();
            status.setState(ComponentState.CREATED);
            status.setReason("Created");
            nodeModel.setStatus(status);
            inputNode = new InputNodeImpl(nodeModel);
            while (jsonReader.hasNext()) {
                name = jsonReader.nextName();
                if (name.equals(NAME)) {
                    nodeModel.setName(jsonReader.nextString());
                } else if (name.equals(ID)) {
                    nodeModel.setNodeId(jsonReader.nextString());
                } else if (name.equals(DATATYPE)) {
                    inputNode.setDataType(DataType.valueOf(jsonReader.nextString()));
                } else if (name.equals(DESCRIPTION)) {
                    nodeModel.setDescription(jsonReader.nextString());
                } else if (name.equals(POSITION)) {
                    readPosition(jsonReader);
                } else if (name.equals(NODE_ID)) {
                    jsonReader.skipValue();
                    //                        nodeModel.setNodeId(jsonReader.nextString());
                } else if (name.equals(DEFAULT_VALUE)) {
                    inputNode.setValue(jsonReader.nextString());
                } else {
                    jsonReader.skipValue();
                }
            }
            jsonReader.endObject();
            inputs.add(inputNode);
        }
        jsonReader.endArray();
    } else {
        throw new ParserException("Error! Unsupported value for Workflow Inputs, exptected "
                + getTokenString(JsonToken.BEGIN_OBJECT) + " but found" + getTokenString(peek));
    }
}

From source file:org.apache.airavata.workflow.core.parser.JsonWorkflowParser.java

License:Apache License

private void readWorkflowOutputs(JsonReader jsonReader) throws IOException, ParserException {
    JsonToken peek = jsonReader.peek();/*from   w  w  w . java2 s. c  om*/
    OutputNode outputNode;
    NodeModel nodeModel;
    ComponentStatus status;
    String name;
    if (peek == JsonToken.NULL) {
        throw new ParserException("Error! workflow outputs can't be null");
    } else if (peek == JsonToken.BEGIN_ARRAY) {
        jsonReader.beginArray();
        while (jsonReader.hasNext()) {
            jsonReader.beginObject();
            nodeModel = new NodeModel();
            status = new ComponentStatus();
            status.setState(ComponentState.CREATED);
            status.setReason("Created");
            nodeModel.setStatus(status);
            outputNode = new OutputNodeImpl(nodeModel);
            while (jsonReader.hasNext()) {
                name = jsonReader.nextName();
                if (name.equals(NAME)) {
                    nodeModel.setName(jsonReader.nextString());
                } else if (name.equals(ID)) {
                    nodeModel.setNodeId(jsonReader.nextString());
                } else if (name.equals(DATATYPE)) {
                    jsonReader.skipValue();
                } else if (name.equals(DESCRIPTION)) {
                    nodeModel.setDescription(jsonReader.nextString());
                } else if (name.equals(POSITION)) {
                    readPosition(jsonReader);
                } else if (name.equals(NODE_ID)) {
                    jsonReader.skipValue();
                    //                        nodeModel.setNodeId(jsonReader.nextString());
                } else if (name.equals(DEFAULT_VALUE)) {
                    jsonReader.skipValue();
                } else {
                    jsonReader.skipValue();
                }

            }
            jsonReader.endObject();
            outputs.add(outputNode);
        }
        jsonReader.endArray();
    } else {
        throw new ParserException("Error! Unsupported value for Workflow Outputs, exptected "
                + getTokenString(JsonToken.BEGIN_OBJECT) + " but found" + getTokenString(peek));
    }
}

From source file:org.apache.airavata.workflow.core.parser.JsonWorkflowParser.java

License:Apache License

private void readWorkflowLinks(JsonReader jsonReader) throws IOException, ParserException {
    JsonToken peek = jsonReader.peek();/*from  ww  w.jav  a 2s  .c  om*/
    if (peek == JsonToken.NULL) {
        throw new ParserException(
                "Error! Workflow should have connecting links, found " + getTokenString(peek));
    } else if (peek == JsonToken.BEGIN_ARRAY) {
        jsonReader.beginArray();
        while (jsonReader.hasNext()) {
            links.add(readLink(jsonReader));
        }
        jsonReader.endArray();
    } else {
        throw new ParserException("Error! Unsupported value for workflow links, expected "
                + getTokenString(JsonToken.BEGIN_ARRAY) + " but found" + getTokenString(peek));

    }
}