@Test public void testChunks() { ReserveBuffer buffer = new ReserveBuffer(16); byte[] input = new byte[32]; for (int i=0;i<input.length;i++) { input[i] = (byte)i; } byte[] result = buffer.update(input, 0, input.length); assertEquals(16, result.length); for (int i=0;i<result.length;i++) { assertEquals(i, result[i]); } }
public byte[] update(byte[] input, int offset, int inputLength) { int reserveToApply = Math.min(reserve.length, inputLength); int reserveToRelease = Math.max(reserveToApply - capacity(), 0); byte[] output = new byte[reserveToRelease + (inputLength - reserveToApply)]; read(output, 0, reserveToRelease); System.arraycopy(input, offset, output, reserveToRelease, inputLength - reserveToApply); write(input, offset + (inputLength - reserveToApply), reserveToApply); return output; }
ReserveBuffer { public byte[] update(byte[] input, int offset, int inputLength) { int reserveToApply = Math.min(reserve.length, inputLength); int reserveToRelease = Math.max(reserveToApply - capacity(), 0); byte[] output = new byte[reserveToRelease + (inputLength - reserveToApply)]; read(output, 0, reserveToRelease); System.arraycopy(input, offset, output, reserveToRelease, inputLength - reserveToApply); write(input, offset + (inputLength - reserveToApply), reserveToApply); return output; } }
ReserveBuffer { public byte[] update(byte[] input, int offset, int inputLength) { int reserveToApply = Math.min(reserve.length, inputLength); int reserveToRelease = Math.max(reserveToApply - capacity(), 0); byte[] output = new byte[reserveToRelease + (inputLength - reserveToApply)]; read(output, 0, reserveToRelease); System.arraycopy(input, offset, output, reserveToRelease, inputLength - reserveToApply); write(input, offset + (inputLength - reserveToApply), reserveToApply); return output; } ReserveBuffer(int sizeInBytes); }
ReserveBuffer { public byte[] update(byte[] input, int offset, int inputLength) { int reserveToApply = Math.min(reserve.length, inputLength); int reserveToRelease = Math.max(reserveToApply - capacity(), 0); byte[] output = new byte[reserveToRelease + (inputLength - reserveToApply)]; read(output, 0, reserveToRelease); System.arraycopy(input, offset, output, reserveToRelease, inputLength - reserveToApply); write(input, offset + (inputLength - reserveToApply), reserveToApply); return output; } ReserveBuffer(int sizeInBytes); byte[] update(byte[] input, int offset, int inputLength); void read(byte[] buffer, int offset, int length); int capacity(); int getAvailable(); }
ReserveBuffer { public byte[] update(byte[] input, int offset, int inputLength) { int reserveToApply = Math.min(reserve.length, inputLength); int reserveToRelease = Math.max(reserveToApply - capacity(), 0); byte[] output = new byte[reserveToRelease + (inputLength - reserveToApply)]; read(output, 0, reserveToRelease); System.arraycopy(input, offset, output, reserveToRelease, inputLength - reserveToApply); write(input, offset + (inputLength - reserveToApply), reserveToApply); return output; } ReserveBuffer(int sizeInBytes); byte[] update(byte[] input, int offset, int inputLength); void read(byte[] buffer, int offset, int length); int capacity(); int getAvailable();  }