/** * Serves all input stream to the output stream. * * @param inputStream * @param outputStream * @throws IOException */ public void serveMultiRangeStream(final InputStream inputStream, final OutputStream outputStream) throws IOException { int numberOfBufferReadBytes; byte[] buffer = new byte[BUFFER_SIZE]; while ((numberOfBufferReadBytes = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, numberOfBufferReadBytes); outputStream.flush(); Statistics.addBytesSent(numberOfBufferReadBytes); } }
Statistics.addBytesSent(numberOfBytesToServe);
@Test public void shouldIncrementAllByteCounters() { assertThat(Statistics.getBytesReceived(), is(equalTo(0l))); assertThat(Statistics.getBytesSent(), is(equalTo(0l))); Statistics.addBytesReceived(3); assertThat(Statistics.getBytesReceived(), is(equalTo(3l))); Statistics.addBytesReceived(5); assertThat(Statistics.getBytesReceived(), is(equalTo(8l))); Statistics.addBytesSent(2); assertThat(Statistics.getBytesSent(), is(equalTo(2l))); Statistics.addBytesSent(11); assertThat(Statistics.getBytesSent(), is(equalTo(13l))); Statistics.reset(); assertThat(Statistics.getBytesReceived(), is(equalTo(0l))); assertThat(Statistics.getBytesSent(), is(equalTo(0l))); }