Example usage for com.google.gson.stream JsonReader nextInt

List of usage examples for com.google.gson.stream JsonReader nextInt

Introduction

In this page you can find the example usage for com.google.gson.stream JsonReader nextInt.

Prototype

public int nextInt() throws IOException 

Source Link

Document

Returns the com.google.gson.stream.JsonToken#NUMBER int value of the next token, consuming it.

Usage

From source file:org.gw2InfoViewer.services.json.typeadaptors.EventAdapter.java

License:Open Source License

@Override
public Event read(JsonReader reader) throws IOException {
    if (reader.peek() == JsonToken.NULL) {
        reader.nextNull();/* www. j  a v  a2  s . co m*/
        return null;
    }

    Event event = new Event();

    reader.beginObject();
    reader.nextName(); //world id
    event.setWorldId(reader.nextInt());
    reader.nextName(); //map id
    event.setMapId(reader.nextInt());
    reader.nextName(); //event id
    event.setEventId(reader.nextString());
    reader.nextName();
    event.setState(EventState.valueOf(reader.nextString())); //state
    reader.endObject();

    return event;
}

From source file:org.komodo.rest.relational.json.QueryAttributeSerializer.java

License:Open Source License

/**
 * {@inheritDoc}//  w ww . jav a2 s .  c  o  m
 *
 * @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
 */
@Override
public KomodoQueryAttribute read(final JsonReader in) throws IOException {
    final KomodoQueryAttribute queryAttr = new KomodoQueryAttribute();
    in.beginObject();

    while (in.hasNext()) {
        final String name = in.nextName();
        switch (name) {
        case KomodoQueryAttribute.QUERY_LABEL:
            queryAttr.setQuery(in.nextString());
            break;
        case KomodoQueryAttribute.TARGET_LABEL:
            queryAttr.setTarget(in.nextString());
            break;
        case KomodoQueryAttribute.LIMIT_LABEL:
            queryAttr.setLimit(in.nextInt());
            break;
        case KomodoQueryAttribute.OFFSET_LABEL:
            queryAttr.setOffset(in.nextInt());
            break;
        }
    }

    in.endObject();

    return queryAttr;
}

From source file:org.komodo.rest.relational.json.TeiidAttributesSerializer.java

License:Open Source License

/**
 * {@inheritDoc}/*w  w w.j  av a 2  s  .co  m*/
 *
 * @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
 */
@Override
public KomodoTeiidAttributes read(final JsonReader in) throws IOException {
    final KomodoTeiidAttributes teiidAttrs = new KomodoTeiidAttributes();
    in.beginObject();

    while (in.hasNext()) {
        final String name = in.nextName();

        switch (name) {
        case KomodoTeiidAttributes.ADMIN_USER_LABEL:
            teiidAttrs.setAdminUser(in.nextString());
            break;
        case KomodoTeiidAttributes.ADMIN_PASSWD_LABEL:
            teiidAttrs.setAdminPasswd(in.nextString());
            break;
        case KomodoTeiidAttributes.ADMIN_PORT_LABEL:
            teiidAttrs.setAdminPort(in.nextInt());
            break;
        case KomodoTeiidAttributes.ADMIN_SECURE_LABEL:
            teiidAttrs.setAdminSecure(in.nextBoolean());
            break;
        case KomodoTeiidAttributes.JDBC_USER_LABEL:
            teiidAttrs.setJdbcUser(in.nextString());
            break;
        case KomodoTeiidAttributes.JDBC_PASSWD_LABEL:
            teiidAttrs.setJdbcPasswd(in.nextString());
            break;
        case KomodoTeiidAttributes.JDBC_PORT_LABEL:
            teiidAttrs.setJdbcPort(in.nextInt());
            break;
        case KomodoTeiidAttributes.JDBC_SECURE_LABEL:
            teiidAttrs.setJdbcSecure(in.nextBoolean());
            break;
        default:
            throw new IOException(Messages.getString(UNEXPECTED_JSON_TOKEN, name));
        }
    }

    in.endObject();

    return teiidAttrs;
}

