public void output() throws Exception {
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
final CountingOutputStream o = new CountingOutputStream(bos);
o.write(1);
assertEquals(1, o.getBytesWritten());
o.write(new byte[] { 2, 3 });
assertEquals(3, o.getBytesWritten());
o.write(new byte[] { 2, 3, 4, 5, }, 2, 1);
assertEquals(4, o.getBytesWritten());
o.count(-1);
assertEquals(4, o.getBytesWritten());
o.count(-2);
assertEquals(2, o.getBytesWritten());
o.close();
assertArrayEquals(new byte[] { 1, 2, 3, 4 }, bos.toByteArray());
}
|