List of usage examples for com.google.gson.stream JsonReader skipValue
public void skipValue() throws IOException
From source file:edu.rpi.shuttles.data.RPIShuttleDataProvider.java
License:Apache License
@SuppressLint("SimpleDateFormat") private Vehicle readVehicleLocation(JsonReader reader) throws IOException { Vehicle shuttle = new Vehicle(); reader.beginObject();//from w w w.j av a2 s . c o m reader.nextName(); reader.beginObject(); while (reader.hasNext()) { String key = reader.nextName(); if (key.equals("id")) { shuttle.id = reader.nextInt(); } else if (key.equals("name")) { shuttle.name = reader.nextString(); } else if (key.equals("latest_position")) { reader.beginObject(); while (reader.hasNext()) { key = reader.nextName(); if (key.equals("heading")) { shuttle.heading = reader.nextInt(); } else if (key.equals("latitude")) { shuttle.latitude = reader.nextDouble(); } else if (key.equals("longitude")) { shuttle.longitude = reader.nextDouble(); } else if (key.equals("speed")) { shuttle.speed = reader.nextInt(); } else if (key.equals("timestamp")) { SimpleDateFormat iso_format = new SimpleDateFormat("yyyy-MM-dd HH:mmZ"); try { shuttle.timestamp = iso_format.parse(reader.nextString().replace("T", " ")); } catch (ParseException e) { e.printStackTrace(); } } else if (key.equals("public_status_message")) { shuttle.description = reader.nextString(); } else if (key.equals("cardinal_point")) { shuttle.cardinalPoint = reader.nextString(); } } reader.endArray(); } else { reader.skipValue(); } } reader.endObject(); reader.endObject(); Log.d("RPIDataProvider", String.format("Updated Shuttle %S (%S) location...", Integer.toString(shuttle.id), shuttle.name)); return shuttle; }
From source file:guru.qas.martini.report.DefaultTraceabilityMatrix.java
License:Apache License
@Override public void createReport(JsonReader reader, OutputStream outputStream) throws IOException { checkNotNull(reader, "null JsonReader"); checkNotNull(outputStream, "null OutputStream"); Workbook workbook = new XSSFWorkbook(); Sheet sheet = workbook.createSheet("Results"); addHeader(sheet);/*w w w . j av a2s . c o m*/ State state = new DefaultState(); while (reader.hasNext()) { JsonToken peek = reader.peek(); JsonObject object; switch (peek) { case BEGIN_ARRAY: reader.beginArray(); continue; case BEGIN_OBJECT: object = gson.fromJson(reader, JsonObject.class); break; case END_ARRAY: reader.endArray(); continue; case END_DOCUMENT: reader.skipValue(); continue; default: JsonElement element = gson.fromJson(reader, JsonElement.class); LOGGER.warn("skipping unhandled element {}", element); continue; } switch (JsonObjectType.evaluate(object)) { case SUITE: JsonObject suite = SUITE.get(object); state.addSuite(suite); break; case FEATURE: JsonObject feature = FEATURE.get(object); state.addFeature(feature); break; case RESULT: JsonObject result = RESULT.get(object); addResult(state, sheet, result); break; default: LOGGER.warn("skipping unrecognized JsonObject: {}", object); } } state.updateResults(); resizeColumns(sheet); Sheet suiteSheet = workbook.createSheet("Suites"); state.updateSuites(suiteSheet); workbook.write(outputStream); outputStream.flush(); }
From source file:it.bradipao.berengar.DbTool.java
License:Apache License
public static int gson2db(SQLiteDatabase mDB, File jsonFile) { // vars/*from w ww .j a v a 2 s . c om*/ int iTableNum = 0; FileReader fr = null; BufferedReader br = null; JsonReader jr = null; String name = null; String val = null; String mTable = null; String mTableSql = null; ArrayList<String> aFields = null; ArrayList<String> aValues = null; ContentValues cv = null; // file readers try { fr = new FileReader(jsonFile); br = new BufferedReader(fr); jr = new JsonReader(br); } catch (FileNotFoundException e) { Log.e(LOGTAG, "error in gson2db file readers", e); } // parsing try { // start database transaction mDB.beginTransaction(); // open root { jr.beginObject(); // iterate through root objects while (jr.hasNext()) { name = jr.nextName(); if (jr.peek() == JsonToken.NULL) jr.skipValue(); // number of tables else if (name.equals("tables_num")) { val = jr.nextString(); iTableNum = Integer.parseInt(val); if (GOLOG) Log.d(LOGTAG, "TABLE NUM : " + iTableNum); } // iterate through tables array else if (name.equals("tables")) { jr.beginArray(); while (jr.hasNext()) { // start table mTable = null; aFields = null; jr.beginObject(); while (jr.hasNext()) { name = jr.nextName(); if (jr.peek() == JsonToken.NULL) jr.skipValue(); // table name else if (name.equals("table_name")) { mTable = jr.nextString(); } // table sql else if (name.equals("table_sql")) { mTableSql = jr.nextString(); if ((mTable != null) && (mTableSql != null)) { mDB.execSQL("DROP TABLE IF EXISTS " + mTable); mDB.execSQL(mTableSql); if (GOLOG) Log.d(LOGTAG, "DROPPED AND CREATED TABLE : " + mTable); } } // iterate through columns name else if (name.equals("cols_name")) { jr.beginArray(); while (jr.hasNext()) { val = jr.nextString(); if (aFields == null) aFields = new ArrayList<String>(); aFields.add(val); } jr.endArray(); if (GOLOG) Log.d(LOGTAG, "COLUMN NAME : " + aFields.toString()); } // iterate through rows else if (name.equals("rows")) { jr.beginArray(); while (jr.hasNext()) { jr.beginArray(); // iterate through values in row aValues = null; cv = null; while (jr.hasNext()) { val = jr.nextString(); if (aValues == null) aValues = new ArrayList<String>(); aValues.add(val); } jr.endArray(); // add to database cv = new ContentValues(); for (int j = 0; j < aFields.size(); j++) cv.put(aFields.get(j), aValues.get(j)); mDB.insert(mTable, null, cv); if (GOLOG) Log.d(LOGTAG, "INSERT IN " + mTable + " : " + aValues.toString()); } jr.endArray(); } else jr.skipValue(); } // end table jr.endObject(); } jr.endArray(); } else jr.skipValue(); } // close root } jr.endObject(); jr.close(); // successfull transaction mDB.setTransactionSuccessful(); } catch (IOException e) { Log.e(LOGTAG, "error in gson2db gson parsing", e); } finally { mDB.endTransaction(); } return iTableNum; }
From source file:net.visualillusionsent.newu.NewUStation.java
License:Open Source License
NewUStation(String stationName, JsonReader reader) throws IOException { String tempName = stationName == null ? UUID.randomUUID().toString() : stationName; this.discoverers = Collections.synchronizedList(new ArrayList<String>()); this.station = new Location(0, 0, 0); // Initialize while (reader.hasNext()) { String object = reader.nextName(); if (object.equals("Name")) { tempName = reader.nextString(); }/* www . ja v a 2 s .c om*/ if (object.equals("World")) { station.setWorldName(reader.nextString()); } else if (object.equals("Dimension")) { station.setType(DimensionType.fromName(reader.nextString())); } else if (object.equals("X")) { station.setX(reader.nextDouble()); } else if (object.equals("Y")) { station.setY(reader.nextDouble()); } else if (object.equals("Z")) { station.setZ(reader.nextDouble()); } else if (object.equals("RotX")) { station.setRotation((float) reader.nextDouble()); } else if (object.equals("RotY")) { station.setPitch((float) reader.nextDouble()); } else { reader.skipValue(); // Unknown } } this.name = tempName; }
From source file:net.visualillusionsent.newu.StationTracker.java
License:Open Source License
private void loadStations() { try {/*from w ww . jav a 2s. c o m*/ 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:org.apache.airavata.workflow.core.parser.JsonWorkflowParser.java
License:Apache License
private void readWorkflowInfo(JsonReader jsonReader) throws IOException, ParserException { jsonReader.beginObject();/*w ww. j a v a 2s. c o m*/ String name; while (jsonReader.hasNext()) { name = jsonReader.nextName(); if (name.equals(NAME)) { workflowInfo.setName(jsonReader.nextString()); } else if (name.equals(ID)) { workflowInfo.setId(jsonReader.nextString()); } else if (name.equals(DESCRIPTION)) { workflowInfo.setDescription(jsonReader.nextString()); } else if (name.equals(VERSION)) { workflowInfo.setVersion(jsonReader.nextString()); } else if (name.equals(APPLICATIONS)) { readApplications(jsonReader); } else if (name.equals(WORKFLOW_INPUTS)) { readWorkflowInputs(jsonReader); } else if (name.equals(WORKFLOW_OUTPUTS)) { readWorkflowOutputs(jsonReader); } else if (name.equals(LINKS)) { readWorkflowLinks(jsonReader); } else { jsonReader.skipValue(); } } jsonReader.endObject(); //TODO: set count properties of workflow info object }
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 ww w . ja v a 2s . 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();// w w w.j a v a2s. c o m 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 Link readLink(JsonReader jsonReader) throws IOException { jsonReader.beginObject();/* w w w . j a va2 s .c o m*/ String name = null; Link link = new Link(); while (jsonReader.hasNext()) { name = jsonReader.nextName(); if (name.equals(DESCRIPTION)) { link.setDescription(jsonReader.nextString()); } else if (name.equals(FROM)) { link.setFrom(readLinkHelper(jsonReader)); } else if (name.equals(TO)) { link.setTo(readLinkHelper(jsonReader)); } else if (name.equals(ID)) { link.setId(jsonReader.nextString()); } else { jsonReader.skipValue(); } } jsonReader.endObject(); return link; }
From source file:org.apache.airavata.workflow.core.parser.JsonWorkflowParser.java
License:Apache License
private LinkHelper readLinkHelper(JsonReader jsonReader) throws IOException { jsonReader.beginObject();//from w ww . ja v a2 s . c om String name; LinkHelper helper = new LinkHelper(); while (jsonReader.hasNext()) { name = jsonReader.nextName(); if (name.equals(NODE_ID)) { helper.setNodeId(jsonReader.nextString()); } else if (name.equals(OUTPUT_ID) || name.equals(INPUT_ID)) { helper.setPortId(jsonReader.nextString()); } else { jsonReader.skipValue(); } } jsonReader.endObject(); return helper; }