// see end-of-stream marker information in devdocs/chunk-format.md
// finishV1 writes a v1 end-of-stream record to the bitstream
485883
func finishV1(w *bstream) {
	w.writeBits(0x0f, 4)
	w.writeBits(0xffffffff, 32)
	w.writeBit(zero)
}
927227
func (r *ResourceDefinition) Finalize() {
	meta := r.Metadata["swagger:generate"]
	r.IterateFileServers(func(f *FileServerDefinition) error {
		if meta != nil {
			if _, ok := f.Metadata["swagger:generate"]; !ok {
				f.Metadata["swagger:generate"] = meta
			}
		}
		f.Finalize()
		return nil
	})
	r.IterateActions(func(a *ActionDefinition) error {
		if meta != nil {
			if _, ok := a.Metadata["swagger:generate"]; !ok {
				a.Metadata["swagger:generate"] = meta
			}
		}
		a.Finalize()
		return nil
	})
}
1308662
func (fbo *folderBranchOps) finalizeResolution(ctx context.Context,
	lState *kbfssync.LockState, md *RootMetadata, bps blockPutState,
	newOps []op, blocksToDelete []kbfsblock.ID) error {
	// Take the writer lock.
	fbo.mdWriterLock.Lock(lState)
	defer fbo.mdWriterLock.Unlock(lState)
	return fbo.finalizeResolutionLocked(
		ctx, lState, md, bps, newOps, blocksToDelete)
}
152885
func (t *http2Server) finishStream(s *Stream, rst bool, rstCode http2.ErrCode, hdr *headerFrame, eosReceived bool) {
	oldState := t.deleteStream(s, eosReceived)
	// If the stream is already closed, then don't put trailing header to controlbuf.
	if oldState == streamDone {
		return
	}

	hdr.cleanup = &cleanupStream{
		streamID: s.id,
		rst:      rst,
		rstCode:  rstCode,
		onWrite:  func() {},
	}
	t.controlBuf.put(hdr)
}
763428
func (ctl *Controller) finishShard(c context.Context, shardID, processedCount int64, shardErr error) error {
	err := shardTxn(c, shardID, func(c context.Context, sh *shard) (save bool, err error) {
		runtime := clock.Now(c).Sub(sh.Created)
		switch {
		case shardErr == errJobAborted:
			logging.Warningf(c, "The job has been aborted, aborting the shard after it has been running %s", runtime)
			sh.State = State_ABORTED
			sh.Error = errJobAborted.Error()
		case shardErr != nil:
			logging.Errorf(c, "The shard processing failed in %s with error: %s", runtime, shardErr)
			sh.State = State_FAIL
			sh.Error = shardErr.Error()
		default:
			logging.Infof(c, "The shard processing finished successfully in %s", runtime)
			sh.State = State_SUCCESS
		}
		sh.ProcessedCount += processedCount
		return true, ctl.requestJobStateUpdate(c, sh.JobID, sh.ID)
	})
	return errors.Annotate(err, "when marking the shard as finished").Err()
}
1290551
func (b *Builder) Finish() (*FST, error) {
	root := b.frontier[0]

	// minimize nodes in the last word's suffix
	err := b.freezeTail(0)
	if err != nil {
		return nil, err
	}
	if root.InputCount < int64(b.minSuffixCount1) ||
		root.InputCount < int64(b.minSuffixCount2) || root.NumArcs == 0 {
		if b.fst.emptyOutput == nil {
			return nil, nil
		} else if b.minSuffixCount1 > 0 || b.minSuffixCount2 > 0 {
			// emtpy string got pruned
			return nil, nil
		}
	} else {
		if b.minSuffixCount2 != 0 {
			err = b.compileAllTargets(root, b.lastInput.Length())
			if err != nil {
				return nil, err
			}
		}
	}
	d, err := b.compileNode(root, b.lastInput.Length())
	if err != nil {
		return nil, err
	}
	err = b.fst.finish(d.node)
	if err != nil {
		return nil, err
	}

	if b.doPackFST {
		n := b.fst.NodeCount() / 4
		if n < 10 {
			n = 10
		}
		return b.fst.pack(3, int(n), b.acceptableOverheadRatio)
	}
	return b.fst, nil
}
837213
func (pb *paramsBuffer) End() string {
	s := pb.out.String()
	pb.lk.Unlock()
	return s
}
974821
func (sd *SignedData) Finish() ([]byte, error) {
	sd.sd.Certificates = marshalCertificates(sd.certs)
	inner, err := asn1.Marshal(sd.sd)
	if err != nil {
		return nil, err
	}
	outer := contentInfo{
		ContentType: oidSignedData,
		Content:     asn1.RawValue{Class: 2, Tag: 0, Bytes: inner, IsCompound: true},
	}
	return asn1.Marshal(outer)
}
418206
func (kt *SharedKeybaseTransport) Finalize() {
	kt.mutex.Lock()
	defer kt.mutex.Unlock()
	kt.transport = kt.stagedTransport
	kt.stagedTransport = nil
}
834762
func (buf *Buffer) End() error {
	if buf.pos >= buf.size {
		return nil
	}

	buf.pos = buf.size
	return buf.Refresh()
}
680249
func (w *SSTFileWriter) Finish() error {
	var cErr *C.char
	C.rocksdb_sstfilewriter_finish(w.c, &cErr)
	if cErr != nil {
		defer C.free(unsafe.Pointer(cErr))
		return errors.New(C.GoString(cErr))
	}
	return nil
}
721110
func (m *Metrics) Finalize(rateLimit uint, totalQueries uint) {
	if rateLimit == 0 {
		rateLimit = 1
	}

	for _, s := range m.TimeMetrics {
		sort.Float64s(s.vals)
		cnt := len(s.vals)

		s.Min = Float64(s.vals[0])
		s.Med = Float64(s.vals[(50*cnt)/100]) // median = 50th percentile
		s.P95 = Float64(s.vals[(95*cnt)/100])
		s.Max = Float64(s.vals[cnt-1])
		s.Sum = (s.Sum * float64(rateLimit)) + s.outlierSum
		s.Avg = Float64(s.Sum / float64(totalQueries))
	}

	for _, s := range m.NumberMetrics {
		sort.Sort(byUint64(s.vals))
		cnt := len(s.vals)

		s.Min = Uint64(s.vals[0])
		s.Med = Uint64(s.vals[(50*cnt)/100]) // median = 50th percentile
		s.P95 = Uint64(s.vals[(95*cnt)/100])
		s.Max = Uint64(s.vals[cnt-1])
		s.Sum = (s.Sum * uint64(rateLimit)) + s.outlierSum
		s.Avg = Uint64(s.Sum / uint64(totalQueries))
	}

	for _, s := range m.BoolMetrics {
		s.Sum = (s.Sum * uint64(rateLimit)) + s.outlierSum
	}
}
535003
func (mr *MockBytesMockRecorder) Finalizer() *gomock.Call {
	return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Finalizer", reflect.TypeOf((*MockBytes)(nil).Finalizer))
}
1138445
func (d *Decoder) Finish() ([]byte, error) {
	// If we've ever seen an error, just return that again.
	if d.err != nil {
		return nil, d.err
	}
	if int64(len(d.buf)) >= d.packetLen {
		panic("decoder buffer has more bytes than expected")
	}
	// If we've been truncated at a packet boundary, this open will fail on a
	// simple length check. If we've been truncated in the middle of a packet,
	// this open will fail to validate.
	var plaintext []byte
	plaintext, d.err = d.openOnePacket(int64(len(d.buf)))
	return plaintext, d.err
}
914921
func (b *Builder) Finish() error {
	b.flush()
	b.building.Wait()

	if b.buildError != nil {
		for tmp := range b.finishedShards {
			os.Remove(tmp)
		}
		return b.buildError
	}

	for tmp, final := range b.finishedShards {
		if err := os.Rename(tmp, final); err != nil {
			b.buildError = err
		}
	}

	if b.nextShardNum > 0 {
		b.deleteRemainingShards()
	}
	return b.buildError
}
773409
func (e *Encoder) Finish() []byte {
	if int64(len(e.buf)) >= e.plaintextChunkLen {
		panic("encoder buffer has more bytes than expected")
	}
	packet := e.sealOnePacket(int64(len(e.buf)))
	return packet
}
131474
func (t *DryRunTarget) Finish(taskMap map[string]Task) error {
	return t.PrintReport(taskMap, t.out)
}