List of usage examples for java.lang IllegalStateException IllegalStateException
public IllegalStateException(Throwable cause)
From source file:com.github.dozermapper.core.classmap.RelationshipType.java
public static RelationshipType valueOf(String relationshipType) { if (CUMULATIVE_VALUE.equals(relationshipType)) { return CUMULATIVE; } else if (NON_CUMULATIVE_VALUE.equals(relationshipType)) { return NON_CUMULATIVE; } else if (StringUtils.isEmpty(relationshipType)) { return null; }//w w w . j a va 2 s . c o m throw new IllegalStateException( "relationship-type should be cumulative or non-cumulative. " + relationshipType); }
From source file:com.nicksa.flickrtopicasa.io.IoUtils.java
public static void copyFile(File sourceFile, File toFile) throws Throwable { // Does the source file exist? if (!sourceFile.exists()) { throw new IllegalStateException("Source file does not exist."); }//w w w.j a va2 s .c o m // Is the destination path a directory? if (toFile.isDirectory()) { toFile = new File(toFile, sourceFile.getName()); } // Does the destination path already exist on the filesystem? File parentDirectory = toFile.getParentFile(); if (!parentDirectory.exists()) { boolean successInMakingDirectory = parentDirectory.mkdirs(); if (!successInMakingDirectory) { throw new IllegalStateException("Could not create directories."); } } // Start copying. FileCopyUtils.copy(sourceFile, toFile); }
From source file:Main.java
/** * Converts a java.io.InputStream to a java.lang.String object * @throws java.lang.IllegalStateException if an error occurs while reading the stream or closing the reader * @param is/*from ww w .j a va 2s . c o m*/ * @return the String representation of the provided InputStream */ public static String inputStreamToString(InputStream is) { String line = ""; StringBuilder builder = new StringBuilder(); BufferedReader rd = new BufferedReader(new InputStreamReader(is)); try { while ((line = rd.readLine()) != null) { builder.append(line); } } catch (IOException e) { throw new IllegalStateException(e); } finally { try { if (rd != null) rd.close(); } catch (IOException e) { throw new IllegalStateException(e); } } return builder.toString(); }
From source file:com.github.trask.sandbox.saucelabs.SauceLabsCredentials.java
public static SauceLabsCredentials fromSystemEnv() { String username = System.getenv("SAUCE_LABS_USERNAME"); String apiKey = System.getenv("SAUCE_LABS_API_KEY"); if (StringUtils.isEmpty(username)) { throw new IllegalStateException("Missing environment variable SAUCE_LABS_USERNAME"); }/* ww w .j a v a 2 s.c om*/ if (StringUtils.isEmpty(apiKey)) { throw new IllegalStateException("Missing environment variable SAUCE_LABS_API_KEY"); } return new SauceLabsCredentials(username, apiKey); }
From source file:com.tc.process.Exec.java
public static String getJavaExecutable() { String javaHome = System.getProperty("java.home"); if (javaHome == null) { throw new IllegalStateException("java.home system property not set"); }/*from w w w . j a v a 2s . c om*/ File home = new File(javaHome); ensureDir(home); File bin = new File(home, "bin"); ensureDir(bin); File java = new File(bin, "java" + (System.getProperty("os.name").contains("win") ? ".exe" : "")); if (java.exists() && java.canRead()) { return java.getAbsolutePath(); } throw new AssertionError(java.getAbsolutePath() + " cannot be read or does not exist"); }
From source file:Main.java
public static void writeDocumentToDisk(Document document, File directoryToWriteTo, String fileName) { DOMImplementation domImplementation = document.getImplementation(); if (domImplementation.hasFeature("LS", "3.0") && domImplementation.hasFeature("Core", "2.0")) { DOMImplementationLS domImplementationLS = (DOMImplementationLS) domImplementation.getFeature("LS", "3.0"); LSSerializer lsSerializer = domImplementationLS.createLSSerializer(); DOMConfiguration domConfiguration = lsSerializer.getDomConfig(); if (domConfiguration.canSetParameter("format-pretty-print", Boolean.TRUE)) { lsSerializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); LSOutput lsOutput = domImplementationLS.createLSOutput(); lsOutput.setEncoding("UTF-8"); try { lsOutput.setByteStream(new FileOutputStream(new File(directoryToWriteTo, fileName))); } catch (FileNotFoundException e) { throw new IllegalStateException(e); }/*from w w w . j a va 2s. c o m*/ lsSerializer.write(document, lsOutput); } } }
From source file:Main.java
/** * Create a new SAXParser which processes XML securely. * * @return a SAXParser// w ww. j a v a 2 s . co m */ public static SAXParser createSaxParser() { SAXParserFactory spf = SAXParserFactory.newInstance(); try { spf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); return spf.newSAXParser(); } catch (ParserConfigurationException | SAXException e) { throw new IllegalStateException(e); } }
From source file:com.textocat.textokit.eval.matching.PrimitiveCollectionFeatureMatcher.java
public static <FST extends FeatureStructure> Matcher<FST> forFeature(Feature feat, boolean ignoreOrder) { Type compType = MatchingUtils.getComponentType(feat.getRange()); if (!compType.isPrimitive()) { throw new IllegalStateException( String.format("Component type %s of feature %s is not primitive type", compType, feat)); }/*from w ww . j ava2s .co m*/ if ("uima.cas.String".equals(compType.getName())) { return forStringCollection(feat, ignoreOrder); } else { // TODO LOW PRIORITY throw new UnsupportedOperationException( String.format("PrimitiveCollectionFeatureMatcher for %s is not implemented yet", compType)); } }
From source file:org.trustedanalytics.cloud.cc.api.CcLastOperationState.java
@JsonCreator public static CcLastOperationState fromValue(String value) { return Arrays.asList(CcLastOperationState.values()).stream() .filter(enm -> enm.state.equalsIgnoreCase(value)).findFirst() .orElseThrow(() -> new IllegalStateException( String.format("Unable to deserialize %s from %s", CcLastOperationState.class, value))); }
From source file:gov.nih.nci.caintegrator.application.configuration.SpringContext.java
/** * Returns a bean from the spring ApplicationFactory with the * provided name./*from www . j a v a 2 s. c om*/ * * @param name * @return * @throws IllegalStateException */ public static Object getBean(final String name) throws IllegalStateException { if (!initialized) throw new IllegalStateException("SpringContext has not been initialized."); return wac.getBean(name); }