Example usage for java.lang IllegalStateException IllegalStateException

List of usage examples for java.lang IllegalStateException IllegalStateException

Introduction

In this page you can find the example usage for java.lang IllegalStateException IllegalStateException.

Prototype

public IllegalStateException(String message, Throwable cause) 

Source Link

Document

Constructs a new exception with the specified detail message and cause.

Usage

From source file:com.ai.bss.util.user.DigestUtils.java

/**
 * Calculate the SHA1 hash for a given string.
 *
 * @param text the given text to hash to a SHA1
 * @return the SHA1 Hash/*from   w  w w  .j a va  2 s. c  o  m*/
 */
public static String sha1(String text) {
    Assert.notNull(text);
    try {
        MessageDigest md = MessageDigest.getInstance("SHA1");
        return hex(md.digest(text.getBytes("UTF-8")));
    } catch (NoSuchAlgorithmException ex) {
        throw new IllegalStateException(
                "Unable to calculate hash. No SHA1 hasher available in this Java implementation", ex);
    } catch (UnsupportedEncodingException ex) {
        throw new IllegalStateException(
                "Unable to calculate hash. UTF-8 encoding is not available in this Java implementation", ex);
    }
}

From source file:com.github.jcustenborder.kafka.connect.salesforce.TestData.java

License:asdf

public static SObjectDescriptor sObjectDescriptor() {
    try (InputStream inputStream = TestData.class.getResourceAsStream("sobjectdescriptor.json")) {
        return jsonFactory.fromInputStream(inputStream, SObjectDescriptor.class);
    } catch (IOException ex) {
        throw new IllegalStateException("Could not read", ex);
    }/*from  ww  w  . j  a  v a 2 s . co  m*/
}

From source file:com.barrybecker4.common.util.Base64Codec.java

/**
 * take a String and compress it.//from   ww  w.j a va  2  s.c o  m
 * See @decompress for reversing the compression.
 * @param data a string to compress.
 * @return compressed string representation.
 */
public static synchronized String compress(final String data) {

    ByteArrayOutputStream byteOut = new ByteArrayOutputStream(512);
    Deflater deflater = new Deflater();
    DeflaterOutputStream oStream = new DeflaterOutputStream(byteOut, deflater);

    try {
        oStream.write(data.getBytes(CONVERTER_UTF8));
        oStream.flush();
        oStream.close();
    } catch (UnsupportedEncodingException e) {
        throw new IllegalArgumentException("Unsupported encoding exception :" + e.getMessage(), e);
    } catch (IOException e) {
        throw new IllegalStateException("io error :" + e.getMessage(), e);
    }

    return new String(Base64.encodeBase64(byteOut.toByteArray()));
}

From source file:io.syndesis.credential.BaseCredentialProvider.java

protected static String callbackUrlFor(final URI baseUrl,
        final MultiValueMap<String, String> additionalParams) {
    final String path = baseUrl.getPath();

    final String callbackPath = path + "credentials/callback";

    try {/*from   w ww . jav a  2s.  com*/
        final URI base = new URI(baseUrl.getScheme(), null, baseUrl.getHost(), baseUrl.getPort(), callbackPath,
                null, null);

        return UriComponentsBuilder.fromUri(base).queryParams(additionalParams).build().toUriString();
    } catch (final URISyntaxException e) {
        throw new IllegalStateException("Unable to generate callback URI", e);
    }
}

From source file:dtu.ds.warnme.app.utils.SecurityUtils.java

public static String hashMD5Base64(String stringToHash) {
    if (StringUtils.isEmpty(stringToHash)) {
        return StringUtils.EMPTY;
    }/*from  www .  j av a 2 s  .co  m*/
    try {
        byte[] bytes = stringToHash.getBytes(CHARSET_UTF8);
        byte[] sha512bytes = DigestUtils.md5(bytes);
        byte[] base64bytes = Base64.encodeBase64(sha512bytes);
        return new String(base64bytes, CHARSET_UTF8);
    } catch (UnsupportedEncodingException e) {
        Log.e(TAG, "This system does not support required hashing algorithms.", e);
        throw new IllegalStateException("This system does not support required hashing algorithms.", e);
    }
}

From source file:org.springframework.cloud.dataflow.rest.util.HttpUtils.java

/**
 * Will create a certificate-ignoring {@link SSLContext}. Please use with utmost
 * caution as it undermines security, but may be useful in certain testing or
 * development scenarios./*from   w w  w . j a  v  a2s .  c o  m*/
 *
 * @return an SSLContext that will ignore peer certificates
 */
public static SSLContext buildCertificateIgnoringSslContext() {
    try {
        return SSLContexts.custom().loadTrustMaterial((chain, authType) -> true).build();
    } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
        throw new IllegalStateException(
                "Unexpected exception while building the certificate-ignoring SSLContext" + ".", e);
    }
}

From source file:com.googlecode.flyway.core.util.ResourceUtils.java

/**
 * Loads this resource in a string using this encoding.
 *
 * @param resource The resource to load.
 * @param encoding The encoding of the resource.
 * @return The resource contents as a string.
 *///w w w  .j  a  va  2  s.  com
public static String loadResourceAsString(Resource resource, String encoding) {
    try {
        Reader reader = new InputStreamReader(resource.getInputStream(), Charset.forName(encoding));
        return FileCopyUtils.copyToString(reader);
    } catch (IOException e) {
        throw new IllegalStateException(
                "Unable to load resource: " + resource.getDescription() + " (encoding: " + encoding + ")", e);
    }
}

From source file:com.github.robozonky.app.tenant.RefreshableStrategy.java

protected static URL convertToUrl(final String maybeUrl) {
    try {/*from   www .j  a v a2 s.c  om*/
        return new URL(maybeUrl);
    } catch (final MalformedURLException e) {
        try {
            return new File(maybeUrl).toURI().toURL();
        } catch (final NullPointerException | MalformedURLException e1) {
            throw new IllegalStateException("Cannot load strategy " + maybeUrl, e1);
        }
    }
}

From source file:com.basho.riak.client.api.convert.reflection.ClassUtil.java

public static void setFieldValue(Field field, Object obj, Object value) {
    try {//w w w . ja  v  a 2  s . c  om
        field.set(obj, value);
    } catch (IllegalAccessException e) {
        throw new IllegalStateException("Unable to set Riak annotated field value", e);
    }
}

From source file:ch.newscron.referral.ReferralManager.java

/**
 * Provides a connection to the database specified (see fields)
 * @return a Connection for the database
 *///from w  w w .ja  v a2 s. c  o m
public static Connection connect() {
    try {
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection connection = DriverManager.getConnection(DBurl, username, password);
        return connection;
    } catch (SQLException e) {
        throw new IllegalStateException("Cannot connect the database! ", e);
    } catch (Exception ex) {
        Logger.getLogger(ReferralManager.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}