List of usage examples for com.google.gson.stream JsonReader nextLong
public long nextLong() throws IOException
From source file:org.eclipse.packagedrone.repo.channel.apm.ChannelReader.java
License:Open Source License
private Instant readTime(final JsonReader jr) throws IOException { final JsonToken peek = jr.peek(); if (peek == JsonToken.NUMBER) { return Instant.ofEpochMilli(jr.nextLong()); } else if (peek == JsonToken.NULL) { jr.nextNull();//from ww w.j a va 2 s. co m return null; } else if (peek == JsonToken.STRING) { final String str = jr.nextString(); try { return Instant.ofEpochMilli(Long.parseLong(str)); } catch (final NumberFormatException e) { try { return this.dateFormat.parse(str).toInstant(); } catch (final ParseException e2) { throw new IOException(e2); } } } else { throw new IOException(String.format("Invalid timestamp token: %s", peek)); } }
From source file:org.eclipse.tm4e.core.internal.parser.json.JSONPListParser.java
License:Open Source License
public T parse(InputStream contents) throws Exception { PList<T> pList = new PList<T>(theme); JsonReader reader = new JsonReader(new InputStreamReader(contents, StandardCharsets.UTF_8)); // reader.setLenient(true); boolean parsing = true; while (parsing) { JsonToken nextToken = reader.peek(); switch (nextToken) { case BEGIN_ARRAY: pList.startElement(null, "array", null, null); reader.beginArray();// ww w . ja va2 s.com break; case END_ARRAY: pList.endElement(null, "array", null); reader.endArray(); break; case BEGIN_OBJECT: pList.startElement(null, "dict", null, null); reader.beginObject(); break; case END_OBJECT: pList.endElement(null, "dict", null); reader.endObject(); break; case NAME: String lastName = reader.nextName(); pList.startElement(null, "key", null, null); pList.characters(lastName.toCharArray(), 0, lastName.length()); pList.endElement(null, "key", null); break; case NULL: reader.nextNull(); break; case BOOLEAN: reader.nextBoolean(); break; case NUMBER: reader.nextLong(); break; case STRING: String value = reader.nextString(); pList.startElement(null, "string", null, null); pList.characters(value.toCharArray(), 0, value.length()); pList.endElement(null, "string", null); break; case END_DOCUMENT: parsing = false; break; default: break; } } reader.close(); return pList.getResult(); }
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 . ja v a 2 s . co m*/ 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.komodo.rest.relational.json.ImportExportStatusSerializer.java
License:Open Source License
/** * {@inheritDoc}/*from ww w . j av a 2 s . co m*/ * * @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader) */ @Override public ImportExportStatus read(final JsonReader in) throws IOException { final ImportExportStatus status = new ImportExportStatus(); in.beginObject(); while (in.hasNext()) { final String name = in.nextName(); switch (name) { case ImportExportStatus.NAME_LABEL: status.setName(in.nextString()); break; case ImportExportStatus.TYPE_LABEL: status.setType(in.nextString()); break; case ImportExportStatus.SUCCESS_LABEL: status.setSuccess(in.nextBoolean()); break; case ImportExportStatus.DOWNLOADABLE_LABEL: status.setDownloadable(in.nextBoolean()); break; case ImportExportStatus.CONTENT_LABEL: status.setContent(in.nextString()); break; case ImportExportStatus.MESSAGE_LABEL: status.setMessage(in.nextString()); break; case ImportExportStatus.DOWNLOADABLE_SIZE_LABEL: status.setDownloadableSize(in.nextLong()); break; default: throw new IOException(Messages.getString(UNEXPECTED_JSON_TOKEN, name)); } } in.endObject(); return status; }
From source file:org.mitre.openid.connect.service.impl.AbstractMITREidDataService.java
License:Apache License
protected static Set readSet(JsonReader reader) throws IOException { Set arraySet = null;/*from w w w .ja v a 2s.c o m*/ reader.beginArray(); switch (reader.peek()) { case STRING: arraySet = new HashSet<String>(); while (reader.hasNext()) { arraySet.add(reader.nextString()); } break; case NUMBER: arraySet = new HashSet<Long>(); while (reader.hasNext()) { arraySet.add(reader.nextLong()); } break; default: arraySet = new HashSet(); break; } reader.endArray(); return arraySet; }
From source file:org.mitre.openid.connect.service.impl.AbstractMITREidDataService.java
License:Apache License
protected static Map readMap(JsonReader reader) throws IOException { Map map = new HashMap<String, Object>(); reader.beginObject();/*from w w w . j a v a 2 s . c o m*/ while (reader.hasNext()) { String name = reader.nextName(); Object value = null; switch (reader.peek()) { case STRING: value = reader.nextString(); break; case BOOLEAN: value = reader.nextBoolean(); break; case NUMBER: value = reader.nextLong(); break; } map.put(name, value); } reader.endObject(); return map; }
From source file:org.mitre.openid.connect.service.impl.MITREidDataService_1_0.java
License:Apache License
/** * @param reader//from w ww.j a v a2 s .co m * @throws IOException */ private void readRefreshTokens(JsonReader reader) throws IOException { reader.beginArray(); while (reader.hasNext()) { OAuth2RefreshTokenEntity token = new OAuth2RefreshTokenEntity(); reader.beginObject(); Long currentId = null; String clientId = null; Long authHolderId = null; while (reader.hasNext()) { switch (reader.peek()) { case END_OBJECT: continue; case NAME: String name = reader.nextName(); if (reader.peek() == JsonToken.NULL) { reader.skipValue(); } else if (name.equals("id")) { currentId = reader.nextLong(); } else if (name.equals("expiration")) { Date date = utcToDate(reader.nextString()); token.setExpiration(date); } else if (name.equals("value")) { String value = reader.nextString(); try { token.setJwt(JWTParser.parse(value)); } catch (ParseException ex) { logger.error("Unable to set refresh token value to {}", value, ex); } } else if (name.equals("clientId")) { clientId = reader.nextString(); } else if (name.equals("authenticationHolderId")) { authHolderId = reader.nextLong(); } else { logger.debug("Found unexpected entry"); reader.skipValue(); } break; default: logger.debug("Found unexpected entry"); reader.skipValue(); continue; } } reader.endObject(); Long newId = tokenRepository.saveRefreshToken(token).getId(); maps.getRefreshTokenToClientRefs().put(currentId, clientId); maps.getRefreshTokenToAuthHolderRefs().put(currentId, authHolderId); maps.getRefreshTokenOldToNewIdMap().put(currentId, newId); logger.debug("Read refresh token {}", currentId); } reader.endArray(); logger.info("Done reading refresh tokens"); }
From source file:org.mitre.openid.connect.service.impl.MITREidDataService_1_0.java
License:Apache License
/** * @param reader//from w ww. java 2s .c om * @throws IOException */ private void readAccessTokens(JsonReader reader) throws IOException { reader.beginArray(); while (reader.hasNext()) { OAuth2AccessTokenEntity token = new OAuth2AccessTokenEntity(); reader.beginObject(); Long currentId = null; String clientId = null; Long authHolderId = null; Long refreshTokenId = null; while (reader.hasNext()) { switch (reader.peek()) { case END_OBJECT: continue; case NAME: String name = reader.nextName(); if (reader.peek() == JsonToken.NULL) { reader.skipValue(); } else if (name.equals("id")) { currentId = reader.nextLong(); } else if (name.equals("expiration")) { Date date = utcToDate(reader.nextString()); token.setExpiration(date); } else if (name.equals("value")) { String value = reader.nextString(); try { // all tokens are JWTs token.setJwt(JWTParser.parse(value)); } catch (ParseException ex) { logger.error("Unable to set refresh token value to {}", value, ex); } } else if (name.equals("clientId")) { clientId = reader.nextString(); } else if (name.equals("authenticationHolderId")) { authHolderId = reader.nextLong(); } else if (name.equals("refreshTokenId")) { refreshTokenId = reader.nextLong(); } else if (name.equals("scope")) { Set<String> scope = readSet(reader); token.setScope(scope); } else if (name.equals("type")) { token.setTokenType(reader.nextString()); } else { logger.debug("Found unexpected entry"); reader.skipValue(); } break; default: logger.debug("Found unexpected entry"); reader.skipValue(); continue; } } reader.endObject(); Long newId = tokenRepository.saveAccessToken(token).getId(); maps.getAccessTokenToClientRefs().put(currentId, clientId); maps.getAccessTokenToAuthHolderRefs().put(currentId, authHolderId); if (refreshTokenId != null) { maps.getAccessTokenToRefreshTokenRefs().put(currentId, refreshTokenId); } maps.getAccessTokenOldToNewIdMap().put(currentId, newId); logger.debug("Read access token {}", currentId); } reader.endArray(); logger.info("Done reading access tokens"); }
From source file:org.mitre.openid.connect.service.impl.MITREidDataService_1_0.java
License:Apache License
/** * @param reader/*from ww w . ja v a 2 s. co m*/ * @throws IOException */ private void readAuthenticationHolders(JsonReader reader) throws IOException { reader.beginArray(); while (reader.hasNext()) { AuthenticationHolderEntity ahe = new AuthenticationHolderEntity(); reader.beginObject(); Long currentId = null; while (reader.hasNext()) { switch (reader.peek()) { case END_OBJECT: continue; case NAME: String name = reader.nextName(); if (reader.peek() == JsonToken.NULL) { reader.skipValue(); } else if (name.equals("id")) { currentId = reader.nextLong(); } else if (name.equals("ownerId")) { //not needed reader.skipValue(); } else if (name.equals("authentication")) { OAuth2Request clientAuthorization = null; Authentication userAuthentication = null; reader.beginObject(); while (reader.hasNext()) { switch (reader.peek()) { case END_OBJECT: continue; case NAME: String subName = reader.nextName(); if (reader.peek() == JsonToken.NULL) { reader.skipValue(); } else if (subName.equals("clientAuthorization")) { clientAuthorization = readAuthorizationRequest(reader); } else if (subName.equals("userAuthentication")) { // skip binary encoded version reader.skipValue(); } else if (subName.equals("savedUserAuthentication")) { userAuthentication = readSavedUserAuthentication(reader); } else { logger.debug("Found unexpected entry"); reader.skipValue(); } break; default: logger.debug("Found unexpected entry"); reader.skipValue(); continue; } } reader.endObject(); OAuth2Authentication auth = new OAuth2Authentication(clientAuthorization, userAuthentication); ahe.setAuthentication(auth); } else { logger.debug("Found unexpected entry"); reader.skipValue(); } break; default: logger.debug("Found unexpected entry"); reader.skipValue(); continue; } } reader.endObject(); Long newId = authHolderRepository.save(ahe).getId(); maps.getAuthHolderOldToNewIdMap().put(currentId, newId); logger.debug("Read authentication holder {}", currentId); } reader.endArray(); logger.info("Done reading authentication holders"); }
From source file:org.mitre.openid.connect.service.impl.MITREidDataService_1_0.java
License:Apache License
/** * @param reader//from w w w . j a v a 2 s .c o m * @throws IOException */ private void readGrants(JsonReader reader) throws IOException { reader.beginArray(); while (reader.hasNext()) { ApprovedSite site = new ApprovedSite(); Long currentId = null; Long whitelistedSiteId = null; Set<Long> tokenIds = null; reader.beginObject(); while (reader.hasNext()) { switch (reader.peek()) { case END_OBJECT: continue; case NAME: String name = reader.nextName(); if (reader.peek() == JsonToken.NULL) { reader.skipValue(); } else if (name.equals("id")) { currentId = reader.nextLong(); } else if (name.equals("accessDate")) { Date date = utcToDate(reader.nextString()); site.setAccessDate(date); } else if (name.equals("clientId")) { site.setClientId(reader.nextString()); } else if (name.equals("creationDate")) { Date date = utcToDate(reader.nextString()); site.setCreationDate(date); } else if (name.equals("timeoutDate")) { Date date = utcToDate(reader.nextString()); site.setTimeoutDate(date); } else if (name.equals("userId")) { site.setUserId(reader.nextString()); } else if (name.equals("allowedScopes")) { Set<String> allowedScopes = readSet(reader); site.setAllowedScopes(allowedScopes); } else if (name.equals("whitelistedSiteId")) { whitelistedSiteId = reader.nextLong(); } else if (name.equals("approvedAccessTokens")) { tokenIds = readSet(reader); } else { logger.debug("Found unexpected entry"); reader.skipValue(); } break; default: logger.debug("Found unexpected entry"); reader.skipValue(); continue; } } reader.endObject(); Long newId = approvedSiteRepository.save(site).getId(); maps.getGrantOldToNewIdMap().put(currentId, newId); if (whitelistedSiteId != null) { logger.debug("Ignoring whitelisted site marker on approved site."); } if (tokenIds != null) { maps.getGrantToAccessTokensRefs().put(currentId, tokenIds); } logger.debug("Read grant {}", currentId); } reader.endArray(); logger.info("Done reading grants"); }