Search in sources :

Example 51 with IOException

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"));
        }
    };
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) IOException(java.io.IOException) CamelExecutionException(org.apache.camel.CamelExecutionException) IOException(java.io.IOException)

Example 52 with IOException

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());
    }
}
Also used : ObjectPath(com.emc.atmos.api.ObjectPath) AtmosException(org.apache.camel.component.atmos.util.AtmosException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 53 with IOException

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;
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) Properties(java.util.Properties) URL(java.net.URL)

Example 54 with IOException

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;
    }
}
Also used : IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 55 with IOException

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 + ".");
    }
}
Also used : IOException(java.io.IOException) Tool(org.antlr.Tool)

Aggregations

IOException (java.io.IOException)41104 File (java.io.File)7663 InputStream (java.io.InputStream)4105 Test (org.junit.Test)3557 ArrayList (java.util.ArrayList)3023 FileInputStream (java.io.FileInputStream)2674 FileOutputStream (java.io.FileOutputStream)2358 FileNotFoundException (java.io.FileNotFoundException)2146 BufferedReader (java.io.BufferedReader)2028 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1761 InputStreamReader (java.io.InputStreamReader)1677 URL (java.net.URL)1608 HashMap (java.util.HashMap)1552 ByteArrayInputStream (java.io.ByteArrayInputStream)1534 OutputStream (java.io.OutputStream)1349 Path (org.apache.hadoop.fs.Path)1316 Map (java.util.Map)1212 List (java.util.List)1042 Properties (java.util.Properties)994 ServletException (javax.servlet.ServletException)916