code: @Override
    public void writeReference(final BAMIndexContent content) {
  
        if (content == null) {
            writeNullContent();
            return;
        }
  
        // write bins
  
        final BAMIndexContent.BinList bins = content.getBins();
        final int size = bins == null ? 0 : content.getNumberOfNonNullBins();
  
        if (size == 0) {
            writeNullContent();
            return;
        }
  
        //final List<Chunk> chunks = content.getMetaData() == null ? null
        //        : content.getMetaData().getMetaDataChunks();
        final BAMIndexMetaData metaData = content.getMetaData();
  
        codec.writeInt(size + ((metaData != null)? 1 : 0 ));
        // codec.writeInt(size);
        for (final Bin bin : bins) {   // note, bins will always be sorted
            if (bin.getBinNumber() == GenomicIndexUtil.MAX_BINS)
                continue;
            writeBin(bin);
        }
  
        // write metadata "bin" and chunks        
        if (metaData != null)
            writeChunkMetaData(metaData);
  
        // write linear index
  
        final LinearIndex linearIndex = content.getLinearIndex();
        final long[] entries = linearIndex == null ? null : linearIndex.getIndexEntries();
        final int indexStart = linearIndex == null ? 0 : linearIndex.getIndexStart();
        final int n_intv = entries == null ? indexStart : entries.length + indexStart;
        codec.writeInt(n_intv);
        if (entries == null) {
            return;
        }
        // since indexStart is usually 0, this is usually a no-op
        for (int i = 0; i < indexStart; i++) {
            codec.writeLong(0);
        }
        for (int k = 0; k < entries.length; k++) {
            codec.writeLong(entries[k]);
        }
        try {
            codec.getOutputStream().flush();
        } catch (final IOException e) {
            throw new SAMException("IOException in BinaryBAMIndexWriter reference " + content.getReferenceSequence(), e);
        }
    }
docs: Write this content as binary output