public static void rethrowIOException(Throwable cause)
            throws IOException {
        if (cause instanceof IOException) {
            throw (IOException) cause;
        } else if (cause instanceof RuntimeException) {
            throw (RuntimeException) cause;
        } else if (cause instanceof Error) {
            throw (Error) cause;
        } else {
            throw new IOException(cause.getMessage(), cause);
        }
    }
@Test
    public void testRethrowRuntimeExceptionAsIOException() throws IOException {
        RuntimeException re = new RuntimeException("test");
        try {
            rethrowIOException(re);
            fail("Should rethrow RuntimeException");
        } catch (RuntimeException e) {
            assertSame(re, e);
        }
    }