@Test public void testReadByteByByte() throws IOException { ByteArrayInputStream bais = new ByteArrayInputStream(DATA); SnifferInputStream sis = new SnifferInputStream(snifferSocket, bais); int read; ByteArrayOutputStream baos = new ByteArrayOutputStream(); while ((read = sis.read()) != -1) { baos.write(read); } verify(snifferSocket, times(4)).logSocket(anyLong(), eq(1), eq(0)); verify(snifferSocket).logSocket(anyLong(), eq(0), eq(0)); }
@Override public int read() throws IOException { snifferSocket.checkConnectionAllowed(0); long start = System.currentTimeMillis(); int bytesDown = 0; try { int read = delegate.read(); if (read != -1) bytesDown = 1; return read; } finally { sleepIfRequired(bytesDown); snifferSocket.logSocket(System.currentTimeMillis() - start, bytesDown, 0); } }
SnifferInputStream extends InputStream { @Override public int read() throws IOException { snifferSocket.checkConnectionAllowed(0); long start = System.currentTimeMillis(); int bytesDown = 0; try { int read = delegate.read(); if (read != -1) bytesDown = 1; return read; } finally { sleepIfRequired(bytesDown); snifferSocket.logSocket(System.currentTimeMillis() - start, bytesDown, 0); } } }
SnifferInputStream extends InputStream { @Override public int read() throws IOException { snifferSocket.checkConnectionAllowed(0); long start = System.currentTimeMillis(); int bytesDown = 0; try { int read = delegate.read(); if (read != -1) bytesDown = 1; return read; } finally { sleepIfRequired(bytesDown); snifferSocket.logSocket(System.currentTimeMillis() - start, bytesDown, 0); } } SnifferInputStream(SnifferSocketImpl snifferSocket, InputStream delegate); }
SnifferInputStream extends InputStream { @Override public int read() throws IOException { snifferSocket.checkConnectionAllowed(0); long start = System.currentTimeMillis(); int bytesDown = 0; try { int read = delegate.read(); if (read != -1) bytesDown = 1; return read; } finally { sleepIfRequired(bytesDown); snifferSocket.logSocket(System.currentTimeMillis() - start, bytesDown, 0); } } SnifferInputStream(SnifferSocketImpl snifferSocket, InputStream delegate); @Override int read(); @Override int read(byte[] b); @Override int read(byte[] b, int off, int len); @Override long skip(long n); @Override int available(); @Override void close(); @Override void mark(int readlimit); @Override void reset(); @Override boolean markSupported(); }
SnifferInputStream extends InputStream { @Override public int read() throws IOException { snifferSocket.checkConnectionAllowed(0); long start = System.currentTimeMillis(); int bytesDown = 0; try { int read = delegate.read(); if (read != -1) bytesDown = 1; return read; } finally { sleepIfRequired(bytesDown); snifferSocket.logSocket(System.currentTimeMillis() - start, bytesDown, 0); } } SnifferInputStream(SnifferSocketImpl snifferSocket, InputStream delegate); @Override int read(); @Override int read(byte[] b); @Override int read(byte[] b, int off, int len); @Override long skip(long n); @Override int available(); @Override void close(); @Override void mark(int readlimit); @Override void reset(); @Override boolean markSupported();  }