/** * Convert a {@link Throwable} to an {@link IOException}. * * @param cause reason to fail * @return a converted {@link IOException}. */ public static IOException toIOException(Throwable cause) { if (cause instanceof IOException) { return (IOException) cause; } else if (cause instanceof ExecutionException || cause instanceof CompletionException) { return toIOException(cause.getCause()); } else { return new IOException(cause); } }