Having
ByteArrayOutputStream b = ...;
//some code under test writes to b
Reader result = (convert b to reader);
IOUtils.contentEqualsIgnoreEOL(expected, result);
如何将
ByteArrayOutputStream
转换为Reader
?Having
ByteArrayOutputStream b = ...;
//some code under test writes to b
Reader result = (convert b to reader);
IOUtils.contentEqualsIgnoreEOL(expected, result);
ByteArrayOutputStream
转换为Reader
?ByteArrayOutputStream baos =
Reader reader = new InputStreamReader(new ByteArrayInputStream(baos.toByteArray()));
一个更简单的解决方案是检查缓冲区的内容。
assertEquals(expected, baos.toString().trim());
ByteArrayInputStream
开始,就不会有这个问题。对于OP的用例,这并不重要。 - Stephen COutputStream
实现.. 它需要与文件中的某些内容进行比较。 - Queequeg