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:net.javacrumbs.smock.axis2.client.SmockClient.java

public static void bootstrap() {
    try {/*from  www .  j  av a 2  s .  c  o m*/
        ConfigurationContext configurationContext = ConfigurationContextFactory
                .createConfigurationContextFromFileSystem(null, null);
        HashMap<String, TransportOutDescription> transportsOut = configurationContext.getAxisConfiguration()
                .getTransportsOut();
        for (TransportOutDescription tod : transportsOut.values()) {
            setSender(tod);
        }
        ListenerManager.defaultConfigurationContext = configurationContext;
    } catch (AxisFault e) {
        throw new IllegalStateException("Can not set ListenerManager.defaultConfigurationContext.", e);
    }
}

From source file:com.android.volley.toolbox.SslSocketFactory.java

private static SSLContext createSSLContext(InputStream keyStore, String keyStorePassword)
        throws GeneralSecurityException {
    SSLContext sslcontext = null;
    try {//from  www .  j  av a  2s.  co  m
        sslcontext = SSLContext.getInstance("TLS");
        sslcontext.init(null, new TrustManager[] { new SsX509TrustManager(keyStore, keyStorePassword) }, null);
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalStateException("Failure initializing default SSL context", e);
    } catch (KeyManagementException e) {
        throw new IllegalStateException("Failure initializing default SSL context", e);
    }

    return sslcontext;
}

From source file:io.yields.math.framework.kpi.ExplorerDAO.java

public static void save(Explorer<?> explorer) {
    String group = explorer.getGroup();
    if (StringUtils.isBlank(group)) {
        group = NO_GROUP;/*from   ww  w . j  a  v a  2s. com*/
    }
    File destinationFolder = getRootFolder(group);

    if (!destinationFolder.exists()) {
        try {
            forceMkdir(destinationFolder);
        } catch (IOException ioe) {
            throw new IllegalStateException(
                    format("Destination folder for data export could not be created at %s",
                            destinationFolder.getAbsolutePath()),
                    ioe);
        }
    }

    if (!destinationFolder.isDirectory()) {
        throw new IllegalStateException(format("Destination path for data export %s is not a folder",
                destinationFolder.getAbsolutePath()));
    }

    if (!destinationFolder.canWrite()) {
        throw new IllegalStateException(format("Destination folder for data export %s is not writable",
                destinationFolder.getAbsolutePath()));
    }

    String fileName = explorer.getName().replaceAll("[^a-zA-Z0-9]", "_") + "_"
            + DATE_TIME_FORMATTER.format(LocalDateTime.now());

    File csvDestinationFile = new File(destinationFolder, fileName + "." + FILE_SUFFIX_CSV);
    csvExporter.export(explorer, csvDestinationFile);

    File jsonDestinationFile = new File(destinationFolder, fileName + "." + FILE_SUFFIX_JSON);
    jsonExporter.export(explorer, jsonDestinationFile);

}

From source file:org.eclipse.swordfish.core.test.util.base.BaseMavenOsgiTestCase.java

protected static String getBundleVersion(String groupId, String artifactId) {
    Properties dependencies = null;
    InputStream inputStream = null;
    try {/* www  .  j  av a 2s  .co  m*/
        inputStream = BaseMavenOsgiTestCase.class.getClassLoader()
                .getResource("META-INF/maven/dependencies.properties").openStream();
        Properties prop = new Properties();
        prop.load(inputStream);
        dependencies = prop;
    } catch (IOException e) {
        throw new IllegalStateException("Unable to load dependencies informations", e);
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
                throw new AssertionError();
            }
        }
    }
    String version = dependencies.getProperty(groupId + "/" + artifactId + "/version");
    if (version == null) {
        throw new IllegalStateException(
                "Unable to find dependency information for: " + groupId + "/" + artifactId + "/version");
    }
    return version;
}

From source file:oz.hadoop.yarn.api.utils.JarUtils.java

/**
 * Will create a JAR file frombase dir//from  w  ww  . ja  v  a2 s.  c o  m
 *
 * @param source
 * @param jarName
 * @return
 */
public static File toJar(File source, String jarName) {
    if (!source.isAbsolute()) {
        throw new IllegalArgumentException("Source must be expressed through absolute path");
    }
    StringAssertUtils.assertNotEmptyAndNoSpacesAndEndsWith(jarName, ".jar");
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
    File jarFile = new File(jarName);
    try {
        JarOutputStream target = new JarOutputStream(new FileOutputStream(jarFile), manifest);
        add(source, source.getAbsolutePath().length(), target);
        target.close();
    } catch (Exception e) {
        throw new IllegalStateException(
                "Failed to create JAR file '" + jarName + "' from " + source.getAbsolutePath(), e);
    }
    return jarFile;
}

From source file:com.qcadoo.model.internal.utils.JdomUtils.java

public static byte[] documentToByteArray(final Document document) {
    try {//from ww w. jav a  2 s.  c om
        XMLOutputter outputter = new XMLOutputter();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        outputter.output(document, out);
        return out.toByteArray();
    } catch (IOException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}

From source file:com.orange.clara.cloud.truststore.TrustStoreStorePropertyJsonReader.java

@Override
public TrustStoreProperty read(String json) {
    try {/*from   w w  w .  ja v  a 2 s .c o  m*/
        ObjectMapper mapper = new ObjectMapper();
        return mapper.readValue(json, TrustStoreProperty.class);

    } catch (Exception e) {
        String message = String.format("Invalid truststore property.");
        throw new IllegalStateException(message, e);
    }

}

From source file:org.jspringbot.keyword.ssh.SSHConnect.java

@Override
public Object execute(Object[] params) {
    try {//w w w .  j  a v  a2 s .c o  m
        helper.sshConnect();
    } catch (IOException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }

    return null;
}

From source file:oz.hadoop.yarn.api.utils.ConfigUtils.java

/**
 * Will dynamically add configuration directory to the classpath.
 * // w ww .  ja v a 2  s  . co m
 * @param configurationDirectoryPath
 */
public static void addToClasspath(File configurationDirectoryPath) {
    Assert.notNull(configurationDirectoryPath, "'configurationDirectoryPath' must not be null");
    Assert.isTrue(configurationDirectoryPath.exists(), "'configurationDirectoryPath' must exist");
    Assert.isTrue(configurationDirectoryPath.isDirectory(), "'configurationDirectoryPath' must be a directory");

    URL configUrl = null;
    try {
        configUrl = new URL("file:" + configurationDirectoryPath.getAbsolutePath() + "/");
    } catch (Exception e) {
        throw new IllegalArgumentException("Failed to construct URL for " + configurationDirectoryPath, e);
    }
    URLClassLoader cl = (URLClassLoader) ClassLoader.getSystemClassLoader();
    Method addUrlMethod = ReflectionUtils.getMethodAndMakeAccessible(URLClassLoader.class, "addURL", URL.class);
    try {
        addUrlMethod.invoke(cl, configUrl);
    } catch (Exception e) {
        throw new IllegalStateException("Failed to add URL: " + configUrl + " to the classpath", e);
    }
}