FragmentStream { public boolean isComplete(int tillIndex) { if (tillIndex < 0) { throw new IllegalArgumentException("Cannot check stream for completnes with negative index: " + tillIndex); } for (int i = 0; i < tillIndex; i++) { if (!fragmentByteMap.containsKey(i)) { return false; } } return true; } FragmentStream(int intendedSize); boolean canInsertByteArray(byte[] bytesToAdd, int offset); void insertByteArray(byte[] bytesToAdd, int offset); boolean isComplete(int tillIndex); byte[] getCompleteFilledStream(byte fillingByte); byte[] getCompleteTruncatedStream();  }
@Test public void testIsComplete() { stream.insertByteArray(new byte[] { 1, 2, 3 }, 0); stream.insertByteArray(new byte[] { 7, 8, 9, 10 }, 6); assertFalse(stream.isComplete(4)); assertFalse(stream.isComplete(10)); assertTrue(stream.isComplete(3)); assertTrue(stream.isComplete(1)); assertTrue(stream.isComplete(0)); }