@Test(expected = IllegalArgumentException.class) public void shouldFailIfSourceIsGreaterThan255() throws Exception { pool.add(256, "Hello".getBytes()); }
public void add(int source, byte[] event) { writeLock.lock(); try { if (source < 0 || source > 255) { throw new IllegalArgumentException("Source needs to be in the range 0 to 255, it was " + source); } if (event.length < 1 || event.length > 32) { throw new IllegalArgumentException("The length of the event need to be in the range 1 to 32, it was " + event.length); } size += event.length + 2; poolDigest.update(new byte[]{(byte) source, (byte) event.length}); poolDigest.update(event); } finally { writeLock.unlock(); } }
Pool { public void add(int source, byte[] event) { writeLock.lock(); try { if (source < 0 || source > 255) { throw new IllegalArgumentException("Source needs to be in the range 0 to 255, it was " + source); } if (event.length < 1 || event.length > 32) { throw new IllegalArgumentException("The length of the event need to be in the range 1 to 32, it was " + event.length); } size += event.length + 2; poolDigest.update(new byte[]{(byte) source, (byte) event.length}); poolDigest.update(event); } finally { writeLock.unlock(); } } }
Pool { public void add(int source, byte[] event) { writeLock.lock(); try { if (source < 0 || source > 255) { throw new IllegalArgumentException("Source needs to be in the range 0 to 255, it was " + source); } if (event.length < 1 || event.length > 32) { throw new IllegalArgumentException("The length of the event need to be in the range 1 to 32, it was " + event.length); } size += event.length + 2; poolDigest.update(new byte[]{(byte) source, (byte) event.length}); poolDigest.update(event); } finally { writeLock.unlock(); } }  }
Pool { public void add(int source, byte[] event) { writeLock.lock(); try { if (source < 0 || source > 255) { throw new IllegalArgumentException("Source needs to be in the range 0 to 255, it was " + source); } if (event.length < 1 || event.length > 32) { throw new IllegalArgumentException("The length of the event need to be in the range 1 to 32, it was " + event.length); } size += event.length + 2; poolDigest.update(new byte[]{(byte) source, (byte) event.length}); poolDigest.update(event); } finally { writeLock.unlock(); } }  long size(); void add(int source, byte[] event); byte[] getAndClear(); }
Pool { public void add(int source, byte[] event) { writeLock.lock(); try { if (source < 0 || source > 255) { throw new IllegalArgumentException("Source needs to be in the range 0 to 255, it was " + source); } if (event.length < 1 || event.length > 32) { throw new IllegalArgumentException("The length of the event need to be in the range 1 to 32, it was " + event.length); } size += event.length + 2; poolDigest.update(new byte[]{(byte) source, (byte) event.length}); poolDigest.update(event); } finally { writeLock.unlock(); } }  long size(); void add(int source, byte[] event); byte[] getAndClear();  }