Example usage for com.google.common.base VerifyException VerifyException

List of usage examples for com.google.common.base VerifyException VerifyException

Introduction

In this page you can find the example usage for com.google.common.base VerifyException VerifyException.

Prototype

public VerifyException(@Nullable Throwable cause) 

Source Link

Document

Constructs a VerifyException with the cause cause and a message that is null if cause is null, and cause.toString() otherwise.

Usage

From source file:org.opendaylight.yangtools.triemap.CNode.java

static VerifyException invalidElement(final BasicNode elem) {
    throw new VerifyException("A CNode can contain only CNodes and SNodes, not " + elem);
}

From source file:google.registry.keyring.api.PgpHelper.java

/**
 * Search for public key on keyring based on a substring (like an email address).
 *
 * @throws VerifyException if the key couldn't be found.
 * @see #lookupKeyPair//from  w  w w  .j a v  a  2s.c  o  m
 */
public static PGPPublicKey lookupPublicKey(PGPPublicKeyRingCollection keyring, String query,
        KeyRequirement want) {
    try {
        // Safe by specification.
        @SuppressWarnings("unchecked")
        Iterator<PGPPublicKeyRing> results = keyring.getKeyRings(checkNotNull(query, "query"), true, true);
        verify(results.hasNext(), "No public key found matching substring: %s", query);
        while (results.hasNext()) {
            Optional<PGPPublicKey> result = lookupPublicSubkey(results.next(), want);
            if (result.isPresent()) {
                return result.get();
            }
        }
        throw new VerifyException(
                String.format("No public key (%s) found matching substring: %s", want, query));
    } catch (PGPException e) {
        throw new VerifyException(
                String.format("Public key lookup with query %s failed: %s", query, e.getMessage()));
    }
}

From source file:com.facebook.buck.versions.VersionUniverseVersionSelector.java

@VisibleForTesting
protected Optional<Map.Entry<String, VersionUniverse>> getVersionUniverse(TargetNode<?, ?> root) {
    Optional<String> universeName = getVersionUniverseName(root);
    if (!universeName.isPresent() && !universes.isEmpty()) {
        return Optional.of(Iterables.get(universes.entrySet(), 0));
    }//from  w w  w  .j a v a  2  s .co  m
    if (!universeName.isPresent()) {
        return Optional.empty();
    }
    VersionUniverse universe = universes.get(universeName.get());
    if (universe == null) {
        throw new VerifyException(String.format("%s: unknown version universe \"%s\"", root.getBuildTarget(),
                universeName.get()));
    }
    return Optional.of(new AbstractMap.SimpleEntry<>(universeName.get(), universe));
}

From source file:io.prestosql.plugin.jdbc.JdbcRecordCursor.java

public JdbcRecordCursor(JdbcClient jdbcClient, ConnectorSession session, JdbcSplit split,
        List<JdbcColumnHandle> columnHandles) {
    this.jdbcClient = requireNonNull(jdbcClient, "jdbcClient is null");

    this.columnHandles = columnHandles.toArray(new JdbcColumnHandle[0]);

    booleanReadFunctions = new BooleanReadFunction[columnHandles.size()];
    doubleReadFunctions = new DoubleReadFunction[columnHandles.size()];
    longReadFunctions = new LongReadFunction[columnHandles.size()];
    sliceReadFunctions = new SliceReadFunction[columnHandles.size()];

    for (int i = 0; i < this.columnHandles.length; i++) {
        ColumnMapping columnMapping = jdbcClient.toPrestoType(session, columnHandles.get(i).getJdbcTypeHandle())
                .orElseThrow(() -> new VerifyException("Unsupported column type"));
        Class<?> javaType = columnMapping.getType().getJavaType();
        ReadFunction readFunction = columnMapping.getReadFunction();

        if (javaType == boolean.class) {
            booleanReadFunctions[i] = (BooleanReadFunction) readFunction;
        } else if (javaType == double.class) {
            doubleReadFunctions[i] = (DoubleReadFunction) readFunction;
        } else if (javaType == long.class) {
            longReadFunctions[i] = (LongReadFunction) readFunction;
        } else if (javaType == Slice.class) {
            sliceReadFunctions[i] = (SliceReadFunction) readFunction;
        } else {//w w w.ja  v a  2s.  c o m
            throw new IllegalStateException(format("Unsupported java type %s", javaType));
        }
    }

    try {
        connection = jdbcClient.getConnection(split);
        statement = jdbcClient.buildSql(session, connection, split, columnHandles);
        log.debug("Executing: %s", statement.toString());
        resultSet = statement.executeQuery();
    } catch (SQLException | RuntimeException e) {
        throw handleSqlException(e);
    }
}

From source file:com.iblsoft.iwxxm.webservice.validator.XmlCatalogResolver.java

