private static int discard(LinkedList<Fragment> src, int cut, int poffset) {

        int offset = poffset;
        int postend, c, l;
        // i think this discards everything up to "cut"
        // a fragment may have to be split if it
        // overlaps "cut"
        for (Iterator<Fragment> iter = src.iterator(); iter.hasNext();) {
            final Fragment s = iter.next();
            if (cut <= s.start + offset) {
                break;
            }

            postend = offset + s.start + s.len();
            if (postend <= cut) {
                // this one is discarded
                offset += s.start + s.len() - s.end;
                iter.remove();
            } else {
                // partial discarding, move the content of s.data so that it
                // doesn't overlap cut
                c = cut - offset;
                if (s.end < c) {
                    c = s.end;
                }
                l = cut - offset - s.start;
                if (s.len() < l) {
                    l = s.len();
                }

                offset += s.start + l - c;
                s.start = c;
                s.len(s.len() - l);

                // s.data = s.data + l;
                // this should work, but doesnt, bug?
                // s.data = Arrays.copyOfRange(s.data, l, s.len());
                s.offset += l;
                // s.data = Arrays.copyOfRange(s.data, l, s.data.length);
                // no more needs to be discarded
                break;
            }
        }
        return offset;
    }