// getWriter returns the current writer. It may be either
// the original connection or a wrapper.
345312
func (c *Conn) getWriter() io.Writer {
	if c.bufferedWriter != nil {
		return c.bufferedWriter
	}
	return c.conn
}
1237492
func GetNewTabWriter(output io.Writer) *tabwriter.Writer {
	return tabwriter.NewWriter(output, tabwriterMinWidth, tabwriterWidth, tabwriterPadding, tabwriterPadChar, tabwriterFlags)
}
599605
func BufWriter(w io.Writer) *bufio.Writer {
	if w, is := w.(*bufio.Writer); is {
		return w
	}

	return bufio.NewWriter(w)
}
872795
func (f *File) Writer(done chan struct{}, wg *sync.WaitGroup) (client.Writer, error) {
	return newWriter(), nil
}
912028
func (s *AmberEngine) ExecuteWriter(w io.Writer, filename string, layout string, bindingData interface{}) error {
	// re-parse the templates if reload is enabled.
	if s.reload {
		// locks to fix #872, it's the simplest solution and the most correct,
		// to execute writers with "wait list", one at a time.
		s.rmu.Lock()
		defer s.rmu.Unlock()
		if err := s.Load(); err != nil {
			return err
		}
	}

	if tmpl := s.fromCache(filename); tmpl != nil {
		return tmpl.Execute(w, bindingData)
	}

	return fmt.Errorf("Template with name %s doesn't exists in the dir", filename)
}
1127044
func (c *ExecCommand) GetWriters() (stdout io.WriteCloser, stderr io.WriteCloser) {
	return c.stdout, c.stderr
}
41410
func getColorableWriter() io.Writer {
	if strings.ToLower(os.Getenv("ConEmuANSI")) == "on" {
		// The ConEmu terminal is installed. Use it.
		return os.Stdout
	}

	const ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004

	h, err := syscall.GetStdHandle(syscall.STD_OUTPUT_HANDLE)
	if err != nil {
		return os.Stdout
	}
	var m uint32
	err = syscall.GetConsoleMode(h, &m)
	if err != nil {
		return os.Stdout
	}
	if m&ENABLE_VIRTUAL_TERMINAL_PROCESSING != 0 {
		return os.Stdout
	}
	return colorable.NewColorableStdout()
}
814374
func (m *multiWriter) Write(p []byte) (n int, err error) {
	// lock and make a local copy of available writers:
	getWriters := func() (writers []writerWrapper) {
		m.RLock()
		defer m.RUnlock()
		writers = make([]writerWrapper, 0, len(m.writers))
		for _, w := range m.writers {
			writers = append(writers, w)
		}

		// add the recent write chunk to the "instant replay" buffer
		// of the session, to be replayed to newly joining parties:
		m.lockedAddRecentWrite(p)
		return writers
	}

	// unlock and multiplex the write to all writers:
	for _, w := range getWriters() {
		n, err = w.Write(p)
		if err != nil {
			if w.closeOnError {
				return
			}
			continue
		}
		if n != len(p) {
			err = io.ErrShortWrite
			return
		}
	}
	return len(p), nil
}
199304
func Get(helper Helper, reader io.Reader, writer io.Writer) error {
	scanner := bufio.NewScanner(reader)

	buffer := new(bytes.Buffer)
	for scanner.Scan() {
		buffer.Write(scanner.Bytes())
	}

	if err := scanner.Err(); err != nil && err != io.EOF {
		return err
	}

	serverURL := strings.TrimSpace(buffer.String())
	if len(serverURL) == 0 {
		return NewErrCredentialsMissingServerURL()
	}

	username, secret, err := helper.Get(serverURL)
	if err != nil {
		return err
	}

	resp := Credentials{
		ServerURL: serverURL,
		Username:  username,
		Secret:    secret,
	}

	buffer.Reset()
	if err := json.NewEncoder(buffer).Encode(resp); err != nil {
		return err
	}

	fmt.Fprint(writer, buffer.String())
	return nil
}
1280469
func (e *Elasticsearch) Writer(done chan struct{}, wg *sync.WaitGroup) (client.Writer, error) {
	return setupWriter(e)
}
1239834
func NewWriter(w io.Writer) *Writer {
	return &Writer{
		Delimiter: '\t',
		UseCRLF:   false,
		w:         bufio.NewWriter(w),
	}
}
356940
func NewWriter(wr io.Writer) *Writer {
	return &Writer{writer: wr, lastElement: defaultLastElement, bf: &bytes.Buffer{}}
}
7543
func DownloadInWriter(ctx context.Context, c *http.Client, src string, dst io.Writer) (err error) {
	// Send request
	var resp *http.Response
	if resp, err = c.Get(src); err != nil {
		return errors.Wrapf(err, "astihttp: getting %s failed", src)
	}
	defer resp.Body.Close()

	// Validate status code
	if resp.StatusCode != http.StatusOK {
		return fmt.Errorf("astihttp: getting %s returned %d status code", src, resp.StatusCode)
	}

	// Copy
	if _, err = astiio.Copy(ctx, resp.Body, dst); err != nil {
		return errors.Wrapf(err, "astihttp: copying content from %s to writer failed", src)
	}
	return
}
460565
func GetPrint(wr io.Writer) error {
	tmpl, err := template.New("").Parse(versionTemplate)
	if err != nil {
		return err
	}

	v := struct {
		Version   string
		Codename  string
		GoVersion string
		BuildTime string
		Os        string
		Arch      string
	}{
		Version:   version.Version,
		Codename:  version.Codename,
		GoVersion: runtime.Version(),
		BuildTime: version.BuildDate,
		Os:        runtime.GOOS,
		Arch:      runtime.GOARCH,
	}

	return tmpl.Execute(wr, v)
}
1317020
func (c *connector) GetAttr(key string) interface{} {
	c.RLock()
	v := c.attrs[key]
	c.RUnlock()
	return v
}
39705
func NewWriter(addr string) (*Writer, error) {
	var err error
	w := new(Writer)
	w.CompressionLevel = flate.BestSpeed

	if w.conn, err = net.Dial("udp", addr); err != nil {
		return nil, err
	}
	if w.hostname, err = os.Hostname(); err != nil {
		return nil, err
	}

	w.Facility = path.Base(os.Args[0])

	return w, nil
}
418772
func (vp *ValidatingPool) GetWriter(fileIndex int64) (io.WriteCloser, error) {
	var wounds chan *Wound
	var woundsDone chan bool

	if vp.Wounds != nil {
		wounds = make(chan *Wound)
		originalWounds := wounds
		if vp.WoundsFilter != nil {
			wounds = vp.WoundsFilter(wounds)
		}

		woundsDone = make(chan bool)

		go func() {
			for wound := range originalWounds {
				if vp.Wounds != nil {
					vp.Wounds <- wound
				}
			}
			woundsDone <- true
		}()
	}

	if vp.hashGroups == nil {
		err := vp.makeHashGroups()
		if err != nil {
			return nil, errors.WithStack(err)
		}
		vp.sctx = wsync.NewContext(int(BlockSize))
	}

	w, err := vp.Pool.GetWriter(fileIndex)
	if err != nil {
		return nil, errors.WithStack(err)
	}

	hashGroup := vp.hashGroups[fileIndex]
	blockIndex := int64(0)
	file := vp.Container.Files[fileIndex]
	fileSize := file.Size

	validate := func(data []byte) error {
		weakHash, strongHash := vp.sctx.HashBlock(data)
		start := blockIndex * BlockSize
		size := ComputeBlockSize(fileSize, blockIndex)

		if blockIndex >= int64(len(hashGroup)) {
			if wounds == nil {
				err := fmt.Errorf("%s: too large (%d blocks, tried to look up hash %d)",
					file.Path, len(hashGroup), blockIndex)
				return errors.WithStack(err)
			}

			wounds <- &Wound{
				Kind:  WoundKind_FILE,
				Index: fileIndex,
				Start: start,
				End:   start + size,
			}
		} else {
			bh := hashGroup[blockIndex]

			if bh.WeakHash != weakHash {
				if wounds == nil {
					err := fmt.Errorf("%s: at block %d, expected weak hash %x, got %x", file.Path, blockIndex, bh.WeakHash, weakHash)
					return errors.WithStack(err)
				}

				wounds <- &Wound{
					Kind:  WoundKind_FILE,
					Index: fileIndex,
					Start: start,
					End:   start + size,
				}
			} else if !bytes.Equal(bh.StrongHash, strongHash) {
				if wounds == nil {
					err := fmt.Errorf("%s: at block %d, expected strong hash %x, got %x", file.Path, blockIndex, bh.StrongHash, strongHash)
					return errors.WithStack(err)
				}

				wounds <- &Wound{
					Kind:  WoundKind_FILE,
					Index: fileIndex,
					Start: start,
					End:   start + size,
				}
			} else {
				if wounds != nil {
					wounds <- &Wound{
						Kind:  WoundKind_CLOSED_FILE,
						Index: fileIndex,
						Start: start,
						End:   start + size,
					}
				}
			}
		}

		blockIndex++
		return nil
	}

	ocw := &onclose.Writer{
		Writer: w,
		BeforeClose: func() {
			if wounds != nil {
				close(wounds)
				<-woundsDone
			}
		},
		AfterClose: func() {
			if vp.OnClose != nil {
				vp.OnClose(fileIndex)
			}
		},
	}

	dw := &drip.Writer{
		Writer:   ocw,
		Buffer:   make([]byte, BlockSize),
		Validate: validate,
	}

	return dw, nil
}