/** * Tests a <code>BoundedOutputStream</code> operating in unbounded mode. * * @throws IOException should not happen */ @Test public void testUnboundedStream() throws IOException { BoundedOutputStream bout = new BoundedOutputStream(new SinkOutputStream(), -1); assert 0 == bout.getProcessedBytes(); assert Long.MAX_VALUE == bout.getRemainingBytes(); assert -1 == bout.getAllowedBytes(); bout.write(0); assert 1 == bout.getProcessedBytes(); assert Long.MAX_VALUE == bout.getRemainingBytes(); assert -1 == bout.getAllowedBytes(); bout.write(new byte[1]); assert 2 == bout.getProcessedBytes(); assert Long.MAX_VALUE == bout.getRemainingBytes(); assert -1 == bout.getAllowedBytes(); bout.write(new byte[2], 0, 2); assert 4 == bout.getProcessedBytes(); assert Long.MAX_VALUE == bout.getRemainingBytes(); assert -1 == bout.getAllowedBytes(); } }
BoundedOutputStream bout = new BoundedOutputStream(new SinkOutputStream(), 4); assert 0 == bout.getProcessedBytes(); assert 4 == bout.getRemainingBytes(); assert 4 == bout.getAllowedBytes(); assert 1 == bout.getProcessedBytes(); assert 3 == bout.getRemainingBytes(); assert 4 == bout.getAllowedBytes(); assert 2 == bout.getProcessedBytes(); assert 2 == bout.getRemainingBytes(); assert 4 == bout.getAllowedBytes(); assert 4 == bout.getProcessedBytes(); assert 0 == bout.getRemainingBytes(); assert 4 == bout.getAllowedBytes(); assert 4 == bout.getProcessedBytes(); assert 0 == bout.getRemainingBytes(); assert 4 == bout.getAllowedBytes(); bout.write(new byte[6]); assert 4 == bout.getProcessedBytes(); assert 0 == bout.getRemainingBytes(); assert 4 == bout.getAllowedBytes();