我想测试我写入OutputStream
(文件OuputStream)的字节与我从相同的InputStream
中读取的字节相同。如何从InputStream中读取字节?
测试看起来像
@Test
public void testStreamBytes() throws PersistenceException, IOException, ClassNotFoundException {
String uniqueId = "TestString";
final OutputStream outStream = fileService.getOutputStream(uniqueId);
new ObjectOutputStream(outStream).write(uniqueId.getBytes());
final InputStream inStream = fileService.getInputStream(uniqueId);
}
我意识到InputStream
没有getBytes()
。
如何测试像
assertEquals(inStream.getBytes(), uniqueId.getBytes())
谢谢
我相信IOUtils是commons-io,是不是'Java'提供了类似的东西? – daydreamer
@daydreamer是的,使用'ByteArrayOutputStream'。 – oldrinb