FixedLengthByteArraySortedSet extends AbstractByteArraySortedSet { @Override public void writeTo( @NotNull final OutputStream os) throws IOException { assert elements.first().getSizeInBytes() <= Integer.MAX_VALUE; os.write(Ints.toByteArray((int) elements.first().getSizeInBytes())); os.write(Ints.toByteArray(elements.size())); long elementSize = -1; for (UnsignedByteArray e : elements) { if (elementSize == -1) elementSize = e.getSizeInBytes(); assert elementSize == e.getSizeInBytes() : "Variable size"; e.writeTo(os); } } FixedLengthByteArraySortedSet(
            final SortedSet<UnsignedByteArray> elements); @Override long getSizeInBytes(); @Override void writeTo(
            @NotNull
            final OutputStream os); @Override String toString();  }
@Test(expected = AssertionError.class) public void expectFixed() throws IOException { final SortedSet<UnsignedByteArray> elements = new TreeSet<>(); elements.add(from(1)); elements.add(from(1L)); new FixedLengthByteArraySortedSet(elements) .writeTo(new ByteArrayOutputStream()); }