List of usage examples for java.io IOException getCause
public synchronized Throwable getCause()
From source file:xtrememp.playlist.PlaylistIO.java
/** * Saves playlist in M3U format./*from w w w . j ava2s .c om*/ * * @param playlist * @param location * @return <code>true</code> if playlist is successfully saved, else <code>false</code>. */ public static boolean saveM3U(Playlist playlist, String location) throws PlaylistException { if (playlist != null) { BufferedWriter bw = null; try { bw = new BufferedWriter(new FileWriter(location)); bw.write("#EXTM3U"); bw.newLine(); for (PlaylistItem pli : playlist.listAllItems()) { bw.write("#EXTINF:" + pli.getM3UExtInf()); bw.newLine(); bw.write(pli.getLocation()); bw.newLine(); } playlist.setModified(false); return true; } catch (IOException ex) { logger.error("Can't save playlist in M3U format", ex); throw new PlaylistException(ex.getMessage(), ex.getCause()); } finally { IOUtils.closeQuietly(bw); } } return false; }
From source file:gov.nasa.ensemble.common.io.FileUtilities.java
/** * Make a copy of a file on the filesystem (platform independent). * /*from www .j av a2 s . c om*/ * @param source * the file to copy. * @param dest * the copy to make. * @return whether the file copy exists on the filesystem upon completion. * @throws IOException */ public static boolean copyFile(File source, File dest) throws IOException { FileInputStream sourceStream = new FileInputStream(source); FileChannel sourceChannel = sourceStream.getChannel(); FileOutputStream destStream = new FileOutputStream(dest); FileChannel destChannel = destStream.getChannel(); try { sourceChannel.transferTo(0, sourceChannel.size(), destChannel); } catch (IOException ex) { if (ex.getCause() instanceof OutOfMemoryError) { IOUtils.copy(sourceStream, destStream); } } finally { destChannel.close(); IOUtils.closeQuietly(destStream); sourceChannel.close(); IOUtils.closeQuietly(sourceStream); } return dest.exists(); }
From source file:com.hortonworks.hbase.replication.bridge.HBaseRPC.java
/** * @param protocol protocol interface/*ww w . j a va 2 s . com*/ * @param clientVersion which client version we expect * @param addr address of remote service * @param conf configuration * @param maxAttempts max attempts * @param rpcTimeout timeout for each RPC * @param timeout timeout in milliseconds * @return proxy * @throws IOException e */ @SuppressWarnings("unchecked") public static <T extends VersionedProtocol> T waitForProxy(RpcEngine rpcClient, Class<T> protocol, long clientVersion, InetSocketAddress addr, Configuration conf, int maxAttempts, int rpcTimeout, long timeout) throws IOException { // HBase does limited number of reconnects which is different from hadoop. long startTime = System.currentTimeMillis(); IOException ioe; int reconnectAttempts = 0; while (true) { try { return rpcClient.getProxy(protocol, clientVersion, addr, conf, rpcTimeout); } catch (SocketTimeoutException te) { // namenode is busy LOG.info("Problem connecting to server: " + addr); ioe = te; } catch (IOException ioex) { // We only handle the ConnectException. ConnectException ce = null; if (ioex instanceof ConnectException) { ce = (ConnectException) ioex; ioe = ce; } else if (ioex.getCause() != null && ioex.getCause() instanceof ConnectException) { ce = (ConnectException) ioex.getCause(); ioe = ce; } else if (ioex.getMessage().toLowerCase().contains("connection refused")) { ce = new ConnectException(ioex.getMessage()); ioe = ce; } else { // This is the exception we can't handle. ioe = ioex; } if (ce != null) { handleConnectionException(++reconnectAttempts, maxAttempts, protocol, addr, ce); } } // check if timed out if (System.currentTimeMillis() - timeout >= startTime) { throw ioe; } // wait for retry try { Thread.sleep(1000); } catch (InterruptedException ie) { // IGNORE } } }
From source file:org.wildfly.test.integration.elytron.sasl.mgmt.ScramPlusMgmtSaslTestCase.java
/** * Asserts that execution of :whoami operation fail and exception contains *//* w w w . ja va 2 s . c o m*/ protected static void assertAuthenticationFailsPlusRequired() { final long startTime = System.currentTimeMillis(); try { executeWhoAmI(); fail("Client authentication failure is expected."); } catch (IOException e) { assertTrue("Connection reached its timeout (hang).", startTime + CONNECTION_TIMEOUT_IN_MS > System.currentTimeMillis()); Throwable cause = e.getCause(); assertThat("ConnectionException was expected as a cause when SASL authentication fails", cause, is(instanceOf(ConnectException.class))); Throwable saslException = cause.getCause(); assertThat("An unexpected second Exception cause came when authentication failed", saslException, is(instanceOf(SaslException.class))); final String saslExceptionMsg = saslException.getMessage(); assertThat("SASL Error message should contain reason of failure (channel binding configuration).", saslExceptionMsg, allOf(containsString("ELY05166"), containsString(ScramServerErrorCode.SERVER_DOES_SUPPORT_CHANNEL_BINDING.getText()))); } }
From source file:org.apache.hadoop.hbase.zookeeper.MetaTableLocator.java
/** * @param sn ServerName to get a connection against. * @return The AdminProtocol we got when we connected to <code>sn</code> * May have come from cache, may not be good, may have been setup by this * invocation, or may be null./*www. j av a2 s . c o m*/ * @throws IOException */ @SuppressWarnings("deprecation") private static AdminService.BlockingInterface getCachedConnection(HConnection hConnection, ServerName sn) throws IOException { if (sn == null) { return null; } AdminService.BlockingInterface service = null; try { service = hConnection.getAdmin(sn); } catch (RetriesExhaustedException e) { if (e.getCause() != null && e.getCause() instanceof ConnectException) { // Catch this; presume it means the cached connection has gone bad. } else { throw e; } } catch (SocketTimeoutException e) { LOG.debug("Timed out connecting to " + sn); } catch (NoRouteToHostException e) { LOG.debug("Connecting to " + sn, e); } catch (SocketException e) { LOG.debug("Exception connecting to " + sn); } catch (UnknownHostException e) { LOG.debug("Unknown host exception connecting to " + sn); } catch (FailedServerException e) { if (LOG.isDebugEnabled()) { LOG.debug("Server " + sn + " is in failed server list."); } } catch (IOException ioe) { Throwable cause = ioe.getCause(); if (ioe instanceof ConnectException) { // Catch. Connect refused. } else if (cause != null && cause instanceof EOFException) { // Catch. Other end disconnected us. } else if (cause != null && cause.getMessage() != null && cause.getMessage().toLowerCase().contains("connection reset")) { // Catch. Connection reset. } else { throw ioe; } } return service; }
From source file:mas.MAS_TOP_PAPERS.java
public static String getData2(String url_org, int start) { try {/*from w w w.j av a2 s . c o m*/ String complete_url = url_org + "&$skip=" + start; // String url_str = generateURL(url_org, prop); Document doc = Jsoup.connect(complete_url).timeout(25000).ignoreContentType(true).get(); return doc.text(); } catch (IOException ex) { System.out.println(ex.getMessage() + " Cause: " + ex.getCause()); Logger.getLogger(MAS_TOP_PAPERS.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:mas.MAS_VLDB.java
public static String getData2(String url_org, int start) { try {//from w w w .jav a 2 s . com String complete_url = url_org + "&$skip=" + start; // String url_str = generateURL(url_org, prop); Document doc = Jsoup.connect(complete_url).timeout(25000).ignoreContentType(true).get(); return doc.text(); } catch (IOException ex) { System.out.println(ex.getMessage() + " Cause: " + ex.getCause()); Logger.getLogger(MAS_VLDB.class.getName()).log(Level.SEVERE, null, ex); } return null; }
From source file:org.apache.hadoop.hbase.ipc.HBaseRPC.java
/** * @param protocol protocol interface/*from w w w. j a va 2 s .c om*/ * @param clientVersion which client version we expect * @param addr address of remote service * @param conf configuration * @param maxAttempts max attempts * @param rpcTimeout timeout for each RPC * @param timeout timeout in milliseconds * @return proxy * @throws IOException e */ @SuppressWarnings("unchecked") public static VersionedProtocol waitForProxy(Class protocol, long clientVersion, InetSocketAddress addr, Configuration conf, int maxAttempts, int rpcTimeout, long timeout) throws IOException { // HBase does limited number of reconnects which is different from hadoop. long startTime = System.currentTimeMillis(); IOException ioe; int reconnectAttempts = 0; while (true) { try { return getProxy(protocol, clientVersion, addr, conf, rpcTimeout); } catch (SocketTimeoutException te) { // namenode is busy LOG.info("Problem connecting to server: " + addr); ioe = te; } catch (IOException ioex) { // We only handle the ConnectException. ConnectException ce = null; if (ioex instanceof ConnectException) { ce = (ConnectException) ioex; ioe = ce; } else if (ioex.getCause() != null && ioex.getCause() instanceof ConnectException) { ce = (ConnectException) ioex.getCause(); ioe = ce; } else if (ioex.getMessage().toLowerCase().contains("connection refused")) { ce = new ConnectException(ioex.getMessage()); ioe = ce; } else { // This is the exception we can't handle. ioe = ioex; } if (ce != null) { handleConnectionException(++reconnectAttempts, maxAttempts, protocol, addr, ce); } } // check if timed out if (System.currentTimeMillis() - timeout >= startTime) { throw ioe; } // wait for retry try { Thread.sleep(1000); } catch (InterruptedException ie) { // IGNORE } } }
From source file:org.apache.tika.parser.pdf.PDF2XHTML.java
/** * Converts the given PDF document (and related metadata) to a stream * of XHTML SAX events sent to the given content handler. * * @param document PDF document/* w w w .ja va 2s . c om*/ * @param handler SAX content handler * @param metadata PDF metadata * @throws SAXException if the content handler fails to process SAX events * @throws TikaException if the PDF document can not be processed */ public static void process(PDDocument document, ContentHandler handler, ParseContext context, Metadata metadata, PDFParserConfig config) throws SAXException, TikaException { try { // Extract text using a dummy Writer as we override the // key methods to output to the given content // handler. PDF2XHTML pdf2XHTML = new PDF2XHTML(handler, context, metadata, config); config.configure(pdf2XHTML); pdf2XHTML.writeText(document, new Writer() { @Override public void write(char[] cbuf, int off, int len) { } @Override public void flush() { } @Override public void close() { } }); } catch (IOException e) { if (e.getCause() instanceof SAXException) { throw (SAXException) e.getCause(); } else { throw new TikaException("Unable to extract PDF content", e); } } }
From source file:com.aliyun.oss.common.utils.ExceptionFactory.java
public static ClientException createNetworkException(IOException ex) { String requestId = "Unknown"; String errorCode = ClientErrorCode.UNKNOWN; if (ex instanceof SocketTimeoutException) { errorCode = ClientErrorCode.SOCKET_TIMEOUT; } else if (ex instanceof SocketException) { errorCode = ClientErrorCode.SOCKET_EXCEPTION; } else if (ex instanceof ConnectTimeoutException) { errorCode = ClientErrorCode.CONNECTION_TIMEOUT; } else if (ex instanceof UnknownHostException) { errorCode = ClientErrorCode.UNKNOWN_HOST; } else if (ex instanceof HttpHostConnectException) { errorCode = ClientErrorCode.CONNECTION_REFUSED; } else if (ex instanceof ClientProtocolException) { Throwable cause = ex.getCause(); if (cause instanceof NonRepeatableRequestException) { errorCode = ClientErrorCode.NONREPEATABLE_REQUEST; return new ClientException(cause.getMessage(), errorCode, requestId, cause); }//from w ww . j a v a2s . com } return new ClientException(ex.getMessage(), errorCode, requestId, ex); }