@Override
public String resolveIdentifier(XMLResourceIdentifier xmlResourceIdentifier) throws IOException, XNIException {
    if (xmlResourceIdentifier == null || !(xmlResourceIdentifier instanceof XSDDescription)
            || xmlResourceIdentifier.getNamespace() == null) {
        return super.resolveIdentifier(xmlResourceIdentifier);
    }/* ww  w  . j  a v a 2  s .  com*/
    XSDDescription desc = (XSDDescription) xmlResourceIdentifier;
    String id = super.resolveIdentifier(xmlResourceIdentifier);

    String expandedSystemId = id;
    if (expandedSystemId == null) {
        expandedSystemId = xmlResourceIdentifier.getExpandedSystemId();
    }

    Verify.verifyNotNull(expandedSystemId,
            "Identifier %s is not resolved, check if xsi:schemaLocation and xmlns:xsi attributes are correctly defined.",
            desc.getNamespace());
    if (!expandedSystemId.startsWith("file:")) {
        Log.INSTANCE.warn("Identifier {} is not resolved to local path (resolved to {})",
                desc.getTargetNamespace(), expandedSystemId);
        if (!allowRemoteResources) {
            throw new VerifyException(String.format(
                    "Identifier %s is not resolved to local path (resolved to %s). Only resources stored in local catalog are enbaled.",
                    desc.getNamespace(), expandedSystemId));
        }
    }

    if (Log.INSTANCE.isDebugEnabled()) {
        Log.INSTANCE.debug("Resolved identifier: namespace: {} publicId={] systemId={} to {}",
                xmlResourceIdentifier.getNamespace(), desc.getPublicId(), desc.getLiteralSystemId(),
                expandedSystemId);
    }
    return id;
}

From source file:google.registry.tools.ListObjectsCommand.java

@Override
public void run() throws Exception {
    ImmutableMap.Builder<String, Object> params = new ImmutableMap.Builder<>();
    if (fields != null) {
        params.put(FIELDS_PARAM, fields);
    }// ww  w.j  a va2 s  .  c  om
    if (printHeaderRow != null) {
        params.put(PRINT_HEADER_ROW_PARAM, printHeaderRow);
    }
    if (fullFieldNames) {
        params.put(FULL_FIELD_NAMES_PARAM, Boolean.TRUE);
    }
    ImmutableMap<String, Object> extraParams = getParameterMap();
    if (extraParams != null) {
        params.putAll(extraParams);
    }
    // Call the server and get the response data.
    String response = connection.send(getCommandPath(), params.build(), MediaType.PLAIN_TEXT_UTF_8,
            new byte[0]);
    // Parse the returned JSON and make sure it's a map.
    Object obj = JSONValue.parse(response.substring(JSON_SAFETY_PREFIX.length()));
    if (!(obj instanceof Map<?, ?>)) {
        throw new VerifyException("Server returned unexpected JSON: " + response);
    }
    @SuppressWarnings("unchecked")
    Map<String, Object> responseMap = (Map<String, Object>) obj;
    // Get the status.
    obj = responseMap.get("status");
    if (obj == null) {
        throw new VerifyException("Server returned no status");
    }
    if (!(obj instanceof String)) {
        throw new VerifyException("Server returned non-string status");
    }
    String status = (String) obj;
    // Handle errors.
    if (status.equals("error")) {
        obj = responseMap.get("error");
        if (obj == null) {
            throw new VerifyException("Server returned no error message");
        }
        System.out.println(obj);
        // Handle success.
    } else if (status.equals("success")) {
        obj = responseMap.get("lines");
        if (obj == null) {
            throw new VerifyException("Server returned no response data");
        }
        if (!(obj instanceof List<?>)) {
            throw new VerifyException("Server returned unexpected response data");
        }
        for (Object lineObj : (List<?>) obj) {
            System.out.println(lineObj);
        }
        // Handle unexpected status values.
    } else {
        throw new VerifyException("Server returned unexpected status");
    }
}

From source file:com.facebook.presto.raptor.systemtables.ResultSetValues.java

int extractValues(ResultSet resultSet, Set<Integer> uuidColumns) throws SQLException {
    checkArgument(resultSet != null, "resultSet is null");
    int completedBytes = 0;

    for (int i = 0; i < types.size(); i++) {
        Class<?> javaType = types.get(i).getJavaType();

        if (javaType == boolean.class) {
            booleans[i] = resultSet.getBoolean(i + 1);
            nulls[i] = resultSet.wasNull();
            if (!nulls[i]) {
                completedBytes += SIZE_OF_BYTE;
            }//ww  w .  j  av  a2s. c o  m
        } else if (javaType == long.class) {
            longs[i] = resultSet.getLong(i + 1);
            nulls[i] = resultSet.wasNull();
            if (!nulls[i]) {
                completedBytes += SIZE_OF_LONG;
            }
        } else if (javaType == double.class) {
            doubles[i] = resultSet.getDouble(i + 1);
            nulls[i] = resultSet.wasNull();
            if (!nulls[i]) {
                completedBytes += SIZE_OF_DOUBLE;
            }
        } else if (javaType == Slice.class) {
            if (uuidColumns.contains(i)) {
                byte[] bytes = resultSet.getBytes(i + 1);
                nulls[i] = resultSet.wasNull();
                strings[i] = nulls[i] ? null : uuidFromBytes(bytes).toString().toLowerCase(ENGLISH);
            } else {
                String value = resultSet.getString(i + 1);
                nulls[i] = resultSet.wasNull();
                strings[i] = nulls[i] ? null : value;
            }

            if (!nulls[i]) {
                completedBytes += strings[i].length();
            }
        } else {
            throw new VerifyException("Unknown Java type: " + javaType);
        }
    }
    return completedBytes;
}

