@Test public void testCRLFHandling() throws IOException { List<String> lines = Arrays.asList( getClass().getPackage().getName(), getClass().getSimpleName(), getCurrentTestName(), "(" + mode + ")", new Date(System.currentTimeMillis()).toString()); String content = GenericUtils.join(lines, "\r\n"); try (ByteArrayInputStream bais = new ByteArrayInputStream(content.getBytes(StandardCharsets.UTF_8)); TtyFilterInputStream tty = new TtyFilterInputStream(bais, EnumSet.of(mode))) { final AtomicInteger crCount = new AtomicInteger(0); final AtomicInteger lfCount = new AtomicInteger(0); try (OutputStream output = new OutputStream() { @Override public void write(int b) throws IOException { if (b == '\r') { crCount.incrementAndGet(); } else if (b == '\n') { lfCount.incrementAndGet(); } } }) { long copySize = IoUtils.copy(tty, output); assertTrue( "Copy size (" + copySize + ") above total length (" + content.length() + ")", copySize <= content.length()); } assertCRLFCounts( mode, lines.size() - 1 /* last line has no NL */, crCount.get(), lfCount.get()); } }