List of usage examples for com.google.gson.stream JsonReader skipValue
public void skipValue() throws IOException
From source file:org.eclipse.packagedrone.repo.channel.apm.ChannelReader.java
License:Open Source License
private Map<String, String> readAspects(final JsonReader jr) throws IOException { final Map<String, String> result = new HashMap<>(); jr.beginObject();/*from w w w .ja v a 2s . co m*/ while (jr.hasNext()) { switch (jr.nextName()) { case "map": jr.beginObject(); while (jr.hasNext()) { final String id = jr.nextName(); String value = null; if (jr.peek() == JsonToken.STRING) { value = jr.nextString(); } else { jr.skipValue(); } result.put(id, value); } jr.endObject(); break; } } jr.endObject(); return result; }
From source file:org.eclipse.packagedrone.repo.channel.apm.ChannelReader.java
License:Open Source License
private Map<String, ArtifactInformation> readArtifacts(final JsonReader jr) throws IOException { jr.beginObject();/*w w w. j a v a2 s .c om*/ final Map<String, ArtifactInformation> result = new HashMap<>(); while (jr.hasNext()) { final String id = jr.nextName(); jr.beginObject(); String name = null; Long size = null; Instant creationTimestamp = null; String parentId = null; Set<String> childIds = Collections.emptySet(); Set<String> facets = Collections.emptySet(); String virtualizerAspectId = null; List<ValidationMessage> validationMessages = Collections.emptyList(); Map<MetaKey, String> extractedMetaData = Collections.emptyMap(); Map<MetaKey, String> providedMetaData = Collections.emptyMap(); while (jr.hasNext()) { final String ele = jr.nextName(); switch (ele) { case "name": name = jr.nextString(); break; case "size": size = jr.nextLong(); break; case "date": creationTimestamp = readTime(jr); break; case "parentId": parentId = jr.nextString(); break; case "childIds": childIds = readSet(jr); break; case "facets": facets = readSet(jr); break; case "virtualizerAspectId": virtualizerAspectId = jr.nextString(); break; case "extractedMetaData": extractedMetaData = readMetadata(jr); break; case "providedMetaData": providedMetaData = readMetadata(jr); break; case "validationMessages": validationMessages = readValidationMessages(jr); break; default: jr.skipValue(); break; } } jr.endObject(); if (id == null || name == null || size == null || creationTimestamp == null) { throw new IOException("Missing values for artifact"); } this.numberOfBytes += size; result.put(id, new ArtifactInformation(id, parentId, childIds, name, size, creationTimestamp, facets, validationMessages, providedMetaData, extractedMetaData, virtualizerAspectId)); } jr.endObject(); return result; }
From source file:org.eclipse.packagedrone.repo.channel.apm.ChannelReader.java
License:Open Source License
private Map<MetaKey, String> readMetadata(final JsonReader jr) throws IOException { final Map<MetaKey, String> result = new HashMap<>(); jr.beginObject();//from w w w. ja v a2 s. c om while (jr.hasNext()) { final String name = jr.nextName(); if (jr.peek() == JsonToken.NULL) { jr.skipValue(); } else { final String value = jr.nextString(); result.put(MetaKey.fromString(name), value); } } jr.endObject(); return result; }
From source file:org.eclipse.packagedrone.repo.channel.apm.ChannelReader.java
License:Open Source License
private Map<MetaKey, CacheEntryInformation> readCacheEntries(final JsonReader jr) throws IOException { final Map<MetaKey, CacheEntryInformation> result = new HashMap<>(); jr.beginObject();/*from ww w. j ava 2s .c o m*/ while (jr.hasNext()) { final String entryName = jr.nextName(); jr.beginObject(); String name = null; Long size = null; String mimeType = null; Instant timestamp = null; while (jr.hasNext()) { final String ele = jr.nextName(); switch (ele) { case "name": name = jr.nextString(); break; case "size": size = jr.nextLong(); break; case "mimeType": mimeType = jr.nextString(); break; case "timestamp": timestamp = readTime(jr); break; default: jr.skipValue(); break; } } if (name == null || size == null || mimeType == null || timestamp == null) { throw new IOException("Invalid format"); } jr.endObject(); final MetaKey key = MetaKey.fromString(entryName); result.put(key, new CacheEntryInformation(key, name, size, mimeType, timestamp)); } jr.endObject(); return result; }
From source file:org.eclipse.thym.core.plugin.registry.CordovaPluginRegistryManager.java
License:Open Source License
public List<CordovaRegistryPluginInfo> retrievePluginInfos(IProgressMonitor monitor) throws CoreException { if (monitor == null) monitor = new NullProgressMonitor(); monitor.beginTask("Retrieve plug-in registry catalog", 10); DefaultHttpClient theHttpClient = new DefaultHttpClient(); HttpUtil.setupProxy(theHttpClient);//from w w w. j a v a2 s .c om HttpClient client = new CachingHttpClient(theHttpClient, new HeapResourceFactory(), new BundleHttpCacheStorage(HybridCore.getContext().getBundle()), getCacheConfig()); JsonReader reader = null; try { if (monitor.isCanceled()) { return null; } String url = REGISTRY_URL + "-/_view/byKeyword?startkey=%5B%22ecosystem:cordova%22%5D&endkey=%5B%22ecosystem:cordova1%22%5D&group_level=3"; HttpGet get = new HttpGet(URI.create(url)); HttpResponse response = client.execute(get); HttpEntity entity = response.getEntity(); InputStream stream = entity.getContent(); monitor.worked(7); reader = new JsonReader(new InputStreamReader(stream)); reader.beginObject();//start the Registry final ArrayList<CordovaRegistryPluginInfo> plugins = new ArrayList<CordovaRegistryPluginInfo>(); while (reader.hasNext()) { JsonToken token = reader.peek(); switch (token) { case BEGIN_ARRAY: reader.beginArray(); break; case BEGIN_OBJECT: plugins.add(parseCordovaRegistryPluginInfo(reader)); break; default: reader.skipValue(); break; } } return plugins; } catch (ClientProtocolException e) { throw new CoreException( new Status(IStatus.ERROR, HybridCore.PLUGIN_ID, "Can not retrieve plugin catalog", e)); } catch (IOException e) { throw new CoreException( new Status(IStatus.ERROR, HybridCore.PLUGIN_ID, "Can not retrieve plugin catalog", e)); } finally { if (reader != null) try { reader.close(); } catch (IOException e) { /*ignored*/ } monitor.done(); } }
From source file:org.eclipse.thym.core.plugin.registry.CordovaPluginRegistryManager.java
License:Open Source License
private CordovaRegistryPluginInfo parseCordovaRegistryPluginInfo(JsonReader reader) throws IOException { CordovaRegistryPluginInfo info = new CordovaRegistryPluginInfo(); reader.beginObject();// w w w. j a va 2 s. c om reader.skipValue(); // name reader.beginArray(); reader.nextString(); //ecosystem:cordova info.setName(safeReadStringValue(reader)); info.setDescription(safeReadStringValue(reader)); reader.endArray(); reader.nextName(); reader.nextInt(); reader.endObject(); return info; }
From source file:org.eclipse.thym.core.plugin.registry.CordovaPluginRegistryManager.java
License:Open Source License
private String safeReadStringValue(JsonReader reader) throws IOException { if (reader.peek() == JsonToken.STRING) { return reader.nextString(); }// w ww . ja v a2 s. co m reader.skipValue(); return ""; }
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.ja v a2s. co 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 w w w . j a v a 2 s .co 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 parseDistDetails(JsonReader reader, RegistryPluginVersion plugin) throws IOException { reader.beginObject();// ww w. j a va2s . c o m JsonToken token = reader.peek(); while (token != JsonToken.END_OBJECT) { switch (token) { case NAME: String name = reader.nextName(); if ("shasum".equals(name)) { plugin.setShasum(reader.nextString()); break; } if ("tarball".equals(name)) { plugin.setTarball(reader.nextString()); break; } break; default: reader.skipValue(); break; } token = reader.peek(); } reader.endObject(); }