From source file:org.komodo.rest.relational.json.TeiidVdbStatusSerializer.java

License:Open Source License

/**
 * {@inheritDoc}/*from   ww  w . ja v  a2 s  .c  o m*/
 *
 * @see org.komodo.rest.relational.json.AbstractEntitySerializer#read(com.google.gson.stream.JsonReader)
 */
@Override
public RestTeiidVdbStatus read(final JsonReader in) throws IOException {
    final RestTeiidVdbStatus entity = createEntity();

    beginRead(in);

    while (in.hasNext()) {
        final String name = in.nextName();

        if (RestTeiidVdbStatus.VDBS_LABEL.equals(name)) {
            final RestTeiidVdbStatusVdb[] vdbStatuses = BUILDER.fromJson(in, RestTeiidVdbStatusVdb[].class);
            entity.setVdbProperties(Arrays.asList(vdbStatuses));
        } else if (LINKS.equals(name))
            readLinks(in, entity);
        else {
            JsonToken token = in.peek();
            switch (token) {
            case BOOLEAN:
                entity.addTuple(name, in.nextBoolean());
                break;
            case NUMBER:
                entity.addTuple(name, in.nextInt());
                break;
            case STRING:
                entity.addTuple(name, in.nextString());
                break;
            case NULL:
                in.nextNull();
                entity.addTuple(name, null);
                break;
            case BEGIN_ARRAY:
                final String[] value = BUILDER.fromJson(in, String[].class);
                entity.addTuple(name, value);
                break;
            default:
                throw new IOException(Messages.getString(Messages.Error.UNEXPECTED_JSON_TOKEN, name));
            }
        }
    }

    if (!isComplete(entity)) {
        throw new IOException(Messages.getString(INCOMPLETE_JSON, getClass().getSimpleName()));
    }

    endRead(in);
    return entity;
}

From source file:org.mitre.openid.connect.service.impl.MITREidDataService_1_0.java

License:Apache License

/**
 * @param reader//from www  . j  a v a2 s  . co m
 * @throws IOException
 */
