@Test @Features("issues/219") public void testWriteByteArrayThreeTcpPackets() throws IOException { int backup = snifferSocket.sendBufferSize; try { snifferSocket.sendBufferSize = 5; ByteArrayOutputStream baos = new ByteArrayOutputStream(); SnifferOutputStream sos = new SnifferOutputStream(snifferSocket, baos); byte[] THREE_BYTES_CHUNK = {1, 2, 3}; byte[] ELEVEN_BYTES_CHUNK = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; byte[] ALL_DATA = new byte[THREE_BYTES_CHUNK.length + ELEVEN_BYTES_CHUNK.length]; System.arraycopy(THREE_BYTES_CHUNK, 0, ALL_DATA, 0, THREE_BYTES_CHUNK.length); System.arraycopy(ELEVEN_BYTES_CHUNK, 0, ALL_DATA, THREE_BYTES_CHUNK.length, ELEVEN_BYTES_CHUNK.length); sos.write(THREE_BYTES_CHUNK); sos.write(ELEVEN_BYTES_CHUNK); verify(snifferSocket, times(2)).checkConnectionAllowed(eq(0)); verify(snifferSocket).checkConnectionAllowed(eq(1)); verify(snifferSocket).checkConnectionAllowed(eq(2)); verify(snifferSocket).logSocket(anyLong(), eq(0), eq(THREE_BYTES_CHUNK.length)); verify(snifferSocket).logSocket(anyLong(), eq(0), eq(ELEVEN_BYTES_CHUNK.length)); verifyNoMoreInteractions(snifferSocket); assertArrayEquals(ALL_DATA, baos.toByteArray()); } finally { snifferSocket.sendBufferSize = backup; } }
@Override public void write(int b) throws IOException { snifferSocket.checkConnectionAllowed(0); long start = System.currentTimeMillis(); try { delegate.write(b); } finally { sleepIfRequired(1); snifferSocket.logSocket(System.currentTimeMillis() - start, 0, 1); } }
SnifferOutputStream extends OutputStream { @Override public void write(int b) throws IOException { snifferSocket.checkConnectionAllowed(0); long start = System.currentTimeMillis(); try { delegate.write(b); } finally { sleepIfRequired(1); snifferSocket.logSocket(System.currentTimeMillis() - start, 0, 1); } } }
SnifferOutputStream extends OutputStream { @Override public void write(int b) throws IOException { snifferSocket.checkConnectionAllowed(0); long start = System.currentTimeMillis(); try { delegate.write(b); } finally { sleepIfRequired(1); snifferSocket.logSocket(System.currentTimeMillis() - start, 0, 1); } } SnifferOutputStream(SnifferSocketImpl snifferSocket, OutputStream delegate); }
SnifferOutputStream extends OutputStream { @Override public void write(int b) throws IOException { snifferSocket.checkConnectionAllowed(0); long start = System.currentTimeMillis(); try { delegate.write(b); } finally { sleepIfRequired(1); snifferSocket.logSocket(System.currentTimeMillis() - start, 0, 1); } } SnifferOutputStream(SnifferSocketImpl snifferSocket, OutputStream delegate); @Override void write(int b); @Override void write(byte[] b); @Override void write(byte[] b, int off, int len); @Override void flush(); @Override void close(); }
SnifferOutputStream extends OutputStream { @Override public void write(int b) throws IOException { snifferSocket.checkConnectionAllowed(0); long start = System.currentTimeMillis(); try { delegate.write(b); } finally { sleepIfRequired(1); snifferSocket.logSocket(System.currentTimeMillis() - start, 0, 1); } } SnifferOutputStream(SnifferSocketImpl snifferSocket, OutputStream delegate); @Override void write(int b); @Override void write(byte[] b); @Override void write(byte[] b, int off, int len); @Override void flush(); @Override void close();  }