From source file:io.prestosql.plugin.raptor.legacy.systemtables.ResultSetValues.java

int extractValues(ResultSet resultSet, Set<Integer> uuidColumns, Set<Integer> hexColumns) throws SQLException {
    checkArgument(resultSet != null, "resultSet is null");
    int completedBytes = 0;

    for (int i = 0; i < types.size(); i++) {
        Class<?> javaType = types.get(i).getJavaType();

        if (javaType == boolean.class) {
            booleans[i] = resultSet.getBoolean(i + 1);
            nulls[i] = resultSet.wasNull();
            if (!nulls[i]) {
                completedBytes += SIZE_OF_BYTE;
            }/*from w  w  w. ja  v  a2 s.c  o  m*/
        } else if (javaType == long.class) {
            longs[i] = resultSet.getLong(i + 1);
            nulls[i] = resultSet.wasNull();
            if (!nulls[i]) {
                completedBytes += SIZE_OF_LONG;
            }
        } else if (javaType == double.class) {
            doubles[i] = resultSet.getDouble(i + 1);
            nulls[i] = resultSet.wasNull();
            if (!nulls[i]) {
                completedBytes += SIZE_OF_DOUBLE;
            }
        } else if (javaType == Slice.class) {
            if (uuidColumns.contains(i)) {
                byte[] bytes = resultSet.getBytes(i + 1);
                nulls[i] = resultSet.wasNull();
                strings[i] = nulls[i] ? null : uuidFromBytes(bytes).toString().toLowerCase(ENGLISH);
            } else if (hexColumns.contains(i)) {
                long value = resultSet.getLong(i + 1);
                nulls[i] = resultSet.wasNull();
                strings[i] = nulls[i] ? null : format("%016x", value);
            } else {
                String value = resultSet.getString(i + 1);
                nulls[i] = resultSet.wasNull();
                strings[i] = nulls[i] ? null : value;
            }

            if (!nulls[i]) {
                completedBytes += strings[i].length();
            }
        } else {
            throw new VerifyException("Unknown Java type: " + javaType);
        }
    }
    return completedBytes;
}

From source file:google.registry.keyring.api.PgpHelper.java

/**
 * Same as {@link #lookupPublicKey} but also retrieves the associated private key.
 *
 * @throws VerifyException if either keys couldn't be found.
 * @see #lookupPublicKey/* ww  w  .  j a va2 s  .c o m*/
 */
@SuppressWarnings("deprecation")
public static PGPKeyPair lookupKeyPair(PGPPublicKeyRingCollection publics, PGPSecretKeyRingCollection privates,
        String query, KeyRequirement want) {
    PGPPublicKey publicKey = lookupPublicKey(publics, query, want);
    PGPPrivateKey privateKey;
    try {
        PGPSecretKey secret = verifyNotNull(privates.getSecretKey(publicKey.getKeyID()),
                "Keyring missing private key associated with public key id: %x (query '%s')",
                publicKey.getKeyID(), query);
        // We do not support putting a password on the private key so we're just going to
        // put char[0] here.
        privateKey = secret.extractPrivateKey(
                new BcPBESecretKeyDecryptorBuilder(new BcPGPDigestCalculatorProvider()).build(new char[0]));
    } catch (PGPException e) {
        throw new VerifyException(e.getMessage());
    }
    return new PGPKeyPair(publicKey, privateKey);
}

From source file:io.prestosql.operator.scalar.JsonPathTokenizer.java

private String matchQuotedSubscript() {
    // quote has already been matched

    // seek until we see the close quote
    StringBuilder token = new StringBuilder();
    boolean escaped = false;

    while (hasNextCharacter() && (escaped || peekCharacter() != QUOTE)) {
        if (escaped) {
            switch (peekCharacter()) {
            case QUOTE:
            case BACKSLASH:
                token.append(peekCharacter());
                break;
            default:
                throw invalidJsonPath();
            }/*from   ww w .j  a  v  a2s. co  m*/
            escaped = false;
        } else {
            switch (peekCharacter()) {
            case BACKSLASH:
                escaped = true;
                break;
            case QUOTE:
                throw new VerifyException("Should be handled by loop condition");
            default:
                token.append(peekCharacter());
            }
        }
        nextCharacter();
    }
    if (escaped) {
        verify(!hasNextCharacter(), "Loop terminated after escape while there is still input");
        throw invalidJsonPath();
    }

    match(QUOTE);

    return token.toString();
}