private void readClients(JsonReader reader) throws IOException {
    reader.beginArray();
    while (reader.hasNext()) {
        ClientDetailsEntity client = new ClientDetailsEntity();
        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("clientId")) {
                    client.setClientId(reader.nextString());
                } else if (name.equals("resourceIds")) {
                    Set<String> resourceIds = readSet(reader);
                    client.setResourceIds(resourceIds);
                } else if (name.equals("secret")) {
                    client.setClientSecret(reader.nextString());
                } else if (name.equals("scope")) {
                    Set<String> scope = readSet(reader);
                    client.setScope(scope);
                } else if (name.equals("authorities")) {
                    Set<String> authorityStrs = readSet(reader);
                    Set<GrantedAuthority> authorities = new HashSet<>();
                    for (String s : authorityStrs) {
                        GrantedAuthority ga = new SimpleGrantedAuthority(s);
                        authorities.add(ga);
                    }
                    client.setAuthorities(authorities);
                } else if (name.equals("accessTokenValiditySeconds")) {
                    client.setAccessTokenValiditySeconds(reader.nextInt());
                } else if (name.equals("refreshTokenValiditySeconds")) {
                    client.setRefreshTokenValiditySeconds(reader.nextInt());
                } else if (name.equals("redirectUris")) {
                    Set<String> redirectUris = readSet(reader);
                    client.setRedirectUris(redirectUris);
                } else if (name.equals("name")) {
                    client.setClientName(reader.nextString());
                } else if (name.equals("uri")) {
                    client.setClientUri(reader.nextString());
                } else if (name.equals("logoUri")) {
                    client.setLogoUri(reader.nextString());
                } else if (name.equals("contacts")) {
                    Set<String> contacts = readSet(reader);
                    client.setContacts(contacts);
                } else if (name.equals("tosUri")) {
                    client.setTosUri(reader.nextString());
                } else if (name.equals("tokenEndpointAuthMethod")) {
                    AuthMethod am = AuthMethod.getByValue(reader.nextString());
                    client.setTokenEndpointAuthMethod(am);
                } else if (name.equals("grantTypes")) {
                    Set<String> grantTypes = readSet(reader);
                    client.setGrantTypes(grantTypes);
                } else if (name.equals("responseTypes")) {
                    Set<String> responseTypes = readSet(reader);
                    client.setResponseTypes(responseTypes);
                } else if (name.equals("policyUri")) {
                    client.setPolicyUri(reader.nextString());
                } else if (name.equals("applicationType")) {
                    AppType appType = AppType.getByValue(reader.nextString());
                    client.setApplicationType(appType);
                } else if (name.equals("sectorIdentifierUri")) {
                    client.setSectorIdentifierUri(reader.nextString());
                } else if (name.equals("subjectType")) {
                    SubjectType st = SubjectType.getByValue(reader.nextString());
                    client.setSubjectType(st);
                } else if (name.equals("jwks_uri")) {
                    client.setJwksUri(reader.nextString());
                } else if (name.equals("requestObjectSigningAlg")) {
                    JWSAlgorithm alg = JWSAlgorithm.parse(reader.nextString());
                    client.setRequestObjectSigningAlg(alg);
                } else if (name.equals("userInfoEncryptedResponseAlg")) {
                    JWEAlgorithm alg = JWEAlgorithm.parse(reader.nextString());
                    client.setUserInfoEncryptedResponseAlg(alg);
                } else if (name.equals("userInfoEncryptedResponseEnc")) {
                    EncryptionMethod alg = EncryptionMethod.parse(reader.nextString());
                    client.setUserInfoEncryptedResponseEnc(alg);
                } else if (name.equals("userInfoSignedResponseAlg")) {
                    JWSAlgorithm alg = JWSAlgorithm.parse(reader.nextString());
                    client.setUserInfoSignedResponseAlg(alg);
                } else if (name.equals("idTokenSignedResonseAlg")) {
                    JWSAlgorithm alg = JWSAlgorithm.parse(reader.nextString());
                    client.setIdTokenSignedResponseAlg(alg);
                } else if (name.equals("idTokenEncryptedResponseAlg")) {
                    JWEAlgorithm alg = JWEAlgorithm.parse(reader.nextString());
                    client.setIdTokenEncryptedResponseAlg(alg);
                } else if (name.equals("idTokenEncryptedResponseEnc")) {
                    EncryptionMethod alg = EncryptionMethod.parse(reader.nextString());
                    client.setIdTokenEncryptedResponseEnc(alg);
                } else if (name.equals("tokenEndpointAuthSigningAlg")) {
                    JWSAlgorithm alg = JWSAlgorithm.parse(reader.nextString());
                    client.setTokenEndpointAuthSigningAlg(alg);
                } else if (name.equals("defaultMaxAge")) {
                    client.setDefaultMaxAge(reader.nextInt());
                } else if (name.equals("requireAuthTime")) {
                    client.setRequireAuthTime(reader.nextBoolean());
                } else if (name.equals("defaultACRValues")) {
                    Set<String> defaultACRvalues = readSet(reader);
                    client.setDefaultACRvalues(defaultACRvalues);
                } else if (name.equals("initiateLoginUri")) {
                    client.setInitiateLoginUri(reader.nextString());
                } else if (name.equals("postLogoutRedirectUri")) {
                    HashSet<String> postLogoutUris = Sets.newHashSet(reader.nextString());
                    client.setPostLogoutRedirectUris(postLogoutUris);
                } else if (name.equals("requestUris")) {
                    Set<String> requestUris = readSet(reader);
                    client.setRequestUris(requestUris);
                } else if (name.equals("description")) {
                    client.setClientDescription(reader.nextString());
                } else if (name.equals("allowIntrospection")) {
                    client.setAllowIntrospection(reader.nextBoolean());
                } else if (name.equals("reuseRefreshToken")) {
                    client.setReuseRefreshToken(reader.nextBoolean());
                } else if (name.equals("dynamicallyRegistered")) {
                    client.setDynamicallyRegistered(reader.nextBoolean());
                } else {
                    logger.debug("Found unexpected entry");
                    reader.skipValue();
                }
                break;
            default:
                logger.debug("Found unexpected entry");
                reader.skipValue();
                continue;
            }
        }
        reader.endObject();
        clientRepository.saveClient(client);
    }
    reader.endArray();
    logger.info("Done reading clients");
}

