private static void copyWriter(String in) throws Exception { CloseableRegistry r = new CloseableRegistry(); try { WriterWrapper out = new WriterWrapper(TEST_OUTPUT_FILE); r.register(out); assertEquals(VALUE.length, CopyCharsUtils.copy(in, out.getWriter(), true)); } finally { r.close(); } }
private static void copyReader(String out) throws Exception { CloseableRegistry r = new CloseableRegistry(); try { ReaderWrapper in = new ReaderWrapper(TEST_INPUT_FILE); r.register(in); assertEquals(VALUE.length, CopyCharsUtils.copy(in.getReader(), true, out)); } finally { r.close(); } }
@Test public void failReaderWriter() throws Exception { CopyCharsUtils.copy(VALUE, TEST_INPUT_FILE); CloseableRegistry r = new CloseableRegistry(); try { ReaderWrapper in = new ReaderWrapper(TEST_INPUT_FILE); r.register(in); WriterWrapper out = new WriterWrapper(TEST_OUTPUT_FILE); r.register(out); out.getWriter().close(); CopyCharsUtils.copy(in.getReader(), true, out.getWriter(), true); fail(); } catch (I18NException ex) { assertEquals(ex.getDetail(), Messages.CANNOT_COPY_CSTREAMS, ex.getI18NBoundMessage()); } finally { r.close(); } }
@Test public void copyReaderWriter() throws Exception { CopyCharsUtils.copy(VALUE, TEST_INPUT_FILE); CloseableRegistry r = new CloseableRegistry(); try { ReaderWrapper in = new ReaderWrapper(TEST_INPUT_FILE); r.register(in); WriterWrapper out = new WriterWrapper(TEST_OUTPUT_FILE); r.register(out); assertEquals( VALUE.length, CopyCharsUtils.copy( in.getReader(), true, out.getWriter(), true)); } finally { r.close(); } assertArrayEquals(VALUE, CopyCharsUtils.copy(TEST_OUTPUT_FILE)); }