/** * Converts checked exceptions to unchecked based on the {@code Consumer} interface. * <p> * This wraps the specified consumer returning an instance that handles checked exceptions. * If a checked exception is thrown it is converted to an {@link UncheckedIOException} * or {@link RuntimeException} as appropriate. * * @param <T> the type of the consumer * @param consumer the consumer to be decorated * @return the consumer instance that handles checked exceptions */ public static <T> Consumer<T> consumer(CheckedConsumer<T> consumer) { return (t) -> { try { consumer.accept(t); } catch (Throwable ex) { throw propagate(ex); } }; }