From source file:org.mitre.openid.connect.service.impl.MITREidDataService_1_2.java

License:Apache License

/**
 * @param reader/*from  w  w  w  .j a  v  a 2s  .co  m*/
 * @throws IOException
 */
private void readClients(JsonReader reader) throws IOException {
    reader.beginArray();
    while (reader.hasNext()) {
        ClientDetailsEntity client = new ClientDetailsEntity();
        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(CLIENT_ID)) {
                    client.setClientId(reader.nextString());
                } else if (name.equals(RESOURCE_IDS)) {
                    Set<String> resourceIds = readSet(reader);
                    client.setResourceIds(resourceIds);
                } else if (name.equals(SECRET)) {
                    client.setClientSecret(reader.nextString());
                } else if (name.equals(SCOPE)) {
                    Set<String> scope = readSet(reader);
                    client.setScope(scope);
                } else if (name.equals(AUTHORITIES)) {
                    Set<String> authorityStrs = readSet(reader);
                    Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();
                    for (String s : authorityStrs) {
                        GrantedAuthority ga = new SimpleGrantedAuthority(s);
                        authorities.add(ga);
                    }
                    client.setAuthorities(authorities);
                } else if (name.equals(ACCESS_TOKEN_VALIDITY_SECONDS)) {
                    client.setAccessTokenValiditySeconds(reader.nextInt());
                } else if (name.equals(REFRESH_TOKEN_VALIDITY_SECONDS)) {
                    client.setRefreshTokenValiditySeconds(reader.nextInt());
                } else if (name.equals(REDIRECT_URIS)) {
                    Set<String> redirectUris = readSet(reader);
                    client.setRedirectUris(redirectUris);
                } else if (name.equals(CLAIMS_REDIRECT_URIS)) {
                    Set<String> claimsRedirectUris = readSet(reader);
                    client.setClaimsRedirectUris(claimsRedirectUris);
                } else if (name.equals(NAME)) {
                    client.setClientName(reader.nextString());
                } else if (name.equals(URI)) {
                    client.setClientUri(reader.nextString());
                } else if (name.equals(LOGO_URI)) {
                    client.setLogoUri(reader.nextString());
                } else if (name.equals(CONTACTS)) {
                    Set<String> contacts = readSet(reader);
                    client.setContacts(contacts);
                } else if (name.equals(TOS_URI)) {
                    client.setTosUri(reader.nextString());
                } else if (name.equals(TOKEN_ENDPOINT_AUTH_METHOD)) {
                    AuthMethod am = AuthMethod.getByValue(reader.nextString());
                    client.setTokenEndpointAuthMethod(am);
                } else if (name.equals(GRANT_TYPES)) {
                    Set<String> grantTypes = readSet(reader);
                    client.setGrantTypes(grantTypes);
                } else if (name.equals(RESPONSE_TYPES)) {
                    Set<String> responseTypes = readSet(reader);
                    client.setResponseTypes(responseTypes);
                } else if (name.equals(POLICY_URI)) {
                    client.setPolicyUri(reader.nextString());
                } else if (name.equals(APPLICATION_TYPE)) {
                    AppType appType = AppType.getByValue(reader.nextString());
                    client.setApplicationType(appType);
                } else if (name.equals(SECTOR_IDENTIFIER_URI)) {
                    client.setSectorIdentifierUri(reader.nextString());
                } else if (name.equals(SUBJECT_TYPE)) {
                    SubjectType st = SubjectType.getByValue(reader.nextString());
                    client.setSubjectType(st);
                } else if (name.equals(JWKS_URI)) {
                    client.setJwksUri(reader.nextString());
                } else if (name.equals(JWKS)) {
                    try {
                        client.setJwks(JWKSet.parse(reader.nextString()));
                    } catch (ParseException e) {
                        logger.error("Couldn't parse JWK Set", e);
                    }
                } else if (name.equals(REQUEST_OBJECT_SIGNING_ALG)) {
                    JWSAlgorithm alg = JWSAlgorithm.parse(reader.nextString());
                    client.setRequestObjectSigningAlg(alg);
                } else if (name.equals(USER_INFO_ENCRYPTED_RESPONSE_ALG)) {
                    JWEAlgorithm alg = JWEAlgorithm.parse(reader.nextString());
                    client.setUserInfoEncryptedResponseAlg(alg);
                } else if (name.equals(USER_INFO_ENCRYPTED_RESPONSE_ENC)) {
                    EncryptionMethod alg = EncryptionMethod.parse(reader.nextString());
                    client.setUserInfoEncryptedResponseEnc(alg);
                } else if (name.equals(USER_INFO_SIGNED_RESPONSE_ALG)) {
                    JWSAlgorithm alg = JWSAlgorithm.parse(reader.nextString());
                    client.setUserInfoSignedResponseAlg(alg);
                } else if (name.equals(ID_TOKEN_SIGNED_RESPONSE_ALG)) {
                    JWSAlgorithm alg = JWSAlgorithm.parse(reader.nextString());
                    client.setIdTokenSignedResponseAlg(alg);
                } else if (name.equals(ID_TOKEN_ENCRYPTED_RESPONSE_ALG)) {
                    JWEAlgorithm alg = JWEAlgorithm.parse(reader.nextString());
                    client.setIdTokenEncryptedResponseAlg(alg);
                } else if (name.equals(ID_TOKEN_ENCRYPTED_RESPONSE_ENC)) {
                    EncryptionMethod alg = EncryptionMethod.parse(reader.nextString());
                    client.setIdTokenEncryptedResponseEnc(alg);
                } else if (name.equals(TOKEN_ENDPOINT_AUTH_SIGNING_ALG)) {
                    JWSAlgorithm alg = JWSAlgorithm.parse(reader.nextString());
                    client.setTokenEndpointAuthSigningAlg(alg);
                } else if (name.equals(DEFAULT_MAX_AGE)) {
                    client.setDefaultMaxAge(reader.nextInt());
                } else if (name.equals(REQUIRE_AUTH_TIME)) {
                    client.setRequireAuthTime(reader.nextBoolean());
                } else if (name.equals(DEFAULT_ACR_VALUES)) {
                    Set<String> defaultACRvalues = readSet(reader);
                    client.setDefaultACRvalues(defaultACRvalues);
                } else if (name.equals("initiateLoginUri")) {
                    client.setInitiateLoginUri(reader.nextString());
                } else if (name.equals(POST_LOGOUT_REDIRECT_URI)) {
                    Set<String> postLogoutUris = readSet(reader);
                    client.setPostLogoutRedirectUris(postLogoutUris);
                } else if (name.equals(REQUEST_URIS)) {
                    Set<String> requestUris = readSet(reader);
                    client.setRequestUris(requestUris);
                } else if (name.equals(DESCRIPTION)) {
                    client.setClientDescription(reader.nextString());
                } else if (name.equals(ALLOW_INTROSPECTION)) {
                    client.setAllowIntrospection(reader.nextBoolean());
                } else if (name.equals(REUSE_REFRESH_TOKEN)) {
                    client.setReuseRefreshToken(reader.nextBoolean());
                } else if (name.equals(CLEAR_ACCESS_TOKENS_ON_REFRESH)) {
                    client.setClearAccessTokensOnRefresh(reader.nextBoolean());
                } else if (name.equals(DYNAMICALLY_REGISTERED)) {
                    client.setDynamicallyRegistered(reader.nextBoolean());
                } else {
                    logger.debug("Found unexpected entry");
                    reader.skipValue();
                }
                break;
            default:
                logger.debug("Found unexpected entry");
                reader.skipValue();
                continue;
            }
        }
        reader.endObject();
        clientRepository.saveClient(client);
    }
    reader.endArray();
    logger.info("Done reading clients");
}

