// NextPart implements MultipartReader.
185059
func (r *multipartReader) NextPart() (*Entity, error) {
	p, err := r.r.NextPart()
	if err != nil {
		return nil, err
	}
	return New(Header{mapToHeader(p.Header)}, p)
}
408470
func (iter *MultiEncodedObjectIter) Next() (plumbing.EncodedObject, error) {
	if len(iter.iters) == 0 {
		return nil, io.EOF
	}

	obj, err := iter.iters[0].Next()
	if err == io.EOF {
		iter.iters[0].Close()
		iter.iters = iter.iters[1:]
		return iter.Next()
	}

	return obj, err
}
689486
func (f *chunk) nextPart() (io.ReadSeeker, error) {
	type readerAtSeeker interface {
		io.ReaderAt
		io.ReadSeeker
	}
	switch r := f.fd.(type) {
	case readerAtSeeker:
		var sectionSize int64
		var err error
		leftSize := f.size - f.cur
		if leftSize >= int64(f.partSize) {
			sectionSize = int64(f.partSize)
		} else if leftSize > 0 {
			sectionSize = f.size - f.cur
		} else {
			err = io.EOF
		}
		seekReader := io.NewSectionReader(r, f.cur, sectionSize)
		f.cur += sectionSize
		return seekReader, err
	case io.Reader:
		buf := make([]byte, segmentSize)
		var n, lenBuf int
		var err error
		var chunk []byte
		for {
			n, _ = r.Read(buf)
			if n == 0 {
				if lenBuf == 0 {
					err = io.EOF
				}
				break
			}
			lenBuf = lenBuf + n
			chunk = append(chunk, buf...)
			if lenBuf == f.partSize {
				break
			}
		}
		partBody := bytes.NewReader(chunk[:lenBuf])
		return partBody, err
	default:
		return nil, errors.New("file does not support read")
	}
}
234973
func (itr *mergeSegmentIterator) next() (s0, s1 *rowSegment) {
	// Find current segments.
	if len(itr.a0) > 0 {
		s0 = &itr.a0[0]
	}
	if len(itr.a1) > 0 {
		s1 = &itr.a1[0]
	}

	// Return if either or both are nil.
	if s0 == nil && s1 == nil {
		return
	} else if s0 == nil {
		itr.a1 = itr.a1[1:]
		return
	} else if s1 == nil {
		itr.a0 = itr.a0[1:]
		return
	}

	// Otherwise determine which is first.
	if s0.shard < s1.shard {
		itr.a0 = itr.a0[1:]
		return s0, nil
	} else if s0.shard > s1.shard {
		itr.a1 = itr.a1[1:]
		return s1, nil
	}

	// Return both if shards are equal.
	itr.a0, itr.a1 = itr.a0[1:], itr.a1[1:]
	return s0, s1
}
112175
func sequencePart(node string) (int, error) {
	if node == "" {
		return 0, errors.New("node cannot be blank")
	}
	matches := sequenceRe.FindStringSubmatch(node)
	if len(matches) != 2 {
		return 0, fmt.Errorf("invalid node: %s", node)
	}
	res, err := strconv.Atoi(matches[1])
	if err != nil {
		return 0, fmt.Errorf("invalid sequence part: %s", matches[1])
	}
	return res, nil
}
935227
func (ii *intIterator) Next() uint32 {
	x := uint32(ii.iter.next()) | ii.hs
	if !ii.iter.hasNext() {
		ii.pos = ii.pos + 1
		ii.init()
	}
	return x
}
1317588
func (r *Reader) NextPart() (*Part, error) {
	wrap, err := r.r.NextPart()
	if err != nil {
		return nil, err
	}
	p := &Part{
		Header: wrap.Header,
		Root:   false,
	}

	contentId := parseContentId(p.Header.Get("Content-Id"))
	if r.start != "" && r.start == contentId {
		if r.rootRead {
			return nil, ErrDupRoot
		} else {
			p.Root = true
			r.rootRead = true
		}
	} else if !r.rootRead && r.start == "" {
		p.Root = true
		r.rootRead = true
	}
	p.r = wrap

	switch strings.ToLower(p.Header.Get("Content-Transfer-Encoding")) {
	case "base64":
		p.Header.Del("Content-Transfer-Encoding")
		p.r = base64.NewDecoder(base64.StdEncoding, p.r)
		break
		// TODO binary reader
	}
	// TODO SkipMatch

	return p, nil
}
636510
func (i *PostingsIterator) nextDocNumAtOrAfter(atOrAfter uint64) (uint64, bool, error) {
	if i.normBits1Hit != 0 {
		if i.docNum1Hit == DocNum1HitFinished {
			return 0, false, nil
		}
		if i.docNum1Hit < atOrAfter {
			// advanced past our 1-hit
			i.docNum1Hit = DocNum1HitFinished // consume our 1-hit docNum
			return 0, false, nil
		}
		docNum := i.docNum1Hit
		i.docNum1Hit = DocNum1HitFinished // consume our 1-hit docNum
		return docNum, true, nil
	}

	if i.Actual == nil || !i.Actual.HasNext() {
		return 0, false, nil
	}

	if i.postings == nil || i.postings.postings == i.ActualBM {
		return i.nextDocNumAtOrAfterClean(atOrAfter)
	}

	n := i.Actual.Next()
	for uint64(n) < atOrAfter && i.Actual.HasNext() {
		n = i.Actual.Next()
	}
	if uint64(n) < atOrAfter {
		// couldn't find anything
		return 0, false, nil
	}
	allN := i.all.Next()

	nChunk := n / i.postings.sb.chunkFactor

	// when allN becomes >= to here, then allN is in the same chunk as nChunk.
	allNReachesNChunk := nChunk * i.postings.sb.chunkFactor

	// n is the next actual hit (excluding some postings), and
	// allN is the next hit in the full postings, and
	// if they don't match, move 'all' forwards until they do
	for allN != n {
		// we've reached same chunk, so move the freq/norm/loc decoders forward
		if i.includeFreqNorm && allN >= allNReachesNChunk {
			err := i.currChunkNext(nChunk)
			if err != nil {
				return 0, false, err
			}
		}

		allN = i.all.Next()
	}

	if i.includeFreqNorm && (i.currChunk != nChunk || i.currChunkFreqNorm == nil) {
		err := i.loadChunk(int(nChunk))
		if err != nil {
			return 0, false, fmt.Errorf("error loading chunk: %v", err)
		}
	}

	return uint64(n), true, nil
}
1214699
func (r *selectResult) Next(ctx context.Context, chk *chunk.Chunk) error {
	chk.Reset()
	for !chk.IsFull() {
		if r.selectResp == nil || r.respChkIdx == len(r.selectResp.Chunks) {
			err := r.getSelectResp()
			if err != nil || r.selectResp == nil {
				return err
			}
		}
		err := r.readRowsData(chk)
		if err != nil {
			return err
		}
		if len(r.selectResp.Chunks[r.respChkIdx].RowsData) == 0 {
			r.respChkIdx++
		}
	}
	return nil
}
1208594
func (d *ManyToOneEnvelope) Next() *events.Envelope {
	data := d.d.Next()
	return (*events.Envelope)(data)
}
1359604
func (r *importReader) nextByte(skipSpace bool) byte {
	c := r.peekByte(skipSpace)
	r.peek = 0
	return c
}
821683
func (s *Selection) NextAllMatcher(m Matcher) *Selection {
	return filterAndPush(s, getSiblingNodes(s.Nodes, siblingNextAll, nil, nil), m)
}
1190099
func (e *ByteIntervalElement) Next() *ByteIntervalElement {
	if p := e.next; e.list != nil && p != &e.list.root {
		return p
	}
	return nil
}
737548
func (d *doubleIter) nextTo() (err error) {
	d.to.current, err = d.to.iter.Next()
	return turnEOFIntoNil(err)
}
1045408
func (or *OpaqueReader) Next() (op *OpaquePacket, err error) {
	tag, _, contents, err := readHeader(or.r)
	if err != nil {
		return
	}
	op = &OpaquePacket{Tag: uint8(tag), Reason: err}
	err = op.parse(contents)
	if err != nil {
		consumeAll(contents)
	}
	return
}
657508
func (i *PostingsIterator) nextAtOrAfter(atOrAfter uint64) (segment.Posting, error) {
	docNum, exists, err := i.nextDocNumAtOrAfter(atOrAfter)
	if err != nil || !exists {
		return nil, err
	}

	i.next = Posting{} // clear the struct
	rv := &i.next
	rv.docNum = docNum

	if !i.includeFreqNorm {
		return rv, nil
	}

	var normBits uint64
	var hasLocs bool

	rv.freq, normBits, hasLocs, err = i.readFreqNormHasLocs()
	if err != nil {
		return nil, err
	}

	rv.norm = math.Float32frombits(uint32(normBits))

	if i.includeLocs && hasLocs {
		// prepare locations into reused slices, where we assume
		// rv.freq >= "number of locs", since in a composite field,
		// some component fields might have their IncludeTermVector
		// flags disabled while other component fields are enabled
		if cap(i.nextLocs) >= int(rv.freq) {
			i.nextLocs = i.nextLocs[0:rv.freq]
		} else {
			i.nextLocs = make([]Location, rv.freq, rv.freq*2)
		}
		if cap(i.nextSegmentLocs) < int(rv.freq) {
			i.nextSegmentLocs = make([]segment.Location, rv.freq, rv.freq*2)
		}
		rv.locs = i.nextSegmentLocs[:0]

		numLocsBytes, err := i.locReader.ReadUvarint()
		if err != nil {
			return nil, fmt.Errorf("error reading location numLocsBytes: %v", err)
		}

		j := 0
		startBytesRemaining := i.locReader.Len() // # bytes remaining in the locReader
		for startBytesRemaining-i.locReader.Len() < int(numLocsBytes) {
			err := i.readLocation(&i.nextLocs[j])
			if err != nil {
				return nil, err
			}
			rv.locs = append(rv.locs, &i.nextLocs[j])
			j++
		}
	}

	return rv, nil
}
1139964
func (p Path) Next(part string) Path {
	return Path(string(p) + pathSeparator + part)
}