Text { public void read(final DangerousSupplier<OutputStream> supplier) throws Exception { try (final InputStream in = textSupplier.get()) { IoUtils.redirect(in, supplier.get()); } }  void read(final DangerousSupplier<OutputStream> supplier); void read(final DangerousConsumer<InputStream> consumer); String get();  }
@Test public void testRead() throws Exception { final ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); final ByteArrayOutputStream byteOut2 = new ByteArrayOutputStream(); text.read(() -> byteOut); text.read(in -> IoUtils.redirect(in, byteOut2)); assertArrayEquals(expected.getBytes(), byteOut.toByteArray()); assertArrayEquals(expected.getBytes(), byteOut2.toByteArray()); }