From source file:org.mitre.openid.connect.service.impl.MITREidDataService_1_3.java

License:Apache License

/**
 * @param reader/*from  w  w w .  j  a v a 2 s  .  c om*/
 * @throws IOException
 */
private void readClients(JsonReader reader) throws IOException {
    reader.beginArray();
    while (reader.hasNext()) {
        ClientDetailsEntity client = new ClientDetailsEntity();
        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(CLIENT_ID)) {
                    client.setClientId(reader.nextString());
                } else if (name.equals(RESOURCE_IDS)) {
                    Set<String> resourceIds = readSet(reader);
                    client.setResourceIds(resourceIds);
                } else if (name.equals(SECRET)) {
                    client.setClientSecret(reader.nextString());
                } else if (name.equals(SCOPE)) {
                    Set<String> scope = readSet(reader);
                    client.setScope(scope);
                } else if (name.equals(AUTHORITIES)) {
                    Set<String> authorityStrs = readSet(reader);
                    Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();
                    for (String s : authorityStrs) {
                        GrantedAuthority ga = new SimpleGrantedAuthority(s);
                        authorities.add(ga);
                    }
                    client.setAuthorities(authorities);
                } else if (name.equals(ACCESS_TOKEN_VALIDITY_SECONDS)) {
                    client.setAccessTokenValiditySeconds(reader.nextInt());
                } else if (name.equals(REFRESH_TOKEN_VALIDITY_SECONDS)) {
                    client.setRefreshTokenValiditySeconds(reader.nextInt());
                } else if (name.equals(ID_TOKEN_VALIDITY_SECONDS)) {
                    client.setIdTokenValiditySeconds(reader.nextInt());
                } else if (name.equals(DEVICE_CODE_VALIDITY_SECONDS)) {
                    client.setDeviceCodeValiditySeconds(reader.nextInt());
                } else if (name.equals(REDIRECT_URIS)) {
                    Set<String> redirectUris = readSet(reader);
                    client.setRedirectUris(redirectUris);
                } else if (name.equals(CLAIMS_REDIRECT_URIS)) {
                    Set<String> claimsRedirectUris = readSet(reader);
                    client.setClaimsRedirectUris(claimsRedirectUris);
                } else if (name.equals(NAME)) {
                    client.setClientName(reader.nextString());
                } else if (name.equals(URI)) {
                    client.setClientUri(reader.nextString());
                } else if (name.equals(LOGO_URI)) {
                    client.setLogoUri(reader.nextString());
                } else if (name.equals(CONTACTS)) {
                    Set<String> contacts = readSet(reader);
                    client.setContacts(contacts);
                } else if (name.equals(TOS_URI)) {
                    client.setTosUri(reader.nextString());
                } else if (name.equals(TOKEN_ENDPOINT_AUTH_METHOD)) {
                    AuthMethod am = AuthMethod.getByValue(reader.nextString());
                    client.setTokenEndpointAuthMethod(am);
                } else if (name.equals(GRANT_TYPES)) {
                    Set<String> grantTypes = readSet(reader);
                    client.setGrantTypes(grantTypes);
                } else if (name.equals(RESPONSE_TYPES)) {
                    Set<String> responseTypes = readSet(reader);
                    client.setResponseTypes(responseTypes);
                } else if (name.equals(POLICY_URI)) {
                    client.setPolicyUri(reader.nextString());
                } else if (name.equals(APPLICATION_TYPE)) {
                    AppType appType = AppType.getByValue(reader.nextString());
                    client.setApplicationType(appType);
                } else if (name.equals(SECTOR_IDENTIFIER_URI)) {
                    client.setSectorIdentifierUri(reader.nextString());
                } else if (name.equals(SUBJECT_TYPE)) {
                    SubjectType st = SubjectType.getByValue(reader.nextString());
                    client.setSubjectType(st);
                } else if (name.equals(JWKS_URI)) {
                    client.setJwksUri(reader.nextString());
                } else if (name.equals(JWKS)) {
                    try {
                        client.setJwks(JWKSet.parse(reader.nextString()));
                    } catch (ParseException e) {
                        logger.error("Couldn't parse JWK Set", e);
                    }
                } else if (name.equals(REQUEST_OBJECT_SIGNING_ALG)) {
                    JWSAlgorithm alg = JWSAlgorithm.parse(reader.nextString());
                    client.setRequestObjectSigningAlg(alg);
                } else if (name.equals(USER_INFO_ENCRYPTED_RESPONSE_ALG)) {
                    JWEAlgorithm alg = JWEAlgorithm.parse(reader.nextString());
                    client.setUserInfoEncryptedResponseAlg(alg);
                } else if (name.equals(USER_INFO_ENCRYPTED_RESPONSE_ENC)) {
                    EncryptionMethod alg = EncryptionMethod.parse(reader.nextString());
                    client.setUserInfoEncryptedResponseEnc(alg);
                } else if (name.equals(USER_INFO_SIGNED_RESPONSE_ALG)) {
                    JWSAlgorithm alg = JWSAlgorithm.parse(reader.nextString());
                    client.setUserInfoSignedResponseAlg(alg);
                } else if (name.equals(ID_TOKEN_SIGNED_RESPONSE_ALG)) {
                    JWSAlgorithm alg = JWSAlgorithm.parse(reader.nextString());
                    client.setIdTokenSignedResponseAlg(alg);
                } else if (name.equals(ID_TOKEN_ENCRYPTED_RESPONSE_ALG)) {
                    JWEAlgorithm alg = JWEAlgorithm.parse(reader.nextString());
                    client.setIdTokenEncryptedResponseAlg(alg);
                } else if (name.equals(ID_TOKEN_ENCRYPTED_RESPONSE_ENC)) {
                    EncryptionMethod alg = EncryptionMethod.parse(reader.nextString());
                    client.setIdTokenEncryptedResponseEnc(alg);
                } else if (name.equals(TOKEN_ENDPOINT_AUTH_SIGNING_ALG)) {
                    JWSAlgorithm alg = JWSAlgorithm.parse(reader.nextString());
                    client.setTokenEndpointAuthSigningAlg(alg);
                } else if (name.equals(DEFAULT_MAX_AGE)) {
                    client.setDefaultMaxAge(reader.nextInt());
                } else if (name.equals(REQUIRE_AUTH_TIME)) {
                    client.setRequireAuthTime(reader.nextBoolean());
                } else if (name.equals(DEFAULT_ACR_VALUES)) {
                    Set<String> defaultACRvalues = readSet(reader);
                    client.setDefaultACRvalues(defaultACRvalues);
                } else if (name.equals("initiateLoginUri")) {
                    client.setInitiateLoginUri(reader.nextString());
                } else if (name.equals(POST_LOGOUT_REDIRECT_URI)) {
                    Set<String> postLogoutUris = readSet(reader);
                    client.setPostLogoutRedirectUris(postLogoutUris);
                } else if (name.equals(REQUEST_URIS)) {
                    Set<String> requestUris = readSet(reader);
                    client.setRequestUris(requestUris);
                } else if (name.equals(DESCRIPTION)) {
                    client.setClientDescription(reader.nextString());
                } else if (name.equals(ALLOW_INTROSPECTION)) {
                    client.setAllowIntrospection(reader.nextBoolean());
                } else if (name.equals(REUSE_REFRESH_TOKEN)) {
                    client.setReuseRefreshToken(reader.nextBoolean());
                } else if (name.equals(CLEAR_ACCESS_TOKENS_ON_REFRESH)) {
                    client.setClearAccessTokensOnRefresh(reader.nextBoolean());
                } else if (name.equals(DYNAMICALLY_REGISTERED)) {
                    client.setDynamicallyRegistered(reader.nextBoolean());
                } else if (name.equals(CODE_CHALLENGE_METHOD)) {
                    client.setCodeChallengeMethod(PKCEAlgorithm.parse(reader.nextString()));
                } else if (name.equals(SOFTWARE_ID)) {
                    client.setSoftwareId(reader.nextString());
                } else if (name.equals(SOFTWARE_VERSION)) {
                    client.setSoftwareVersion(reader.nextString());
                } else if (name.equals(SOFTWARE_STATEMENT)) {
                    try {
                        client.setSoftwareStatement(JWTParser.parse(reader.nextString()));
                    } catch (ParseException e) {
                        logger.error("Couldn't parse software statement", e);
                    }
                } else if (name.equals(CREATION_DATE)) {
                    Date date = utcToDate(reader.nextString());
                    client.setCreatedAt(date);
                } else {
                    logger.debug("Found unexpected entry");
                    reader.skipValue();
                }
                break;
            default:
                logger.debug("Found unexpected entry");
                reader.skipValue();
                continue;
            }
        }
        reader.endObject();
        clientRepository.saveClient(client);
    }
    reader.endArray();
    logger.info("Done reading clients");
}

