code: public int discharge(BitmapStorage32 container, int max) {
        int index = 0;
        while (true) {
          if (index + getRunningLength() > max) {
            final int offset = max - index;
            container.addStreamOfEmptyWords(getRunningBit(), offset);
            this.brlw.RunningLength -= offset;
            return max;
          }
          container.addStreamOfEmptyWords(getRunningBit(), getRunningLength());
          index += getRunningLength();
          if (getNumberOfLiteralWords() + index > max) {
            final int offset = max - index;
            writeLiteralWords(offset, container);
            this.brlw.RunningLength = 0;
            this.brlw.NumberOfLiteralWords -= offset;
            this.literalWordStartPosition += offset;
            return max;
          }
          writeLiteralWords(getNumberOfLiteralWords(), container);
          index += getNumberOfLiteralWords();
          if(!next()) break;
        }
        return index;
      }
docs: Write out up to max words, returns how many were written
  
  @param container target for writes
  @param max       maximal number of writes
  @return how many written