List of usage examples for org.apache.commons.lang UnhandledException UnhandledException
public UnhandledException(Throwable cause)
From source file:de.awtools.xml.TransformerUtils.java
/** * Schreibt ein dom4j Dokument in eine Datei. * * @param document Ein dom4j Dokument.//www . j av a2 s . co m * @param file Die zu schreibende Datei. * @param encoding Das Encoding. * @throws UnhandledException Da ging was schief. */ public static void toFile(final Document document, final File file, final String encoding) throws UnhandledException { XMLWriter writer = null; try { OutputFormat format = OutputFormat.createPrettyPrint(); format.setEncoding(encoding); writer = new XMLWriter(new FileWriter(file), format); writer.write(document); } catch (IOException ex) { log.debug("Fehler: ", ex); throw new UnhandledException(ex); } finally { XMLUtils.close(writer); } }
From source file:ch.admin.suis.msghandler.config.SigningOutbox.java
/** * Returns all PDF files which are in the "signingOutboxDir" directory. These PDFs will be signed later. After a * successful sign process these files should be moved to: * <code>getProcessedDir()</code>. If * <code>getProcessedDir()</code> is null these files should be deleted. * * @return The PDFs that need to be signed *///from w w w . j a v a2s . c om public List<File> getAllPDFsToSign() { try (DirectoryStream<Path> files = FileUtils.listFiles(signingOutboxDir, FileFilters.PDF_FILTER_PATH)) { List<File> retVal = new ArrayList<>(); for (Path path : files) { retVal.add(path.toFile()); } files.close(); return retVal; } catch (IOException e) { throw new UnhandledException(e); } }
From source file:de.iteratec.iteraplan.presentation.tags.StringEscapeUtilsFunction.java
public static String unescapeJava(String str) { if (str == null) { return null; }/* ww w .j ava2 s .com*/ try { StringWriter writer = new StringWriter(str.length()); unescapeJava(writer, str); return writer.toString(); } catch (IOException ioe) { throw new UnhandledException(ioe); } }
From source file:com.prowidesoftware.swift.utils.AckMessageComparator.java
/** * Compare two tag values considering internal settings. * if {@link #ignoreEolsInMultiline} is true, then multi-line tags are compared line by * line, ignoring which eol is used in each case. lines are determined by java api readline * //from w w w. j a va 2s .c o m * @param value1 * @param value2 * @return true if equals accordign to internal settings, false otherwise */ private boolean valuesAreEqual(final String value1, final String value2) { if (value1 == null && value2 == null) { return true; } if (value1 == null || value2 == null) { return false; } // both values are non-null here if (this.ignoreEolsInMultiline) { final BufferedReader br1 = new BufferedReader(new StringReader(value1)); final BufferedReader br2 = new BufferedReader(new StringReader(value2)); while (true) { try { final String l1 = br1.readLine(); final String l2 = br2.readLine(); if (!StringUtils.equals(l1, l2)) { return false; } if (l1 == null && l2 == null) { /* * If both end of streams are reached and no differences were * reported previously then return true */ return true; } } catch (final IOException e) { throw new UnhandledException(e); } } } else { return StringUtils.equals(value1, value2); } }
From source file:net.jotel.ws.client.WebSocketClientTest.java
@Test public void reconnect() throws Exception { final List<Exception> exceptions = new ArrayList<Exception>(); URI uri = new URI("ws://not-existing-domain-name:8080/websocket/ws/subscribe"); final WebSocketClient c = new WebSocketClient(); c.setWebSocketUri(uri);/* www . j a v a 2s. com*/ c.setReconnectEnabled(true); c.setReconnectInterval(100L); c.setReconnectAttempts(2); c.addListener(new WebSocketListener() { @Override public void onMessage(String message) { } @Override public void onMessage(byte[] message) { } @Override public void onError(Exception ex) { exceptions.add(ex); } @Override public void onClose(Integer statusCode, String message) { // TODO Auto-generated method stub } @Override public void onConnect() { // TODO Auto-generated method stub } }); try { c.connect(); fail("Expected WebSocketException"); } catch (WebSocketException ex) { // expected assertEquals(3, exceptions.size()); for (Exception e : exceptions) { Throwable rootCause = ExceptionUtils.getRootCause(e); if (rootCause == null) { rootCause = e; } assertTrue(rootCause instanceof UnknownHostException); } } exceptions.clear(); c.setReconnectAttempts(0); try { c.connect(); fail("Expected WebSocketException"); } catch (WebSocketException ex) { // expected assertEquals(1, exceptions.size()); for (Exception e : exceptions) { Throwable rootCause = ExceptionUtils.getRootCause(e); if (rootCause == null) { rootCause = e; } assertTrue(rootCause instanceof UnknownHostException); } } exceptions.clear(); c.setReconnectAttempts(-1); ExecutorService executor = Executors.newSingleThreadExecutor(); Future<?> future = executor.submit(new Runnable() { @Override public void run() { try { c.connect(); fail("Expected WebSocketException"); } catch (WebSocketException ex) { throw new UnhandledException(ex); } } }); Thread.sleep(2000L); c.setReconnectEnabled(false); Thread.sleep(2000L); executor.shutdown(); assertTrue(executor.awaitTermination(1, TimeUnit.SECONDS)); try { future.get(); fail("Expected WebSocketException"); } catch (Exception ex) { // expected assertTrue(exceptions.size() > 1); for (Exception e : exceptions) { Throwable rootCause = ExceptionUtils.getRootCause(e); if (rootCause == null) { rootCause = e; } assertTrue(rootCause instanceof UnknownHostException); } } }
From source file:ar.com.zauber.commons.mom.MapObjectMapper.java
public RuntimeException soften(Exception e) { if (e instanceof RuntimeException) { return (RuntimeException) e; }/* ww w.ja va2s. c o m*/ return new UnhandledException(e); }
From source file:gov.nih.nci.caarray.application.file.FileManagementServiceBean.java
/** * {@inheritDoc}//from ww w.j a v a 2 s. c o m */ @Override @TransactionAttribute(TransactionAttributeType.REQUIRED) public void reimportAndParseArrayDesign(Long arrayDesignId) throws InvalidDataFileException, IllegalAccessException { ArrayDesign arrayDesign = this.searchDao.retrieve(ArrayDesign.class, arrayDesignId); if (!arrayDesign.isUnparsedAndReimportable()) { throw new IllegalAccessException("This array design is not eligible for reimport"); } final ArrayDesignService ads = ServiceLocatorFactory.getArrayDesignService(); arrayDesign.getDesignFileSet().updateStatus(FileStatus.VALIDATING); try { arrayDesign = ads.saveArrayDesign(arrayDesign); ads.importDesign(arrayDesign); checkDesignFiles(arrayDesign.getDesignFileSet()); } catch (final InvalidDataFileException e) { arrayDesign.getDesignFileSet().updateStatus(FileStatus.IMPORT_FAILED); throw e; } catch (final IllegalAccessException e) { arrayDesign.getDesignFileSet().updateStatus(FileStatus.IMPORT_FAILED); throw e; } catch (final Exception e) { arrayDesign.getDesignFileSet().updateStatus(FileStatus.IMPORT_FAILED); throw new UnhandledException(e); } importArrayDesignDetails(arrayDesign); }
From source file:ch.admin.suis.msghandler.util.FileUtils.java
/** * Reads all files from a directory. Will throw an UnhandledException if the directory doesn't exist or an IO * exception occurred. Use this method instead of File.listFiles(...) * * @param directory The directory to list the files from * @param filefilter The file filter/*w w w . jav a2 s .c om*/ * @return A list of files (static array) * @Deprecated This should never, ever be used again. It is a very, very old method. See java.nio.file. This method * is not good when you're getting to big data. */ public static File[] listFiles(File directory, FileFilter filefilter) { File[] result = directory.listFiles(filefilter); if (result == null) { throw new UnhandledException( new IOException("This pathname does not denote a directory, or an I/O error occured: " + directory.getAbsolutePath())); } return result; }
From source file:hr.fer.zemris.vhdllab.service.impl.GhdlSimulator.java
private List<String> executeProcess(CommandLine cl, java.io.File tempDirectory) throws ExecuteException, IOException { if (LOG.isDebugEnabled()) { LOG.debug("Executing process: " + cl.toString()); }// www . ja v a 2 s . c o m ByteArrayOutputStream bos = new ByteArrayOutputStream(); ExecuteStreamHandler handler = new PumpStreamHandler(bos); ExecuteWatchdog watchdog = new ExecuteWatchdog(PROCESS_TIMEOUT); Executor executor = new DefaultExecutor(); executor.setWorkingDirectory(tempDirectory); executor.setWatchdog(watchdog); executor.setStreamHandler(handler); /* * It seems that when ExecuteWatchdog terminates process by invoking * destroy method, process terminates with exit code 143. And since we * manually ask watchdog if he killed the process, exit code 143 is * marked as successful (just so our code can be executed). * * Exit code 1 in case of compilation error(s). */ executor.setExitValues(new int[] { 0, 1, 143 }); try { executor.execute(cl); } catch (ExecuteException e) { LOG.warn("Process output dump:\n" + bos.toString()); throw e; } if (watchdog.killedProcess()) { throw new SimulatorTimeoutException(PROCESS_TIMEOUT); } String output; try { output = bos.toString(IOUtil.DEFAULT_ENCODING); } catch (UnsupportedEncodingException e) { throw new UnhandledException(e); } if (StringUtils.isBlank(output)) { return Collections.emptyList(); } return Arrays.asList(StringUtil.splitToNewLines(output)); }
From source file:ch.admin.suis.msghandler.util.FileUtils.java
/** * Reads all files from a directory. Will throw an UnhandledException if the directory doesn't exist or an IO * exception occurred. Use this method instead of File.listFiles(...) * * @param directory The directory to list the files from * @param filter The file filter/*from ww w. ja v a 2 s.c o m*/ * @return A stream of files */ public static DirectoryStream<Path> listFiles(File directory, DirectoryStream.Filter<Path> filter) { Path folder = Paths.get(directory.getAbsolutePath()); try { return Files.newDirectoryStream(folder, filter); } catch (IOException e) { throw new UnhandledException( new IOException("This pathname does not denote a directory, or an I/O error occured: " + directory.getAbsolutePath())); } }