From source file:org.mythdroid.services.GuideService.java

License:Open Source License

/**
 * Get ProgramGuide data//from ww  w.java 2  s  .  com
 * @param start Date for start of data
 * @param end Date for end of data
 * @return ArrayList of Channels
 */
public ArrayList<Channel> GetProgramGuide(Date start, Date end) throws IOException {

    final Params params = new Params();
    params.put("StartTime", Globals.utcFormat(start)); //$NON-NLS-1$
    params.put("EndTime", Globals.utcFormat(end)); //$NON-NLS-1$
    params.put("StartChanId", 0); //$NON-NLS-1$
    params.put("NumChannels", -1); //$NON-NLS-1$
    params.put("Details", "true"); //$NON-NLS-1$ //$NON-NLS-2$

    InputStream is = jc.GetStream("GetProgramGuide", params); //$NON-NLS-1$
    JsonReader jreader = new JsonReader(new BufferedReader(new InputStreamReader(is, "UTF-8")) //$NON-NLS-1$
    );

    ArrayList<Channel> channels = new ArrayList<Channel>();

    jreader.beginObject();
    skipTo(jreader, JsonToken.BEGIN_OBJECT);
    jreader.beginObject();
    skipTo(jreader, JsonToken.NAME);
    while (jreader.hasNext()) {
        String name = jreader.nextName();
        if (name.equals("NumOfChannels")) { //$NON-NLS-1$
            channels.ensureCapacity(jreader.nextInt());
            break;
        }
        jreader.skipValue();
    }
    skipTo(jreader, JsonToken.BEGIN_ARRAY);
    jreader.beginArray();
    while (jreader.hasNext()) {
        jreader.beginObject();
        channels.add((Channel) gson.fromJson(jreader, Channel.class));
        jreader.endObject();
    }
    jreader.endArray();
    jreader.endObject();
    jreader.endObject();
    jreader.close();
    jc.endStream();

    return channels;

}

From source file:org.openstreetmap.josm.plugins.openstreetcam.service.photo.adapter.ReaderUtil.java

License:LGPL

static Integer readInt(final JsonReader reader) throws IOException {
    Integer value = null;//from   w w w  . j a  v a 2 s  .co  m
    if (reader.peek() == JsonToken.NULL) {
        reader.nextNull();
    } else {
        value = reader.nextInt();
    }
    return value;
}

From source file:org.openstreetmap.josm.plugins.openstreetcam.service.PhotoTypeAdapter.java

License:Apache License

private Integer readInt(final JsonReader reader) throws IOException {
    Integer value = null;//w w  w  .j av a  2s . c om
    if (reader.peek() == JsonToken.NULL) {
        reader.nextNull();
    } else {
        value = reader.nextInt();
    }
    return value;
}