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 testRethrowOtherExceptionAsIOException() throws IOException {
        Exception e = new Exception("test");
        try {
            rethrowIOException(e);
            fail("Should rethrow IOException");
        } catch (IOException ioe) {
            assertEquals("test", ioe.getMessage());
            assertSame(e, ioe.getCause());
        }
    }