code: public long discharge(BitmapStorage container, long max) {
      	long index = 0;
      	while (true) {
      		if (index + getRunningLength() > max) {
      			final int offset = (int) (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 =(int) (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