List of usage examples for com.google.gson.stream JsonReader nextBoolean
public boolean nextBoolean() throws IOException
From source file:org.ttrssreader.net.JSONConnector.java
License:Open Source License
private boolean parseArticle(final Article a, final JsonReader reader, final Set<Article.ArticleField> skipNames, final IArticleOmitter filter) throws IOException { boolean skipObject = false; while (reader.hasNext() && reader.peek().equals(JsonToken.NAME)) { if (skipObject) { // field name reader.skipValue();// ww w .j a v a 2s . co m // field value reader.skipValue(); continue; } String name = reader.nextName(); Article.ArticleField field = Article.ArticleField.valueOf(name); try { if (skipNames != null && skipNames.contains(field)) { reader.skipValue(); continue; } switch (field) { case id: a.id = reader.nextInt(); break; case title: a.title = reader.nextString(); break; case unread: a.isUnread = reader.nextBoolean(); break; case updated: a.updated = new Date(reader.nextLong() * 1000); break; case feed_id: if (reader.peek() == JsonToken.NULL) reader.nextNull(); else a.feedId = reader.nextInt(); break; case content: a.content = reader.nextString(); break; case link: a.url = reader.nextString(); break; case comments: a.commentUrl = reader.nextString(); break; case attachments: a.attachments = parseAttachments(reader); break; case marked: a.isStarred = reader.nextBoolean(); break; case published: a.isPublished = reader.nextBoolean(); break; case labels: a.labels = parseLabels(reader); break; case author: a.author = reader.nextString(); break; default: reader.skipValue(); continue; } if (filter != null) skipObject = filter.omitArticle(field, a); } catch (IllegalArgumentException | StopJsonParsingException | IOException e) { Log.w(TAG, "Result contained illegal value for entry \"" + field + "\"."); reader.skipValue(); } } return skipObject; }
From source file:org.wso2.carbon.dynamic.client.web.app.registration.util.DynamicClientWebAppRegistrationUtil.java
License:Open Source License
public static JaggeryOAuthConfigurationSettings getJaggeryAppOAuthSettings(ServletContext servletContext) { JaggeryOAuthConfigurationSettings jaggeryOAuthConfigurationSettings = new JaggeryOAuthConfigurationSettings(); try {//from w ww .j a v a 2 s .co m InputStream inputStream = servletContext.getResourceAsStream(JAGGERY_APP_OAUTH_CONFIG_PATH); if (inputStream != null) { JsonReader reader = new JsonReader(new InputStreamReader(inputStream, CHARSET_UTF_8)); reader.beginObject(); while (reader.hasNext()) { String key = reader.nextName(); switch (key) { case DynamicClientWebAppRegistrationConstants.DYNAMIC_CLIENT_REQUIRED_FLAG: jaggeryOAuthConfigurationSettings.setRequireDynamicClientRegistration(reader.nextBoolean()); break; case DynamicClientWebAppRegistrationUtil.OAUTH_PARAM_GRANT_TYPE: jaggeryOAuthConfigurationSettings.setGrantType(reader.nextString()); break; case DynamicClientWebAppRegistrationUtil.OAUTH_PARAM_TOKEN_SCOPE: jaggeryOAuthConfigurationSettings.setTokenScope(reader.nextString()); break; case DynamicClientWebAppRegistrationUtil.OAUTH_PARAM_SAAS_APP: jaggeryOAuthConfigurationSettings.setSaasApp(reader.nextBoolean()); break; case DynamicClientWebAppRegistrationUtil.OAUTH_PARAM_CALLBACK_URL: jaggeryOAuthConfigurationSettings.setCallbackURL(reader.nextString()); break; case DynamicClientWebAppRegistrationUtil.AUDIENCE: jaggeryOAuthConfigurationSettings.setAudience(reader.nextString()); break; case DynamicClientWebAppRegistrationUtil.ASSERTION_CONSUMER_URL: jaggeryOAuthConfigurationSettings.setAssertionConsumerURL(reader.nextString()); break; case DynamicClientWebAppRegistrationUtil.RECEPIENT_VALIDATION_URL: jaggeryOAuthConfigurationSettings.setRecepientValidationURL(reader.nextString()); break; } } return jaggeryOAuthConfigurationSettings; } } catch (UnsupportedEncodingException e) { log.error("Error occurred while initializing OAuth settings for the Jaggery app.", e); } catch (IOException e) { log.error("Error occurred while initializing OAuth settings for the Jaggery app.", e); } return jaggeryOAuthConfigurationSettings; }
From source file:ru.orangesoftware.financisto2.export.flowzr.FlowzrSyncEngine.java
License:Open Source License
public <T> int readJsnArr(JsonReader reader, String tableName, Class<T> clazz) throws IOException, JSONException, Exception { JSONObject o = new JSONObject(); JsonToken peek = reader.peek();/*from w w w . j a v a2s . c om*/ String n = null; reader.beginArray(); int j = 0; int i = 0; while (reader.hasNext()) { peek = reader.peek(); if (reader.peek() == JsonToken.BEGIN_OBJECT) { reader.beginObject(); } else if (reader.peek() == JsonToken.END_OBJECT) { reader.endObject(); } o = new JSONObject(); while (reader.hasNext()) { peek = reader.peek(); if (peek == JsonToken.NAME) { n = reader.nextName(); } else if (peek == JsonToken.BEGIN_OBJECT) { reader.beginObject(); } else if (peek == JsonToken.END_OBJECT) { reader.endObject(); } else if (peek == JsonToken.BOOLEAN) { try { o.put(n, reader.nextBoolean()); } catch (JSONException e) { e.printStackTrace(); } } else if (peek == JsonToken.STRING) { try { o.put(n, reader.nextString()); } catch (JSONException e) { e.printStackTrace(); } } else if (peek == JsonToken.NUMBER) { try { o.put(n, reader.nextDouble()); } catch (JSONException e) { e.printStackTrace(); } } } reader.endObject(); if (o.has("key")) { i = i + 1; j = j + 1; if (j % 100 == 0) { j = 2; } saveEntityFromJson(o, tableName, clazz, i); if (i % 10 == 0) { flowzrSyncActivity.notifyUser( flowzrSyncActivity.getString(R.string.flowzr_sync_receiving) + " " + tableName + ". " + flowzrSyncActivity.getString(R.string.hint_run_background), (int) (Math.round(j))); } } } reader.endArray(); return i; }
From source file:sf.net.experimaestro.manager.json.JsonConverter.java
License:Open Source License
private Json readNext(JsonReader jsonReader) throws IOException { final JsonToken token = jsonReader.peek(); switch (token) { case BEGIN_ARRAY: { jsonReader.beginArray();/*w ww . ja v a 2 s . c om*/ JsonArray array = new JsonArray(); while (jsonReader.peek() != JsonToken.END_ARRAY) { array.add(readNext(jsonReader)); } jsonReader.endArray(); return array; } case BEGIN_OBJECT: { jsonReader.beginObject(); JsonObject object = new JsonObject(); while (jsonReader.peek() != JsonToken.END_OBJECT) { final String name = jsonReader.nextName(); final Json value = readNext(jsonReader); object.put(name, value); } jsonReader.endObject(); return object; } case BOOLEAN: return new JsonBoolean(jsonReader.nextBoolean()); case STRING: return new JsonString(jsonReader.nextString()); case NULL: { jsonReader.nextNull(); return JsonNull.getSingleton(); } case NUMBER: return new JsonReal(jsonReader.nextDouble()); default: throw new RuntimeException("Cannot handle GSON token type: " + token.name()); } }
From source file:sf.net.experimaestro.utils.gson.JsonAdapter.java
License:Open Source License
private Json readValue(JsonReader in) throws IOException { final JsonToken peek = in.peek(); switch (peek) { case BEGIN_ARRAY: in.beginArray();/*from w ww. jav a 2 s . c om*/ JsonArray array = new JsonArray(); while (in.peek() != JsonToken.END_ARRAY) { array.add(readValue(in)); } in.endArray(); return array; case BEGIN_OBJECT: in.beginObject(); JsonObject object = new JsonObject(); while (in.peek() != JsonToken.END_OBJECT) { final String name = in.nextName(); final Json value = readValue(in); object.put(name, value); } in.endObject(); return object; case BOOLEAN: return new JsonBoolean(in.nextBoolean()); case NUMBER: final double value = in.nextDouble(); if (value == Math.round(value)) return new JsonInteger((long) value); return new JsonReal(value); case STRING: return new JsonString(in.nextString()); case NULL: return JsonNull.getSingleton(); case NAME: case END_OBJECT: case END_ARRAY: case END_DOCUMENT: throw new AssertionError("Not expecting " + peek); } return null; }
From source file:uk.ac.susx.tag.classificationframework.classifiers.NaiveBayesClassifier.java
License:Apache License
public static NaiveBayesClassifier readJson(JsonReader reader, FeatureExtractionPipeline pipeline) throws IOException { NaiveBayesClassifier nb = new NaiveBayesClassifier(); while (reader.hasNext()) { String name = reader.nextName(); switch (name) { // Don't worry; this is okay in Java 7 onwards case "labelSmoothing": nb.labelSmoothing = reader.nextDouble(); break; case "featureSmoothing": nb.featureSmoothing = reader.nextDouble(); break; case "labelMultipliers": nb.labelMultipliers = readJsonInt2DoubleMap(reader, pipeline, false); break; case "labels": nb.labels = readJsonIntSet(reader, pipeline, false); break; case "vocab": nb.vocab = readJsonIntSet(reader, pipeline, true); break; case "docCounts": nb.docCounts = readJsonInt2DoubleMap(reader, pipeline, false); break; case "labelCounts": nb.labelCounts = readJsonInt2DoubleMap(reader, pipeline, false); break; case "jointCounts": nb.jointCounts = readJsonInt2ObjectMap(reader, pipeline); break; case "labelFeatureAlphas": nb.labelFeatureAlphas = readJsonInt2ObjectMap(reader, pipeline); break; case "featureAlphaTotals": nb.featureAlphaTotals = readJsonInt2DoubleMap(reader, pipeline, false); break; case "labelAlphas": nb.labelAlphas = readJsonInt2DoubleMap(reader, pipeline, false); break; case "empiricalLabelPriors": nb.empiricalLabelPriors = reader.nextBoolean(); break; }/*from ww w.j av a 2 s .c o m*/ } return nb; }