The 16 least significant bits of the 32-bit cookie have value SERIAL_COOKIE. In that case, the 16 most significant bits of the 32-it cookie are used to store the number of containers minus 1. That is, if you shift right by 16 the cookie and add 1, you get the number of containers. Let size be the number of containers. Then we store (size + 7) / 8 bytes, following the initial 64 bits,
The sample Java code starts the isRun bitmap immediately after the 32-bit cookie (so after the first 32-bits), whereas the spec, in the paragraph quoted above, says it should come after the first 64-bits.
int startOffset = 0;
boolean hasrun = hasRunContainer();
if (hasrun) {
out.writeInt(Integer.reverseBytes(SERIAL_COOKIE | ((size - 1) << 16)));
byte[] bitmapOfRunContainers = new byte[(size + 7) / 8];
for (int i = 0; i < size; ++i) {
if (this.values[i] instanceof RunContainer) {
bitmapOfRunContainers[i / 8] |= (1 << (i % 8));
}
}
out.write(bitmapOfRunContainers);
The sample Java code starts the isRun bitmap immediately after the 32-bit cookie (so after the first 32-bits), whereas the spec, in the paragraph quoted above, says it should come after the first 64-bits.