List of usage examples for com.google.gson.stream JsonReader hasNext
public boolean hasNext() throws IOException
From source file:org.eclipse.thym.core.plugin.registry.CordovaPluginRegistryManager.java
License:Open Source License
private void readVersionInfo(JsonReader reader, RegistryPluginVersion version) throws IOException { Assert.isNotNull(version);/*from w w w . j a va 2 s . c o m*/ reader.beginObject(); while (reader.hasNext()) { JsonToken token = reader.peek(); switch (token) { case NAME: String name = reader.nextName(); if ("dist".equals(name)) { parseDistDetails(reader, version); break; } break; default: reader.skipValue(); break; } } reader.endObject(); }
From source file:org.eclipse.thym.core.plugin.registry.CordovaPluginRegistryManager.java
License:Open Source License
private void readPluginInfo(JsonReader reader, CordovaRegistryPlugin plugin) throws IOException { Assert.isNotNull(plugin);//from ww w.ja v a 2 s. c o m reader.beginObject(); while (reader.hasNext()) { JsonToken token = reader.peek(); switch (token) { case NAME: { String name = reader.nextName(); if ("name".equals(name)) { plugin.setName(reader.nextString()); break; } if ("description".equals(name)) { plugin.setDescription(reader.nextString()); break; } if ("keywords".equals(name)) { parseKeywords(reader, plugin); break; } if ("maintainers".equals(name)) { parseMaintainers(reader, plugin); break; } if ("dist-tags".equals(name)) { parseLatestVersion(reader, plugin); break; } if ("versions".equals(name)) { parseVersions(reader, plugin); break; } if ("license".equals(name)) { plugin.setLicense(reader.nextString()); break; } break; } default: reader.skipValue(); break; } } reader.endObject(); }
From source file:org.eclipse.thym.core.plugin.registry.CordovaPluginRegistryManager.java
License:Open Source License
private void parseKeywords(JsonReader reader, CordovaRegistryPlugin plugin) throws IOException { reader.beginArray();/*from w w w . j a v a 2 s . c o m*/ while (reader.hasNext()) { plugin.addKeyword(reader.nextString()); } reader.endArray(); }
From source file:org.fao.fenix.wds.core.datasource.DatasourcePool.java
License:Open Source License
/** * @throws FileNotFoundException/*from ww w .j av a 2 s.c om*/ * @throws IOException * * This method is invoked by Spring at the start-up. This function retrieves * all the files stored in the <code>datasourcePath</code> and populate the * <code>datasources</code> map where the key is the datasource name (e.g. 'FAOSTAT') * and the value is the <code>DatasourceBean</code>. */ public void init() throws FileNotFoundException, IOException { Gson g = new Gson(); File root = new File(this.datasourcePath); File[] files = root.listFiles(); for (int i = 0; i < files.length; i++) { InputStream is = new FileInputStream(files[i].getAbsoluteFile()); JsonReader reader = new JsonReader(new InputStreamReader(is, "UTF-8")); reader.beginArray(); while (reader.hasNext()) { DatasourceBean b = readMessage(reader); this.datasources.put(b.getId(), b); } reader.endArray(); } }
From source file:org.fao.fenix.wds.core.datasource.DatasourcePool.java
License:Open Source License
/** * @param reader Google's <code>JsonReader</code> * @return <code>DatasourceBean</code> populated out of the JSON file * @throws IOException//from w w w . ja v a 2s . c o m * * This method reads one of the objects of the JSON array through the * <code>JsonReader</code> and creates a <code>DatasourceBean</code> * out of it. */ public DatasourceBean readMessage(JsonReader reader) throws IOException { DatasourceBean b = new DatasourceBean(); reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if (name.equalsIgnoreCase("driver")) { DRIVER d = DRIVER.valueOf(reader.nextString().toUpperCase()); b.setDriver(d); } else if (name.equalsIgnoreCase("id")) { b.setId(reader.nextString()); } else if (name.equalsIgnoreCase("url")) { b.setUrl(reader.nextString()); } else if (name.equalsIgnoreCase("dbName")) { b.setDbName(reader.nextString()); } else if (name.equalsIgnoreCase("username")) { b.setUsername(reader.nextString()); } else if (name.equalsIgnoreCase("password")) { b.setPassword(reader.nextString()); } else if (name.equalsIgnoreCase("create")) { b.setCreate(reader.nextBoolean()); } else if (name.equalsIgnoreCase("retrieve")) { b.setRetrieve(reader.nextBoolean()); } else if (name.equalsIgnoreCase("update")) { b.setUpdate(reader.nextBoolean()); } else if (name.equalsIgnoreCase("delete")) { b.setDelete(reader.nextBoolean()); } else { reader.skipValue(); } } reader.endObject(); return b; }
From source file:org.gradle.nativeplatform.toolchain.internal.msvcpp.version.CommandLineToolVersionLocator.java
License:Apache License
private List<VisualStudioInstallCandidate> parseJson(String json) { List<VisualStudioInstallCandidate> installs = Lists.newArrayList(); JsonReader reader = new JsonReader(new StringReader(json)); try {/*ww w . ja v a2 s . com*/ try { reader.beginArray(); while (reader.hasNext()) { VisualStudioInstallCandidate candidate = readInstall(reader); if (candidate != null) { installs.add(candidate); } } reader.endArray(); } finally { reader.close(); } } catch (IOException e) { throw UncheckedException.throwAsUncheckedException(e); } return installs; }
From source file:org.gradle.nativeplatform.toolchain.internal.msvcpp.version.CommandLineToolVersionLocator.java
License:Apache License
private VisualStudioInstallCandidate readInstall(JsonReader reader) throws IOException { String visualStudioInstallPath = null; String visualStudioVersion = null; reader.beginObject();/* www . j a v a 2 s . com*/ while (reader.hasNext()) { String key = reader.nextName(); if (key.equals(INSTALLATION_PATH_KEY)) { visualStudioInstallPath = reader.nextString(); } else if (key.equals(INSTALLATION_VERSION_KEY)) { visualStudioVersion = reader.nextString(); } else { reader.skipValue(); } } reader.endObject(); File visualStudioInstallDir = new File(visualStudioInstallPath); VisualCppInstallCandidate visualCppMetadata = findVisualCppMetadata(visualStudioInstallDir, visualStudioVersion); if (visualCppMetadata == null) { LOGGER.debug("Ignoring candidate Visual Studio version " + visualStudioVersion + " at " + visualStudioInstallPath + " because it does not appear to be a valid installation"); return null; } else { return new VisualStudioMetadataBuilder().installDir(visualStudioInstallDir) .visualCppDir(visualCppMetadata.getVisualCppDir()) .version(VersionNumber.parse(visualStudioVersion)) .visualCppVersion(visualCppMetadata.getVersion()).build(); } }
From source file:org.guvnor.ala.openshift.access.OpenShiftRuntimeId.java
License:Apache License
public static OpenShiftRuntimeId fromString(String s) { String project = null;/* www .j ava 2 s . c om*/ String service = null; String application = null; try { JsonReader jr = new JsonReader(new StringReader(s)); jr.beginObject(); while (jr.hasNext()) { String n = jr.nextName(); if (PROJECT.equals(n)) { project = jr.nextString(); } else if (SERVICE.equals(n)) { service = jr.nextString(); } else if (APPLICATION.equals(n)) { application = jr.nextString(); } else { jr.skipValue(); } } jr.endObject(); jr.close(); } catch (IOException ex) { throw new RuntimeException(ex.getMessage(), ex); } return new OpenShiftRuntimeId(project, service, application); }
From source file:org.hibernate.search.backend.elasticsearch.document.model.impl.esnative.ElasticsearchRoutingTypeJsonAdapter.java
License:LGPL
@Override public RoutingType read(JsonReader in) throws IOException { if (in.peek() == JsonToken.NULL) { in.nextNull();//from w w w . j a va 2 s. c om return null; } RoutingType value = null; in.beginObject(); while (in.hasNext()) { String name = in.nextName(); switch (name) { case "required": if (in.nextBoolean()) { value = RoutingType.REQUIRED; } else { value = RoutingType.OPTIONAL; } break; default: throw new AssertionFailure( "Unexpected property for attribute of type " + RoutingType.class + ": " + name); } } return value; }
From source file:org.hibernate.search.backend.elasticsearch.gson.impl.AbstractExtraPropertiesJsonAdapter.java
License:LGPL
@Override public T read(JsonReader in) throws IOException { if (in.peek() == JsonToken.NULL) { in.nextNull();/*w w w .j ava 2s. co m*/ return null; } T instance = createInstance(); try { in.beginObject(); while (in.hasNext()) { String name = in.nextName(); FieldAdapter<? super T> fieldAdapter = fieldAdapters.get(name); if (fieldAdapter == null) { extraPropertyAdapter.readOne(in, name, instance); } else { fieldAdapter.read(in, instance); } } in.endObject(); } catch (IllegalStateException e) { throw new JsonSyntaxException(e); } return instance; }