src/main/java/com/googlecode/javaewah/IteratorAggregation.java
protected static long discharge(final BitmapStorage container, IteratingRLW i, long max) {
        long counter = 0;
        while (i.size() > 0 && counter < max) {
            long l1 = i.getRunningLength();
            if (l1 > 0) {
                if (l1 + counter > max)
                    l1 = max - counter;
                container.addStreamOfEmptyWords(i.getRunningBit(), l1);
                counter += l1;
            }
            long l = i.getNumberOfLiteralWords();
            if (l + counter > max)
                l = max - counter;
            for (int k = 0; k < l; ++k) {
                container.addWord(i.getLiteralWordAt(k));
            }
            counter += l;
            i.discardFirstWords(l + l1);
        }
        return counter;
    }
protected static long discharge(final BitmapStorage container, IteratingRLW i, long max) {
        long counter = 0;
        while (i.size() > 0 && counter < max) {
            long l1 = i.getRunningLength();
            if (l1 > 0) {
                if (l1 + counter > max)
                    l1 = max - counter;
                container.addStreamOfEmptyWords(i.getRunningBit(), l1);
                counter += l1;
            }
            long l = i.getNumberOfLiteralWords();
            if (l + counter > max)
                l = max - counter;
            for (int k = 0; k < l; ++k) {
                container.addWord(i.getLiteralWordAt(k));
            }
            counter += l;
            i.discardFirstWords(l + l1);
        }
        return counter;
    }
Write out up to max words, returns how many were written

@param container target for writes
@param i         source of data
@param max       maximal number of writes
@return how many written