List of usage examples for java.io IOException initCause
public synchronized Throwable initCause(Throwable cause)
From source file:com.todoroo.andlib.service.HttpRestClient.java
/** * Issue an HTTP GET for the given URL, return the response * * @param url url with url-encoded params * @return response, or null if there was no response * @throws IOException/*from ww w. j a va2 s .c o m*/ */ public synchronized String get(String url) throws IOException { if (debug) Log.d("http-rest-client-get", url); //$NON-NLS-1$ try { HttpGet httpGet = new HttpGet(url); HttpResponse response = getClient().execute(httpGet); return processHttpResponse(response); } catch (IOException e) { throw e; } catch (Exception e) { IOException ioException = new IOException(e.getMessage()); ioException.initCause(e); throw ioException; } }
From source file:org.apache.ivy.plugins.repository.vfs.VfsRepository.java
private StandardFileSystemManager createVFSManager() throws IOException { StandardFileSystemManager result = null; try {//from w w w . ja va 2 s.c o m /* * The DefaultFileSystemManager gets its configuration from the jakarta-vfs-common * implementation which includes the res and tmp schemes which are of no use to use * here. Using StandardFileSystemManager lets us specify which schemes to support as * well as providing a mechanism to change this support without recompilation. */ result = new StandardFileSystemManager() { protected void configurePlugins() throws FileSystemException { // disable automatic loading potential unsupported extensions } }; result.setConfiguration(getClass().getResource(IVY_VFS_CONFIG)); result.init(); // Generate and print a list of available schemes Message.verbose("Available VFS schemes..."); String[] schemes = result.getSchemes(); Arrays.sort(schemes); for (int i = 0; i < schemes.length; i++) { Message.verbose("VFS Supported Scheme: " + schemes[i]); } } catch (FileSystemException e) { /* * If our attempt to initialize a VFS Repository fails we log the failure but continue * on. Given that an Ivy instance may involve numerous different repository types, it * seems overly cautious to throw a runtime exception on the initialization failure of * just one repository type. */ Message.error("Unable to initialize VFS repository manager!"); Message.error(e.getLocalizedMessage()); IOException error = new IOException(e.getLocalizedMessage()); error.initCause(e); throw error; } return result; }
From source file:com.todoroo.andlib.service.HttpRestClient.java
/** * Issue an HTTP POST for the given URL, return the response * * @param url/*from w w w . ja va2 s . co m*/ * @param data * url-encoded data * @throws IOException */ public synchronized String post(String url, HttpEntity data, Header... headers) throws IOException { if (debug) Log.d("http-rest-client-post", url + " | " + data); //$NON-NLS-1$ //$NON-NLS-2$ try { HttpPost httpPost = new HttpPost(url); httpPost.setEntity(data); for (Header header : headers) httpPost.addHeader(header); HttpResponse response = getClient().execute(httpPost); return processHttpResponse(response); } catch (IOException e) { throw e; } catch (Exception e) { IOException ioException = new IOException(e.getMessage()); ioException.initCause(e); throw ioException; } }
From source file:offstage.crypt.ConfigFilesCrypt.java
/** Encrypt a file, removing the original */ public void encryptFile(File fin) throws IOException { try {/* w w w . ja v a 2s. c om*/ PBECrypt pbe = new PBECrypt(); String contents = FileUtils.readFileToString(fin); // if (!contents.startsWith(PBECrypt.BEGIN_ENCRYPTED)); File fout = new File(fin.getPath() + ".crypt"); FileUtils.writeStringToFile(fout, pbe.encrypt(contents, getPassword())); fin.delete(); } catch (IOException ioe) { throw ioe; } catch (Exception e) { IOException ioe = new IOException(e.getMessage()); ioe.initCause(e); throw ioe; } }
From source file:com.jkoolcloud.tnt4j.repository.FileTokenRepository.java
@Override public void open() throws IOException { if (isOpen() || (configName == null)) return;/*from w ww . ja v a 2s . c o m*/ try { initConfig(); if (refDelay > 0) { FileChangedReloadingStrategy reloadConfig = new FileChangedReloadingStrategy(); reloadConfig.setRefreshDelay(refDelay); config.setReloadingStrategy(reloadConfig); } } catch (Throwable e) { IOException ioe = new IOException(e.toString()); ioe.initCause(e); throw ioe; } }
From source file:org.codehaus.mojo.pml10n.GoogleInterpreter.java
public String translate(String text, Locale source, Locale destination) throws IOException { List parameters = new ArrayList(); StringBuffer textBuffer = new StringBuffer(text.length()); int i0 = 0;//from w ww .j a v a2 s. co m int i1 = text.indexOf('{', i0); int i2; while (i1 != -1 && (i2 = text.indexOf('}', i1)) != -1) { textBuffer.append(text.substring(i0, i1)); textBuffer.append("____"); textBuffer.append(parameters.size()); textBuffer.append("____"); parameters.add(text.substring(i1, i2 + 1)); i0 = i2 + 1; i1 = text.indexOf('{', i0); } textBuffer.append(text.substring(i0)); System.out.println(textBuffer); URL url = new URL(MessageFormat.format(urlPattern, new Object[] { URLEncoder.encode(fromLocale(source), UTF8), URLEncoder.encode(fromLocale(destination), UTF8), URLEncoder.encode(textBuffer.toString(), UTF8) })); JSONObject response = retrieveJSON(url); try { if (response == null || response.getInt("responseStatus") != 200) { throw new IOException("Invalid response"); } String result = StringEscapeUtils.unescapeHtml( URLDecoder.decode(response.getJSONObject("responseData").getString("translatedText"), UTF8)); for (int i = 0; i < parameters.size(); i++) { result = StringUtils.replace(result, "____" + i + "____", (String) parameters.get(i)); } return result; } catch (JSONException e) { IOException ioe = new IOException(e.getMessage()); ioe.initCause(e); throw ioe; } }
From source file:com.mindquarry.desktop.client.dialog.conflict.OpenOfficeMerger.java
/** * Start OpenOffice in merge mode.// w w w. j a v a 2 s . c o m * NOTE: this method returns immediately, the return value thus * isn't valid yet. Ask the user to click a button when he's finished. * @throws IOException */ public File merge(File file1, File file2) throws IOException { // TODO: better way to build file URLs? String url1 = "file://" + file1.getAbsolutePath(); String url2 = "file://" + file2.getAbsolutePath(); try { // 1. this version does all the work for us, it starts OOo if it isn't running // yet. However, we need to reference the original JARs (juh.jar etc) in the // OOo installation directory (not the ones we provide) so this seems useless // as OOo might be installed anywhere //XComponentContext xRemoteContext = com.sun.star.comp.helper.Bootstrap.bootstrap(); // 2. access a running version, if no one is running we need to start // it ourselfes XComponentContext xLocalContext = com.sun.star.comp.helper.Bootstrap .createInitialComponentContext(null); XMultiComponentFactory xLocalServiceManager = xLocalContext.getServiceManager(); Object urlResolver = xLocalServiceManager .createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", xLocalContext); XUnoUrlResolver xUnoUrlResolver = (XUnoUrlResolver) UnoRuntime.queryInterface(XUnoUrlResolver.class, urlResolver); Object initialObject = getConnection(xUnoUrlResolver); XPropertySet xPropertySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, initialObject); Object remoteContext = xPropertySet.getPropertyValue("DefaultContext"); XComponentContext xRemoteContext = (XComponentContext) UnoRuntime .queryInterface(XComponentContext.class, remoteContext); XMultiComponentFactory xRemoteServiceManager = xRemoteContext.getServiceManager(); if (xRemoteServiceManager == null) { throw new NullPointerException("xRemoteServiceManager not available"); } // get the Desktop, we need its XComponentLoader interface to load a new document Object desktop = xRemoteServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", xRemoteContext); // query the XComponentLoader interface from the desktop XComponentLoader xComponentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, desktop); // create empty array of PropertyValue structs, needed for loadComponentFromURL PropertyValue[] loadProps = new PropertyValue[0]; // load text file xComponentLoader.loadComponentFromURL(url1, "_blank", 0, loadProps); XDesktop myDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, desktop); XFrame frame = myDesktop.getCurrentFrame(); XDispatchProvider dispatchProvider = (XDispatchProvider) UnoRuntime .queryInterface(XDispatchProvider.class, frame); PropertyValue[] compareProps = new PropertyValue[1]; compareProps[0] = new PropertyValue(); compareProps[0].Name = "URL"; compareProps[0].Value = url2; Object dispatchHelper = xRemoteServiceManager .createInstanceWithContext("com.sun.star.frame.DispatchHelper", xRemoteContext); XDispatchHelper xDispatchHelper = (XDispatchHelper) UnoRuntime.queryInterface(XDispatchHelper.class, dispatchHelper); // warning: returns immediately xDispatchHelper.executeDispatch(dispatchProvider, ".uno:CompareDocuments", "", 0, compareProps); } catch (NoConnectException e) { IOException ioe = new IOException(e.toString()); ioe.initCause(e); throw ioe; } catch (Exception e) { throw new RuntimeException(e.toString(), e); } // the user is supposed to save (not "save as..."), so just // return the original file: return file1; }
From source file:org.apache.http.impl.client.cache.memcached.MemcachedHttpCacheStorage.java
private byte[] serializeEntry(final String url, final HttpCacheEntry hce) throws IOException { final MemcachedCacheEntry mce = memcachedCacheEntryFactory.getMemcachedCacheEntry(url, hce); try {/*from w w w. j av a 2s. com*/ return mce.toByteArray(); } catch (final MemcachedSerializationException mse) { final IOException ioe = new IOException(); ioe.initCause(mse); throw ioe; } }
From source file:org.apache.hama.pipes.Application.java
/** * Abort the application and wait for it to finish. * /*from w ww . j a va 2 s . c om*/ * @param t the exception that signalled the problem * @throws IOException A wrapper around the exception that was passed in */ void abort(Throwable t) throws IOException { LOG.info("Aborting because of " + StringUtils.stringifyException(t)); try { downlink.abort(); downlink.flush(); } catch (IOException e) { // IGNORE cleanup problems } try { downlink.waitForFinish(); } catch (Throwable ignored) { process.destroy(); } IOException wrapper = new IOException("pipe child exception"); wrapper.initCause(t); throw wrapper; }
From source file:offstage.crypt.ConfigFilesCrypt.java
/** Encrypt a file, removing the original */ public String readCryptedURL(URL url) throws IOException { // First try to read the unencrypted version try {//from w ww .j av a 2 s .c o m return readURLToString(url); } catch (IOException e) { try { // Unencrypted version does not exist; read encrypted version char[] password = getPassword(); URL cipherURL = new URL(url.toExternalForm() + ".crypt"); String cipherString = readURLToString(url); PBECrypt pbe = new PBECrypt(); return pbe.decrypt(cipherString, password); } catch (IOException ioe) { throw ioe; } catch (Exception e2) { IOException ioe = new IOException(e.getMessage()); ioe.initCause(e2); throw ioe; } } }