docs: public void writeBundleStream(BundleStreamSource source, WritableByteChannel output) throws IOException {
      ByteBuffer buffer = ByteBuffer.allocateDirect(INITIAL_BUFFER);
  
      DBIDVar var = DBIDUtil.newVar();
      ByteBufferSerializer<?>[] serializers = null;
      loop: while(true) {
        BundleStreamSource.Event ev = source.nextEvent();
        switch(ev){
        case NEXT_OBJECT:
          if(serializers == null) {
            serializers = writeHeader(source, buffer, output);
          }
          if(serializers[0] != null) {
            if(!source.assignDBID(var)) {
              throw new AbortException("An object did not have an DBID assigned.");
            }
            DBID id = DBIDUtil.deref(var);
            @SuppressWarnings("unchecked")
            ByteBufferSerializer<DBID> ser = (ByteBufferSerializer<DBID>) serializers[0];
            int size = ser.getByteSize(id);
            buffer = ensureBuffer(size, buffer, output);
            ser.toByteBuffer(buffer, id);
          }
          for(int i = 1, j = 0; i < serializers.length; ++i, ++j) {
            @SuppressWarnings("unchecked")
            ByteBufferSerializer<Object> ser = (ByteBufferSerializer<Object>) serializers[i];
            int size = ser.getByteSize(source.data(j));
            buffer = ensureBuffer(size, buffer, output);
            ser.toByteBuffer(buffer, source.data(j));
          }
          break; // switch
        case META_CHANGED:
          if(serializers != null) {
            throw new AbortException("Meta changes are not supported, once the block header has been written.");
          }
          break; // switch
        case END_OF_STREAM:
          break loop;
        default:
          LOG.warning("Unknown bundle stream event. API inconsistent? " + ev);
          break; // switch
        }
      }
      if(buffer.position() > 0) {
        flushBuffer(buffer, output);
      }
    }