// finish flushes the file to disk and returns an open file ready for reading.
331852
func (b *bufWriter) finish() *os.File {
	b.flush()
	f := b.file
	f.Seek(0, 0)
	return f
}
675958
func (s *SeriesLong) Finish() {
	s.Lock()
	if !s.Finished {
		finishV2(&s.bw)
		s.Finished = true
	}
	s.Unlock()
}
205312
func (u readCloser) Close() error {
	if u.file != nil {
		return u.file.Close()
	}
	return nil
}
1301088
func (m *Message) Finish(success bool) {
	if success {
		m.Message.Finish()
	} else {
		m.Message.Requeue(-1)
	}
}
1098485
func (qs *QuietStatus) Finish() {
	console.Println(console.Colorize("Mirror", qs.accounter.Stat().String()))
}
1192236
func (w *BatchedFileWriter) Close() error {
	if w.compressOnClose {
		return w.compressAndCloseLog()
	}

	return w.file.Close()
}
458671
func (f *FileWriter) Close() error {
	if f.closed {
		return io.ErrClosedPipe
	}

	var lastBlock *hdfs.ExtendedBlockProto
	if f.blockWriter != nil {
		lastBlock = f.blockWriter.Block.GetB()

		// Close the blockWriter, flushing any buffered packets.
		err := f.finalizeBlock()
		if err != nil {
			return err
		}
	}

	completeReq := &hdfs.CompleteRequestProto{
		Src:        proto.String(f.name),
		ClientName: proto.String(f.client.namenode.ClientName),
		Last:       lastBlock,
	}
	completeResp := &hdfs.CompleteResponseProto{}

	err := f.client.namenode.Execute("complete", completeReq, completeResp)
	if err != nil {
		return &os.PathError{"create", f.name, err}
	}

	return nil
}
1221994
func (c *Client) end(err error, possiblyClosed bool) error {
	// close connection
	err = c.cleanup(err, true, true)

	// shutdown goroutines
	c.tomb.Kill(nil)

	// wait for all goroutines to exit
	// goroutines will send eventual errors through the callback
	c.tomb.Wait()

	// do cleanup
	return err
}
1328257
func (p *ProgressWriter) Close() (err error) {
	err = p.w.Close()
	p.stopProgress()
	return
}
448132
func (ctrl *Controller) Finish() {
	ctrl.T.Helper()

	ctrl.mu.Lock()
	defer ctrl.mu.Unlock()

	if ctrl.finished {
		ctrl.T.Fatalf("Controller.Finish was called more than once. It has to be called exactly once.")
	}
	ctrl.finished = true

	// If we're currently panicking, probably because this is a deferred call,
	// pass through the panic.
	if err := recover(); err != nil {
		panic(err)
	}

	// Check that all remaining expected calls are satisfied.
	failures := ctrl.expectedCalls.Failures()
	for _, call := range failures {
		ctrl.T.Errorf("missing call(s) to %v", call)
	}
	if len(failures) != 0 {
		ctrl.T.Fatalf("aborting test due to missing call(s)")
	}
}
131474
func (t *DryRunTarget) Finish(taskMap map[string]Task) error {
	return t.PrintReport(taskMap, t.out)
}
1240405
func (w *ResponseWriter) finish() {

	// Determine if we should Base64 encode the output
	contentType := w.response.Headers["Content-Type"]

	// Only encode text content types without base64 encoding
	w.response.IsBase64Encoded = !textContentTypesRegexp.MatchString(contentType)

	if w.response.IsBase64Encoded {
		w.response.Body = base64.StdEncoding.EncodeToString(w.output.Bytes())
	} else {
		w.response.Body = w.output.String()
	}
}
1074917
func (f *FileReader) Close() error {
	f.closed = true

	if f.blockReader != nil {
		f.blockReader.Close()
	}

	return nil
}
562332
func (d *decoder) finished() bool {
	return d.br.finished() && d.dt[d.state].nbBits > 0
}
547104
func (l *LocalFile) Done() {
	l.Close()
	if l.unlink {
		os.Remove(l.Name())
	}
}
1202578
func (s *storageImpl) FinishUpload(c context.Context, r *api.FinishUploadRequest) (resp *api.UploadOperation, err error) {
	defer func() { err = grpcutil.GRPCifyAndLogErr(c, err) }()

	if r.ForceHash != nil {
		if err := common.ValidateObjectRef(r.ForceHash, common.KnownHash); err != nil {
			return nil, errors.Annotate(err, "bad 'force_hash' field").Err()
		}
	}

	// Grab the corresponding operation and inspect its status.
	op, err := fetchOp(c, r.UploadOperationId)
	switch {
	case err != nil:
		return nil, err
	case op.Status != api.UploadStatus_UPLOADING:
		// Nothing to do if the operation is already closed or being verified.
		return op.ToProto(r.UploadOperationId), nil
	}

	// If the forced hash is provided by the (trusted) caller, we are almost done.
	// Just need to move the temp file to its final location based on this hash
	// and close the operation.
	if r.ForceHash != nil {
		mutated, err := s.finishAndForcedHash(c, op, r.ForceHash)
		if err != nil {
			return nil, err
		}
		return mutated.ToProto(r.UploadOperationId), nil
	}

	// Otherwise start the hash verification task, see verifyUploadTask below.
	mutated, err := op.Advance(c, func(c context.Context, op *upload.Operation) error {
		op.Status = api.UploadStatus_VERIFYING
		return s.tq.AddTask(c, &tq.Task{
			Payload: &tasks.VerifyUpload{UploadOperationId: op.ID},
			Title:   fmt.Sprintf("%d", op.ID),
		})
	})
	if err != nil {
		return nil, errors.Annotate(err, "failed to start the verification task").
			Tag(grpcutil.InternalTag).Err()
	}
	return mutated.ToProto(r.UploadOperationId), nil
}
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
}