use of java.io.IOException in project camel by apache.
the class OnExceptionHandleAndThrowNewExceptionTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
onException(IllegalArgumentException.class).handled(true).to("log:onException").process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
Exception cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
assertNotNull(cause);
throw new IOException("First failure message is: " + cause.getMessage());
}
});
from("direct:start").throwException(new IllegalArgumentException("Damn"));
}
};
}
use of java.io.IOException in project camel by apache.
the class AtmosAPIFacade method downloadSingleFile.
private void downloadSingleFile(String path, Map<String, ByteArrayOutputStream> resultEntries) throws AtmosException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] content = null;
try {
content = AtmosAPIFacade.client.readObject(new ObjectPath(path), byte[].class);
baos.write(content);
} catch (IOException e) {
throw new AtmosException(path + " cannot obtain a stream", e);
}
if (content != null) {
resultEntries.put(path, baos);
LOG.debug("Downloaded path: {} size:", path, baos.size());
}
}
use of java.io.IOException in project camel by apache.
the class AtmosPropertyManager method loadProperties.
private static Properties loadProperties() throws Exception {
URL url = AtmosPropertyManager.class.getResource("/atmos.properties");
InputStream inStream;
try {
inStream = url.openStream();
} catch (IOException e) {
throw new AtmosException("atmos.properties could not be found");
}
properties = new Properties();
try {
properties.load(inStream);
} catch (IOException e) {
throw new AtmosException("atmos.properties can't be read");
}
return properties;
}
use of java.io.IOException in project antlrworks by antlr.
the class BrowserLauncher method openURL.
/**
* Attempts to open the default web browser to the given URL.
* @param url The URL to open
* @throws IOException If the web browser could not be located or does not run
*/
public static void openURL(String url) throws IOException {
if (!loadedWithoutErrors) {
throw new IOException("Exception in finding browser: " + errorMessage);
}
Object browser = locateBrowser();
if (browser == null) {
throw new IOException("Unable to locate browser: " + errorMessage);
}
switch(jvm) {
case MRJ_2_0:
Object aeDesc;
try {
aeDesc = aeDescConstructor.newInstance(new Object[] { url });
putParameter.invoke(browser, new Object[] { keyDirectObject, aeDesc });
sendNoReply.invoke(browser, new Object[] {});
} catch (InvocationTargetException ite) {
throw new IOException("InvocationTargetException while creating AEDesc: " + ite.getMessage());
} catch (IllegalAccessException iae) {
throw new IOException("IllegalAccessException while building AppleEvent: " + iae.getMessage());
} catch (InstantiationException ie) {
throw new IOException("InstantiationException while creating AEDesc: " + ie.getMessage());
} finally {
// Encourage it to get disposed if it was created
aeDesc = null;
// Ditto
browser = null;
}
break;
case MRJ_2_1:
Runtime.getRuntime().exec(new String[] { (String) browser, url });
break;
case MRJ_3_0:
int[] instance = new int[1];
int result = ICStart(instance, 0);
if (result == 0) {
int[] selectionStart = new int[] { 0 };
byte[] urlBytes = url.getBytes();
int[] selectionEnd = new int[] { urlBytes.length };
result = ICLaunchURL(instance[0], new byte[] { 0 }, urlBytes, urlBytes.length, selectionStart, selectionEnd);
if (result == 0) {
// Ignore the return value; the URL was launched successfully
// regardless of what happens here.
ICStop(instance);
} else {
throw new IOException("Unable to launch URL: " + result);
}
} else {
throw new IOException("Unable to create an Internet Config instance: " + result);
}
break;
case MRJ_3_1:
try {
openURL.invoke(null, new Object[] { url });
} catch (InvocationTargetException ite) {
throw new IOException("InvocationTargetException while calling openURL: " + ite.getMessage());
} catch (IllegalAccessException iae) {
throw new IOException("IllegalAccessException while calling openURL: " + iae.getMessage());
}
break;
case WINDOWS_NT:
case WINDOWS_9x:
// Add quotes around the URL to allow ampersands and other special
// characters to work.
Process process = Runtime.getRuntime().exec(new String[] { (String) browser, FIRST_WINDOWS_PARAMETER, SECOND_WINDOWS_PARAMETER, THIRD_WINDOWS_PARAMETER, '"' + url + '"' });
// That's hinted at in <http://developer.java.sun.com/developer/qow/archive/68/>.
try {
process.waitFor();
process.exitValue();
} catch (InterruptedException ie) {
throw new IOException("InterruptedException while launching browser: " + ie.getMessage());
}
break;
case LINUX:
case OTHER:
// Assume that we're on Unix and that Netscape is installed
String[] array = (String[]) browser;
for (int i = 0; i < array.length; i++) {
if (openUnixBrowser(array[i], url))
return;
}
throw new IOException("Unable to locate browser");
default:
// This should never occur, but if it does, we'll try the simplest thing possible
Runtime.getRuntime().exec(new String[] { (String) browser, url });
break;
}
}
use of java.io.IOException in project antlrworks by antlr.
the class HelpManager method sendFeedback.
public static void sendFeedback(Container parent) {
StringBuilder url = new StringBuilder(Localizable.getLocalizedString(Localizable.FEEDBACK_URL));
url.append("?ANTLRVersion=");
url.append(XJUtils.encodeToURL(new Tool().VERSION));
url.append("&StringTemplateVersion=");
url.append(XJUtils.encodeToURL(StringTemplate.VERSION));
url.append("&ANTLRWorksVersion=");
url.append(XJUtils.encodeToURL(XJApplication.getAppVersionShort()));
url.append("&OS=");
url.append(XJUtils.encodeToURL(XJSystem.getOSName()));
url.append("&JavaVersion=");
url.append(XJUtils.encodeToURL(XJSystem.getJavaRuntimeVersion()));
try {
BrowserLauncher.openURL(url.toString());
} catch (IOException e) {
XJAlert.display(parent, "Error", "Cannot display the feedback page because:\n" + e + "\n\nTo report a feedback, go to " + url + ".");
}
}
Aggregations