List of usage examples for java.lang IllegalStateException IllegalStateException
public IllegalStateException(Throwable cause)
From source file:Main.java
public static void writeDocument(Document document, File directoryToWriteTo, String fileName) { // Prepare the DOM document for writing Source source = new DOMSource(document); // Prepare the output file File file = new File(directoryToWriteTo, fileName); Result result = new StreamResult(file); // Write the DOM document to the file try {/*from w ww . ja v a2 s. co m*/ Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2"); transformer.transform(source, result); } catch (TransformerFactoryConfigurationError | TransformerException e) { throw new IllegalStateException(e); } }
From source file:com.jdom.util.TestUtil.java
public static File getTestClassDir(Class<?> testClass) { File testDir = new File(JAVA_IO_TMPDIR, testClass.getSimpleName()); if (testDir.exists()) { try {/*from w ww . j ava 2 s .co m*/ FileUtils.deleteDirectory(testDir); } catch (IOException e) { throw new IllegalStateException(e); } } return testDir; }
From source file:Main.java
/** * @return a transformer that indents entries by 4 characters (never null) */// w ww. j a v a 2s . com public static final Transformer createIndentingTransformer() { Transformer xformer; try { transformerFactory.setAttribute("indent-number", 4); xformer = transformerFactory.newTransformer(); } catch (Exception ex) { throw new IllegalStateException(ex); } xformer.setOutputProperty(OutputKeys.INDENT, "yes"); xformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); return xformer; }
From source file:Main.java
public static void quitLoop() { try {/*ww w . j a v a2 s . c o m*/ Field mQuitAllowed = MessageQueue.class.getDeclaredField("mQuitAllowed"); mQuitAllowed.setAccessible(true); mQuitAllowed.set(Looper.myQueue(), true); Looper.myLooper().quit(); Field mQuiting = MessageQueue.class.getDeclaredField("mQuiting"); mQuiting.setAccessible(true); mQuiting.set(Looper.myQueue(), false); mQuitAllowed.set(Looper.myQueue(), false); } catch (Exception e) { throw new IllegalStateException( "Sofia modal runnables are not " + "supported on this version of the Android API because the " + "MessageQueue.mQuitAllowed field could not be found or " + "there was a problem changing it."); } }
From source file:Main.java
public static Double getNodesCount(String expression, Document document) { XPath xpath = xPathFactory.newXPath(); try {/*from ww w.ja v a2 s . c o m*/ Double count = (Double) xpath.evaluate("count(" + expression + ")", document, XPathConstants.NUMBER); return count; } catch (XPathExpressionException xpe) { throw new IllegalStateException(xpe); } }
From source file:io.jmnarloch.spring.boot.rxjava.subscribable.Subscribables.java
public static Subscribable toSubscribable(Object result) { Assert.notNull(result, "Parameter 'result' can not be null"); if (result instanceof Observable) { return new ObservableSubscribable((Observable) result); } else if (result instanceof Single) { return new SingleSubscribable((Single) result); } else {/*w w w. j a va 2 s .c o m*/ throw new IllegalStateException( String.format("The %s type can not be converted to Subscribable", result.getClass().getName())); } }
From source file:org.springframework.rest.documentation.doclet.RestDoclet.java
public static boolean start(RootDoc rootDoc) throws IOException { Javadoc api = new JavadocProcessor().process(rootDoc); File outputDirectory = getOutputDirectory(rootDoc.options()); if (!outputDirectory.isDirectory() && !outputDirectory.mkdirs()) { throw new IllegalStateException("Failed to create output directory " + outputDirectory); }/*from w w w .ja v a 2 s . c om*/ File file = new File(outputDirectory, "javadoc.json"); FileWriter writer = new FileWriter(file); JsonGenerator generator = new JsonFactory(new ObjectMapper()).createGenerator(writer) .useDefaultPrettyPrinter(); generator.writeObject(api); return true; }
From source file:com.yoho.core.trace.util.ExceptionUtils.java
public static void warn(String msg) { if (fail) {// ww w .ja v a2 s .c o m throw new IllegalStateException(msg); } log.warn(msg); }
From source file:com.relicum.ipsum.Utils.Profiler.java
public static void startProfiling(String id) { final long nanos = System.nanoTime(); synchronized (startTimes) { if (startTimes.containsKey(id)) { throw new IllegalStateException("This ID is already being profiled!"); }//from w w w. ja v a 2s . c o m startTimes.put(id, nanos); } }
From source file:Main.java
/** * @return a transformer that indents entries by 4 characters (never null) *//*from w w w.j a va 2s.co m*/ public static final Transformer createIndentingTransformer() { Transformer transformer; try { transformerFactory.setAttribute("indent-number", 4); transformer = transformerFactory.newTransformer(); } catch (Exception e) { throw new IllegalStateException(e); } transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); return transformer; }