List of usage examples for com.google.gson.stream JsonReader hasNext
public boolean hasNext() throws IOException
From source file:org.project.openbaton.nubomedia.paas.model.openshift.EnvironmentVariableSerializer.java
License:Apache License
@Override public EnvironmentVariable read(JsonReader in) throws IOException { EnvironmentVariable env = new EnvironmentVariable(); in.beginObject();//from w w w . j a v a 2 s.c o m while (in.hasNext()) { if (in.nextName().equals("name")) { env.setName(in.nextString()); } if (in.nextName().equals("value")) { env.setValue(in.nextString()); } } in.endObject(); return env; }
From source file:org.project.openbaton.nubomedia.paas.model.openshift.MetadataTypeAdapter.java
License:Apache License
@Override public Metadata read(JsonReader in) throws IOException { String name = "", selfLink = "", resourceVersion = "", namespace = ""; in.beginObject();/*w w w. ja va 2s. c om*/ while (in.hasNext()) { String nameObj = in.nextName(); switch (nameObj) { case "name": name = in.nextString(); break; case "selfLink": selfLink = in.nextString(); break; case "resourceVersion": resourceVersion = in.nextString(); break; case "namespace": namespace = in.nextString(); break; default: in.skipValue(); break; } } in.endObject(); return new Metadata(name, selfLink, resourceVersion, namespace); }
From source file:org.project.openbaton.nubomedia.paas.model.openshift.OutputTypeAdapter.java
License:Apache License
@Override public Output read(JsonReader in) throws IOException { BuildElements be = null;//w w w .ja v a 2 s . c o m SecretID secId = null; in.beginObject(); while (in.hasNext()) { if (in.nextName().equals("to")) { be = readBuildElement(in); } if (in.nextName().equals("pushSecret")) secId = this.readSecID(in); } in.endObject(); return new Output(be, secId); }
From source file:org.project.openbaton.nubomedia.paas.model.openshift.OutputTypeAdapter.java
License:Apache License
private SecretID readSecID(JsonReader in) throws IOException { SecretID res = new SecretID(); in.beginObject();/* w w w. ja v a2 s .co m*/ while (in.hasNext()) { if (in.nextName().equals("name")) res.setName(in.nextString()); } in.endObject(); return res; }
From source file:org.project.openbaton.nubomedia.paas.model.openshift.OutputTypeAdapter.java
License:Apache License
private BuildElements readBuildElement(JsonReader in) throws IOException { BuildElements be = new BuildElements(); in.beginObject();//from w w w . j a v a 2 s . c om while (in.hasNext()) { if (in.nextName().equals("kind")) be.setKind(in.nextString()); if (in.nextName().equals("name")) be.setName(in.nextString()); } in.endObject(); return be; }
From source file:org.sensorhub.impl.security.gxoauth.OAuthAuthenticator.java
License:Mozilla Public License
private String parseUserInfoJson(JsonReader reader) throws IOException { String userId = null;//from w ww. j a v a 2s. c o m reader.beginObject(); while (reader.hasNext()) { String name = reader.nextName(); if ("id".equals(name) || "user_id".equals(name) || "uid".equals(name)) userId = reader.nextString(); else reader.skipValue(); } reader.endObject(); return userId; }
From source file:org.sonar.server.computation.AnalysisReportService.java
License:Open Source License
@VisibleForTesting void saveIssues(ComputeEngineContext context) { IssueStorage issueStorage = issueStorageFactory.newComputeEngineIssueStorage(context.getProject()); File issuesFile = new File(context.getReportDirectory(), "issues.json"); List<DefaultIssue> issues = new ArrayList<>(MAX_ISSUES_SIZE); try {//from w w w .j a v a2 s .c om InputStream issuesStream = new FileInputStream(issuesFile); JsonReader reader = new JsonReader(new InputStreamReader(issuesStream)); reader.beginArray(); while (reader.hasNext()) { ReportIssue reportIssue = gson.fromJson(reader, ReportIssue.class); DefaultIssue defaultIssue = toIssue(context, reportIssue); issues.add(defaultIssue); if (shouldPersistIssues(issues, reader)) { issueStorage.save(issues); issues.clear(); } } reader.endArray(); reader.close(); } catch (IOException e) { throw new IllegalStateException("Failed to read issues", e); } }
From source file:org.sonar.server.computation.AnalysisReportService.java
License:Open Source License
private boolean shouldPersistIssues(List<DefaultIssue> issues, JsonReader reader) throws IOException { return issues.size() == MAX_ISSUES_SIZE || !reader.hasNext(); }
From source file:org.sonarsource.sonarlint.core.container.connected.update.SettingsDownloader.java
License:Open Source License
private static void parseProperty(BiPredicate<String, String> filter, BiConsumer<String, String> consumer, JsonReader reader) throws IOException { String key = null;//from w w w .j a v a2 s.c om String value = null; while (reader.hasNext()) { String propName = reader.nextName(); switch (propName) { case "key": key = reader.nextString(); break; case "value": value = reader.nextString(); break; default: reader.skipValue(); } } // Storage optimisation: don't store properties having same value than global properties if (filter.test(key, value)) { consumer.accept(key, value); } }
From source file:org.spongepowered.plugin.meta.gson.ModMetadataAdapter.java
License:MIT License
@Override public PluginMetadata read(JsonReader in) throws IOException { in.beginObject();//from w ww.j a v a 2s. c om final Set<String> processedKeys = new HashSet<>(); final PluginMetadata result = new PluginMetadata("unknown"); String id = null; while (in.hasNext()) { final String name = in.nextName(); if (!processedKeys.add(name)) { throw new JsonParseException("Duplicate key '" + name + "' in " + in); } switch (name) { case "modid": id = in.nextString(); result.setId(id); break; case "name": result.setName(in.nextString()); break; case "version": result.setVersion(in.nextString()); break; case "description": result.setDescription(in.nextString()); break; case "url": result.setUrl(in.nextString()); break; case "authorList": in.beginArray(); while (in.hasNext()) { result.addAuthor(in.nextString()); } in.endArray(); break; case "requiredMods": in.beginArray(); while (in.hasNext()) { result.addRequiredDependency(ModDependencyAdapter.INSTANCE.read(in)); } in.endArray(); break; case "dependencies": in.beginArray(); while (in.hasNext()) { result.loadAfter(ModDependencyAdapter.INSTANCE.read(in)); } in.endArray(); break; case "dependants": in.beginArray(); while (in.hasNext()) { result.loadBefore(ModDependencyAdapter.INSTANCE.read(in)); } in.endArray(); break; default: result.setExtension(name, this.gson.fromJson(in, getExtension(name))); } } in.endObject(); if (id == null) { throw new JsonParseException("Mod metadata is missing required element 'modid'"); } return result; }