* @param out where to write the serialized representation
*/
@Override
public void write(DataOutput out) throws IOException {
ByteArrayOutputStream b = new ByteArrayOutputStream();
BitOutputStream t = new BitOutputStream(b);
for (int i = 0; i < tf; i++) {
if (i == 0) {
t.writeGamma(positions[0]);
} else {
int pgap = positions[i] - positions[i - 1];
if (positions[i] <= 0 || pgap == 0) {
throw new RuntimeException("Error: invalid term positions " + toString());
}
t.writeGamma(pgap);
}
}
int bitOffset = t.getBitOffset();
int byteOffset = (int) t.getByteOffset();
t.padAndFlush();
t.close();
byte[] bytes = b.toByteArray();
out.writeInt(bytes.length);
out.writeShort(tf);
out.writeInt(byteOffset * 8 + bitOffset);