List of usage examples for com.google.gson.stream JsonReader hasNext
public boolean hasNext() throws IOException
From source file:org.imperiumstudios.Imperium1871Bungee.BukkitWarpHelper.files.JsonFile.java
License:Open Source License
/** * Read the config File into RAM.// www. j a va 2s . c om */ public void readFile() { try { JsonReader reader = new JsonReader(new FileReader(jsonFile)); reader.beginObject(); while (reader.hasNext()) jsonFileContent.put(reader.nextName(), reader.nextString()); reader.endObject(); reader.close(); } catch (IOException ex) { IMP.log.error("JsonFile.java > readFile() > Unable to read " + jsonFile + ". Disabling this plugin .."); IMP.log.error("JsonFile.java > readFile() > Error: " + ex.getMessage()); IMP.disable(); } }
From source file:org.jboss.tools.aerogear.hybrid.core.plugin.registry.CordovaPluginRegistryManager.java
License:Open Source License
public List<CordovaRegistryPluginInfo> retrievePluginInfos(IProgressMonitor monitor) throws CoreException { if (monitor == null) monitor = new NullProgressMonitor(); HttpClient client = new DefaultHttpClient(); String url = registry.endsWith("/") ? registry + "-/all" : registry + "/-/all"; HttpGet get = new HttpGet(url); HttpResponse response;/* ww w .j a va 2s . c om*/ try { if (monitor.isCanceled()) { return null; } response = client.execute(get); HttpEntity entity = response.getEntity(); InputStream stream = entity.getContent(); monitor.worked(9); JsonReader reader = new JsonReader(new InputStreamReader(stream)); reader.beginObject();//start the Registry plugins = new ArrayList<CordovaRegistryPluginInfo>(); while (reader.hasNext()) { JsonToken token = reader.peek(); switch (token) { case BEGIN_OBJECT: CordovaRegistryPluginInfo info = new CordovaRegistryPluginInfo(); readPluginInfo(reader, info); plugins.add(info); break; case NAME: String name = reader.nextName(); if (name.equals("_updated")) { long newUpdate = reader.nextLong(); if (newUpdate == this.updated) {//No changes return plugins; } } break; default: Assert.isTrue(false, "Unexpected token: " + token); break; } } reader.endObject(); 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 { monitor.done(); } }
From source file:org.jboss.tools.aerogear.hybrid.core.plugin.registry.CordovaPluginRegistryManager.java
License:Open Source License
private void readPluginInfo(JsonReader reader, CordovaRegistryPluginInfo plugin) throws IOException { Assert.isNotNull(plugin);/*from www .ja va 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) && plugin instanceof CordovaRegistryPlugin) { parseDetailedVersions(reader, (CordovaRegistryPlugin) plugin); break; } if ("dist".equals(name) && plugin instanceof CordovaRegistryPluginVersion) { parseDistDetails(reader, (CordovaRegistryPluginVersion) plugin); break; } if ("license".equals(name) && plugin instanceof CordovaRegistryPluginVersion) { CordovaRegistryPluginVersion v = (CordovaRegistryPluginVersion) plugin; v.setLicense(reader.nextString()); break; } break; } default: reader.skipValue(); break; } } reader.endObject(); }
From source file:org.jboss.tools.aerogear.hybrid.core.plugin.registry.CordovaPluginRegistryManager.java
License:Open Source License
private void parseKeywords(JsonReader reader, CordovaRegistryPluginInfo plugin) throws IOException { reader.beginArray();//w ww .j av a 2 s .c o m while (reader.hasNext()) { plugin.addKeyword(reader.nextString()); } reader.endArray(); }
From source file:org.jclouds.json.internal.IgnoreNullFluentIterableTypeAdapterFactory.java
License:Apache License
protected <E> TypeAdapter<FluentIterable<E>> newFluentIterableAdapter(final TypeAdapter<E> elementAdapter) { return new TypeAdapter<FluentIterable<E>>() { public void write(JsonWriter out, FluentIterable<E> value) throws IOException { out.beginArray();//from www . ja v a 2s. c o m for (E element : value) { elementAdapter.write(out, element); } out.endArray(); } public FluentIterable<E> read(JsonReader in) throws IOException { in.beginArray(); Builder<E> builder = ImmutableList.<E>builder(); while (in.hasNext()) { E element = elementAdapter.read(in); if (element != null) builder.add(element); } in.endArray(); return FluentIterable.from(builder.build()); } }.nullSafe(); }
From source file:org.jclouds.json.internal.IgnoreNullIterableTypeAdapterFactory.java
License:Apache License
protected <E> TypeAdapter<Iterable<E>> newIterableAdapter(final TypeAdapter<E> elementAdapter) { return new TypeAdapter<Iterable<E>>() { public void write(JsonWriter out, Iterable<E> value) throws IOException { out.beginArray();//from w w w . j a va2 s .c o m for (E element : value) { elementAdapter.write(out, element); } out.endArray(); } public Iterable<E> read(JsonReader in) throws IOException { in.beginArray(); Builder<E> builder = ImmutableList.<E>builder(); while (in.hasNext()) { E element = elementAdapter.read(in); if (element != null) builder.add(element); } in.endArray(); return builder.build(); } }.nullSafe(); }
From source file:org.jclouds.json.internal.IgnoreNullMapTypeAdapterFactory.java
License:Apache License
private <K, V> TypeAdapter<Map<K, V>> newMapAdapter(final TypeAdapter<K> keyAdapter, final TypeAdapter<V> valueAdapter) { return new TypeAdapter<Map<K, V>>() { public void write(JsonWriter out, Map<K, V> value) throws IOException { out.beginObject();/*from ww w. ja v a 2 s . com*/ for (Map.Entry<K, V> element : value.entrySet()) { out.name(String.valueOf(element.getKey())); valueAdapter.write(out, element.getValue()); } out.endObject(); } public Map<K, V> read(JsonReader in) throws IOException { Map<K, V> result = Maps.newLinkedHashMap(); in.beginObject(); while (in.hasNext()) { JsonReaderInternalAccess.INSTANCE.promoteNameToValue(in); K name = keyAdapter.read(in); V value = valueAdapter.read(in); if (value != null) result.put(name, value); } in.endObject(); return result; } }.nullSafe(); }
From source file:org.jclouds.json.internal.IgnoreNullMultimapTypeAdapterFactory.java
License:Apache License
private <K, V> TypeAdapter<Multimap<K, V>> newMapAdapter(final TypeAdapter<K> keyAdapter, final TypeAdapter<V> valueAdapter) { return new TypeAdapter<Multimap<K, V>>() { public void write(JsonWriter out, Multimap<K, V> map) throws IOException { out.beginObject();/* w ww . j av a 2 s .c o m*/ for (K key : map.keySet()) { out.name(String.valueOf(key)); out.beginArray(); for (V value : map.get(key)) { valueAdapter.write(out, value); } out.endArray(); } out.endObject(); } public Multimap<K, V> read(JsonReader in) throws IOException { ImmutableMultimap.Builder<K, V> result = ImmutableListMultimap.builder(); in.beginObject(); while (in.hasNext()) { JsonReaderInternalAccess.INSTANCE.promoteNameToValue(in); K name = keyAdapter.read(in); in.beginArray(); while (in.hasNext()) { V value = valueAdapter.read(in); if (value != null) result.put(name, value); } in.endArray(); } in.endObject(); return result.build(); } }.nullSafe(); }
From source file:org.jclouds.json.internal.IgnoreNullSetTypeAdapterFactory.java
License:Apache License
private <E> TypeAdapter<Set<E>> newSetAdapter(final TypeAdapter<E> elementAdapter) { return new TypeAdapter<Set<E>>() { public void write(JsonWriter out, Set<E> value) throws IOException { out.beginArray();//from ww w.j a v a 2s . c o m for (E element : value) { elementAdapter.write(out, element); } out.endArray(); } public Set<E> read(JsonReader in) throws IOException { Set<E> result = Sets.newLinkedHashSet(); in.beginArray(); while (in.hasNext()) { E element = elementAdapter.read(in); if (element != null) result.add(element); } in.endArray(); return result; } }.nullSafe(); }
From source file:org.jclouds.oauth.v2.json.ClaimSetTypeAdapter.java
License:Apache License
@Override public ClaimSet read(JsonReader in) throws IOException { ClaimSet.Builder builder = new ClaimSet.Builder(); in.beginObject();// ww w. j a v a2 s .c om while (in.hasNext()) { String claimName = in.nextName(); String claimValue = in.nextString(); builder.addClaim(claimName, claimValue); } in.endObject(); return builder.build(); }