List of usage examples for java.io IOException initCause
public synchronized Throwable initCause(Throwable cause)
From source file:com.adito.vfs.webdav.methods.PROPFIND.java
/** * <p>/*ww w.j a v a 2 s .com*/ * Process the <code>PROPFIND</code> method. * </p> */ public void process(DAVTransaction transaction, VFSResource resource) throws LockedException, IOException { if (transaction.isRequiredRootRedirect() || !transaction.isResourcePath(resource.getFullPath())) { throw new DAVRedirection(false, resource); } String handle = VFSLockManager.getNewHandle(); VFSLockManager.getInstance().lock(resource, transaction.getSessionInfo(), false, false, handle); try { /* Check depth */ int depth = transaction.getDepth(); if (depth > 1) throw new DAVException(403, "Invalid depth"); if (SystemProperties.get("adito.disableFolderBrowsing", "true").equals("true") && !resource.isBrowsable()) { transaction.getResponse().sendError(404, "Not Found"); return; } /* What to do on a collection resource */ transaction.setStatus(207); transaction.setContentType("text/xml; charset=\"utf-8\""); PrintWriter out = transaction.write("utf-8"); /* Output the XML declaration and the root document tag */ out.print("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); out.println("<D:multistatus xmlns:D=\"DAV:\">"); /* Process this resource's property (always) */ this.process(transaction, out, resource); /* Process this resource's children (if required) */ if (resource.isCollection() && (depth > 0)) { Iterator children = resource.getChildren(); while (children.hasNext()) { VFSResource child = (VFSResource) children.next(); this.process(transaction, out, child); } } /* Close up the XML Multi-Status response */ out.println("</D:multistatus>"); out.flush(); // Mount may be null at root if (resource.getMount() != null) { resource.getMount().resourceAccessList(resource, transaction, null); } } catch (Exception e) { // Mount may be null at root if (resource.getMount() != null) { resource.getMount().resourceAccessList(resource, transaction, e); } IOException ioe = new IOException(e.getMessage()); ioe.initCause(e); throw ioe; } finally { VFSLockManager.getInstance().unlock(transaction.getSessionInfo(), handle); } }
From source file:com.sslexplorer.vfs.webdav.methods.PROPFIND.java
/** * <p>/*ww w.j av a 2 s .c o m*/ * Process the <code>PROPFIND</code> method. * </p> */ public void process(DAVTransaction transaction, VFSResource resource) throws LockedException, IOException { if (transaction.isRequiredRootRedirect() || !transaction.isResourcePath(resource.getFullPath())) { throw new DAVRedirection(false, resource); } String handle = VFSLockManager.getNewHandle(); VFSLockManager.getInstance().lock(resource, transaction.getSessionInfo(), false, false, handle); try { /* Check depth */ int depth = transaction.getDepth(); if (depth > 1) throw new DAVException(403, "Invalid depth"); if (SystemProperties.get("sslexplorer.disableFolderBrowsing", "true").equals("true") && !resource.isBrowsable()) { transaction.getResponse().sendError(404, "Not Found"); return; } /* What to do on a collection resource */ transaction.setStatus(207); transaction.setContentType("text/xml; charset=\"utf-8\""); PrintWriter out = transaction.write("utf-8"); /* Output the XML declaration and the root document tag */ out.print("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); out.println("<D:multistatus xmlns:D=\"DAV:\">"); /* Process this resource's property (always) */ this.process(transaction, out, resource); /* Process this resource's children (if required) */ if (resource.isCollection() && (depth > 0)) { Iterator children = resource.getChildren(); while (children.hasNext()) { VFSResource child = (VFSResource) children.next(); this.process(transaction, out, child); } } /* Close up the XML Multi-Status response */ out.println("</D:multistatus>"); out.flush(); // Mount may be null at root if (resource.getMount() != null) { resource.getMount().resourceAccessList(resource, transaction, null); } } catch (Exception e) { // Mount may be null at root if (resource.getMount() != null) { resource.getMount().resourceAccessList(resource, transaction, e); } IOException ioe = new IOException(e.getMessage()); ioe.initCause(e); throw ioe; } finally { VFSLockManager.getInstance().unlock(transaction.getSessionInfo(), handle); } }
From source file:ch.cyberduck.core.http.HttpPath.java
/** * @param command Callable writing entity to stream and returning checksum * @param <T> Type of returned checksum * @return Outputstream to write entity into. * @throws IOException Transport error/*from ww w. j a v a 2 s . c o m*/ */ protected <T> ResponseOutputStream<T> write(final DelayedHttpEntityCallable<T> command) throws IOException { /** * Signal on enter streaming */ final CountDownLatch entry = new CountDownLatch(1); final CountDownLatch exit = new CountDownLatch(1); try { final DelayedHttpEntity entity = new DelayedHttpEntity(entry) { @Override public long getContentLength() { return command.getContentLength(); } }; final String type = new MappingMimeTypeService().getMime(this.getName()); entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, type)); final FutureHttpResponse<T> target = new FutureHttpResponse<T>() { @Override public void run() { // Need batcher for logging messages up to the interface final ActionOperationBatcher autorelease = ActionOperationBatcherFactory.get(); try { response = command.call(entity); } catch (IOException e) { exception = e; } finally { // For zero byte files #writeTo is never called and the entry latch not triggered entry.countDown(); // Continue reading the response exit.countDown(); autorelease.operate(); } } }; final Thread t = factory.newThread(target); t.start(); // Wait for output stream to become available entry.await(); if (null != target.getException()) { throw target.getException(); } final OutputStream stream = entity.getStream(); return new ResponseOutputStream<T>(stream) { /** * Only available after this stream is closed. * @return Response from server for upload * @throws IOException Transport error */ @Override public T getResponse() throws IOException { try { // Block the calling thread until after the full response from the server // has been consumed. exit.await(); } catch (InterruptedException e) { IOException failure = new IOException(e.getMessage()); failure.initCause(e); throw failure; } if (null != target.getException()) { throw target.getException(); } return target.getResponse(); } }; } catch (InterruptedException e) { log.error("Error waiting for output stream:" + e.getMessage()); IOException failure = new IOException(e.getMessage()); failure.initCause(e); throw failure; } }
From source file:org.kontalk.client.ClientHTTPConnection.java
private IOException innerException(String detail, Throwable cause) { IOException ie = new IOException(detail); ie.initCause(cause); return ie;//www . j a va 2s. co m }
From source file:org.codehaus.mojo.pml10n.GoogleInterpreter.java
JSONObject retrieveJSON(final URL url) throws IOException { final HttpURLConnection uc = (HttpURLConnection) url.openConnection(); uc.setRequestProperty("referer", referrer); uc.setDoOutput(false);//ww w. j a v a 2 s .c om try { return new JSONObject(IOUtil.toString(uc.getInputStream())); } catch (JSONException e) { IOException ioe = new IOException(e.getMessage()); ioe.initCause(e); throw ioe; } finally { uc.getInputStream().close(); if (uc.getErrorStream() != null) { uc.getErrorStream().close(); } } }
From source file:com.adaptris.core.http.jetty.MessageConsumer.java
@Override public AdaptrisMessage createMessage(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { AdaptrisMessage msg = null;/* w ww .ja va 2 s . c o m*/ OutputStream out = null; try { logHeaders(request); if (getEncoder() != null) { msg = getEncoder().readMessage(request); } else { msg = defaultIfNull(getMessageFactory()).newMessage(); out = msg.getOutputStream(); if (request.getContentLength() == -1) { IOUtils.copy(request.getInputStream(), out); } else { StreamUtil.copyStream(request.getInputStream(), out, request.getContentLength()); } out.flush(); } msg.setContentEncoding(request.getCharacterEncoding()); addParamMetadata(msg, request); addHeaderMetadata(msg, request); } catch (CoreException e) { IOException ioe = new IOException(e.getMessage()); ioe.initCause(e); throw ioe; } finally { IOUtils.closeQuietly(out); } return msg; }
From source file:org.apache.lucene.benchmark.byTask.feeds.ContentSource.java
/** * Returns an {@link InputStream} over the requested file. This method * attempts to identify the appropriate {@link InputStream} instance to return * based on the file name (e.g., if it ends with .bz2 or .bzip, return a * 'bzip' {@link InputStream}).// w w w.ja v a2s .com */ protected InputStream getInputStream(File file) throws IOException { // First, create a FileInputStream, as this will be required by all types. // Wrap with BufferedInputStream for better performance InputStream is = new BufferedInputStream(new FileInputStream(file), BUFFER_SIZE); String fileName = file.getName(); int idx = fileName.lastIndexOf('.'); int type = OTHER; if (idx != -1) { Integer typeInt = (Integer) extensionToType.get(fileName.substring(idx)); if (typeInt != null) { type = typeInt.intValue(); } } switch (type) { case BZIP: try { // According to BZip2CompressorInputStream's code, it reads the first // two file header chars ('B' and 'Z'). It is important to wrap the // underlying input stream with a buffered one since // Bzip2CompressorInputStream uses the read() method exclusively. is = csFactory.createCompressorInputStream("bzip2", is); } catch (CompressorException e) { IOException ioe = new IOException(e.getMessage()); ioe.initCause(e); throw ioe; } break; default: // Do nothing, stay with FileInputStream } return is; }
From source file:org.apache.hadoop.hbase.regionserver.HLog.java
/** * Split up a bunch of regionserver commit log files that are no longer * being written to, into new files, one per region for region to replay on * startup. Delete the old log files when finished. * * @param rootDir qualified root directory of the HBase instance * @param srcDir Directory of log files to split: e.g. * <code>${ROOTDIR}/log_HOST_PORT</code> * @param fs FileSystem//from w w w . j a v a 2s .com * @param conf HBaseConfiguration * @throws IOException */ public static List<Path> splitLog(final Path rootDir, final Path srcDir, final FileSystem fs, final HBaseConfiguration conf) throws IOException { long millis = System.currentTimeMillis(); List<Path> splits = null; if (!fs.exists(srcDir)) { // Nothing to do return splits; } FileStatus[] logfiles = fs.listStatus(srcDir); if (logfiles == null || logfiles.length == 0) { // Nothing to do return splits; } LOG.info("Splitting " + logfiles.length + " hlog(s) in " + srcDir.toString()); splits = splitLog(rootDir, logfiles, fs, conf); try { fs.delete(srcDir, true); } catch (IOException e) { e = RemoteExceptionHandler.checkIOException(e); IOException io = new IOException("Cannot delete: " + srcDir); io.initCause(e); throw io; } long endMillis = System.currentTimeMillis(); LOG.info("hlog file splitting completed in " + (endMillis - millis) + " millis for " + srcDir.toString()); return splits; }
From source file:org.apache.hadoop.hive.hwi.HWIServer.java
/** * This method initialized the internal Jetty Servlet Engine. It adds the * hwi context path./*from w w w . ja v a 2 s.c o m*/ * * @throws java.io.IOException * Port already in use, bad bind etc. */ public void start() throws IOException { HiveConf conf = new HiveConf(this.getClass()); String listen = null; int port = -1; listen = conf.getVar(HiveConf.ConfVars.HIVEHWILISTENHOST); port = conf.getIntVar(HiveConf.ConfVars.HIVEHWILISTENPORT); if (listen.equals("")) { l4j.warn("hive.hwi.listen.host was not specified defaulting to 0.0.0.0"); listen = "0.0.0.0"; } if (port == -1) { l4j.warn("hive.hwi.listen.port was not specified defaulting to 9999"); port = 9999; } String hwiWAR = conf.getVar(HiveConf.ConfVars.HIVEHWIWARFILE); String hivehome = System.getenv().get("HIVE_HOME"); File hwiWARFile = new File(hivehome, hwiWAR); if (!hwiWARFile.exists()) { l4j.fatal("HWI WAR file not found at " + hwiWARFile.toString()); System.exit(1); } webServer = ShimLoader.getJettyShims().startServer(listen, port); webServer.addWar(hwiWARFile.toString(), "/hwi"); /* * The command line args may be used by multiple components. Rather by * setting these as a system property we avoid having to specifically * pass them */ StringBuilder sb = new StringBuilder(); for (String arg : args) { sb.append(arg + " "); } System.setProperty("hwi-args", sb.toString()); try { while (true) { try { webServer.start(); webServer.join(); l4j.debug(" HWI Web Server is started."); break; } catch (org.mortbay.util.MultiException ex) { throw ex; } } } catch (IOException ie) { throw ie; } catch (Exception e) { IOException ie = new IOException("Problem starting HWI server"); ie.initCause(e); l4j.error("Parsing hwi.listen.port caused exception ", e); throw ie; } }
From source file:org.cloudata.core.common.CStatusHttpServer.java
/** * Start the server. Does not wait for the server to start. */// w ww . j a v a2 s .com public void start() throws IOException { if (jettyServer == null) { return; } try { jettyServer.start(); } catch (IOException ie) { LOG.error(ie); throw ie; } catch (Exception e) { IOException ie = new IOException("Problem starting http server"); ie.initCause(e); throw ie; } LOG.info("Web-server up at: " + port); }