// readStream will read from the input stream (stdin or equivalent).
// TODO(russjones): At some point in the future if this becomes an issue, we
// should consider supporting echo = false.
968129
func (p *PAM) readStream(echo bool) (string, error) {
	reader := bufio.NewReader(p.stdin)
	text, err := reader.ReadString('\n')
	if err != nil {
		return "", trace.Wrap(err)
	}

	return text, nil
}
78846
func (s *stream) readVarUint32() (uint32, error) {
	var x, y uint32
	for {
		b, err := s.readByte()
		if err != nil {
			return 0, err
		}
		u := uint32(b)
		x |= (u & 0x7F) << y
		y += 7
		if ((u & 0x80) == 0) || (y == 35) {
			break
		}
	}

	return x, nil
}
727321
func (l *tomlLexer) read() rune {
	r := l.peek()
	if r == '\n' {
		l.endbufferLine++
		l.endbufferCol = 1
	} else {
		l.endbufferCol++
	}
	l.inputIdx++
	return r
}
74523
func ReadStdin(filename string) ([]byte, error) {
	if filename == "-" {
		return ioutil.ReadAll(os.Stdin)
	}
	return ioutil.ReadFile(filename)
}
327238
func (s *Stream) Read(p []byte) (int, error) {
	n, err := s.stream.Read(p)
	// TODO: push this down to a lower level for better accuracy.
	if s.conn.swarm.bwc != nil {
		s.conn.swarm.bwc.LogRecvMessage(int64(n))
		s.conn.swarm.bwc.LogRecvMessageStream(int64(n), s.Protocol(), s.Conn().RemotePeer())
	}
	// If we observe an EOF, this stream is now closed for reading.
	// If we're already closed for writing, this stream is now fully closed.
	if err == io.EOF {
		s.state.Lock()
		switch s.state.v {
		case streamCloseWrite:
			s.state.v = streamCloseBoth
			s.remove()
		case streamOpen:
			s.state.v = streamCloseRead
		}
		s.state.Unlock()
	}
	return n, err
}
533899
func ConsumeStdin() ([]byte, error) {
	file := os.Stdin
	buf := new(bytes.Buffer)
	_, err := buf.ReadFrom(file)
	if err != nil {
		return nil, fmt.Errorf("error reading stdin: %v", err)
	}
	return buf.Bytes(), nil
}
1008088
func (er *EchoRequest) ReadFrom(r io.Reader) (n int64, err error) {
	// The header of the echo request will be unmarshalled by the
	// previous read, so we need to read up to the end of the
	// buffer. So it is responsibility of the called to provide
	// fixed-length reader.
	er.Data, err = ioutil.ReadAll(r)
	if err != nil {
		return
	}

	return int64(len(er.Data)), nil
}
1167449
func (buf *Buffer) ReadByte() (byte, error) {
	if len(buf.buf) == 0 {
		return 0, io.EOF
	}

	c := buf.buf[0]
	buf.buf[0] = 0
	buf.buf = buf.buf[1:]
	return c, nil
}
934730
func ReadN(r io.Reader, n int) ([]byte, error) {
	data := make([]byte, n)
	_, err := r.Read(data)

	if err != nil {
		return nil, err
	}

	return data, nil
}
1023498
func (s *stream) readBytes(n uint32) ([]byte, error) {
	if n > s.size {
		s.buf = make([]byte, n)
		s.size = n
	}

	if _, err := io.ReadFull(s.Reader, s.buf[:n]); err != nil {
		return nil, err
	}

	return s.buf[:n], nil
}
635043
func (r *Reader) ReadLine() (line []byte, err error) {

	// Sets r.idx to first \n or \r, or -1 if not found.
	scan := func() {
		end := r.n
		i1 := bytes.IndexByte(r.buf[r.p:end], '\n')
		if i1 >= 0 {
			end = r.p + i1
		}
		i2 := bytes.IndexByte(r.buf[r.p:end], '\r')
		if i2 >= 0 {
			r.idx = r.p + i2
		} else if i1 >= 0 {
			r.idx = r.p + i1
		} else {
			r.idx = -1
		}
	}

	// Fills buffer if no \n or \r found and no error yet,
	// and then rescans for first \n or \r.
	fill := func() {
		if (r.idx < 0 || r.idx == r.n - 1) && r.err == nil {
			if r.p > 0 {
				// make room
				if r.p < r.n {
					copy(r.buf, r.buf[r.p:r.n])
				}
				r.n -= r.p
				r.p = 0
			}
			if r.n < len(r.buf) {
				var i int
				i, r.err = r.rd.Read(r.buf[r.n:])
				r.n += i
			}
			scan()
		}
	}

	lines := make([][]byte, 0)
	beginning := true
	for {

		fill()

		// if at beginning of line, skip EOL of previous line
		if beginning {
			var c byte
			for i := 0; i < 2; i++ {
				// 1 or 2 times \r or \n, but not \r\r or \n\n
				if r.idx == r.p && r.buf[r.p] != c {
					c = r.buf[r.p]
					r.p += 1
					scan() // reset r.idx
				} else {
					break
				}
			}
			fill()
			beginning = false
		}

		// if error and no more unscanned data, return saved parts if they exist, else return error
		if r.p == r.n && r.err != nil {
			if len(lines) > 0 {
				return buildline(lines, r.buf[0:0]), nil
			} else {
				return r.buf[0:0], r.err
			}
		}

		if r.p < r.n {
			if r.idx < 0 { // no EOL found
				buf := make([]byte, r.n-r.p)
				copy(buf, r.buf[r.p:r.n])
				lines = append(lines, buf)
				r.p = r.n
			} else { // EOL found
				p := r.p
				r.p = r.idx
				return buildline(lines, r.buf[p:r.p]), nil
			}
		}

	}
	panic("not reached")
}
481131
func (m *Memberlist) readStream(conn net.Conn) (messageType, io.Reader, *codec.Decoder, error) {
	// Created a buffered reader
	var bufConn io.Reader = bufio.NewReader(conn)

	// Read the message type
	buf := [1]byte{0}
	if _, err := bufConn.Read(buf[:]); err != nil {
		return 0, nil, nil, err
	}
	msgType := messageType(buf[0])

	// Check if the message is encrypted
	if msgType == encryptMsg {
		if !m.config.EncryptionEnabled() {
			return 0, nil, nil,
				fmt.Errorf("Remote state is encrypted and encryption is not configured")
		}

		plain, err := m.decryptRemoteState(bufConn)
		if err != nil {
			return 0, nil, nil, err
		}

		// Reset message type and bufConn
		msgType = messageType(plain[0])
		bufConn = bytes.NewReader(plain[1:])
	} else if m.config.EncryptionEnabled() && m.config.GossipVerifyIncoming {
		return 0, nil, nil,
			fmt.Errorf("Encryption is configured but remote state is not encrypted")
	}

	// Get the msgPack decoders
	hd := codec.MsgpackHandle{}
	dec := codec.NewDecoder(bufConn, &hd)

	// Check if we have a compressed message
	if msgType == compressMsg {
		var c compress
		if err := dec.Decode(&c); err != nil {
			return 0, nil, nil, err
		}
		decomp, err := decompressBuffer(&c)
		if err != nil {
			return 0, nil, nil, err
		}

		// Reset the message type
		msgType = messageType(decomp[0])

		// Create a new bufConn
		bufConn = bytes.NewReader(decomp[1:])

		// Create a new decoder
		dec = codec.NewDecoder(bufConn, &hd)
	}

	return msgType, bufConn, dec, nil
}
852878
func (p *StreamTransport) Read(buf []byte) (int, error) {
	if p.Reader == nil {
		return 0, NewTTransportException(NOT_OPEN, "Cannot read from null inputStream")
	}
	n, err := p.Reader.Read(buf)
	return n, NewTTransportExceptionFromError(err)
}
1290039
func (s *StreamingReader) Read(buf []byte) (int, error) {
	switch {
	// After the last chunk is read from underlying reader, we
	// never re-fill s.buf.
	case s.done:

	// s.buf will be (re-)filled with next chunk when has lesser
	// bytes than asked for.
	case s.buf.Len() < len(buf):
		s.chunkBufLen = 0
		for {
			n1, err := s.baseReadCloser.Read(s.chunkBuf[s.chunkBufLen:])
			// Usually we validate `err` first, but in this case
			// we are validating n > 0 for the following reasons.
			//
			// 1. n > 0, err is one of io.EOF, nil (near end of stream)
			// A Reader returning a non-zero number of bytes at the end
			// of the input stream may return either err == EOF or err == nil
			//
			// 2. n == 0, err is io.EOF (actual end of stream)
			//
			// Callers should always process the n > 0 bytes returned
			// before considering the error err.
			if n1 > 0 {
				s.chunkBufLen += n1
				s.bytesRead += int64(n1)

				if s.chunkBufLen == payloadChunkSize ||
					(s.chunkNum == s.totalChunks-1 &&
						s.chunkBufLen == s.lastChunkSize) {
					// Sign the chunk and write it to s.buf.
					s.signChunk(s.chunkBufLen)
					break
				}
			}
			if err != nil {
				if err == io.EOF {
					// No more data left in baseReader - last chunk.
					// Done reading the last chunk from baseReader.
					s.done = true

					// bytes read from baseReader different than
					// content length provided.
					if s.bytesRead != s.contentLen {
						return 0, io.ErrUnexpectedEOF
					}

					// Sign the chunk and write it to s.buf.
					s.signChunk(0)
					break
				}
				return 0, err
			}

		}
	}
	return s.buf.Read(buf)
}
909214
func readFromStream(
	ctx context.Context,
	stream transport.Stream,
	newMessage func() proto.Message,
) (proto.Message, error) {
	streamMsg, err := stream.ReceiveMessage(ctx)
	if err != nil {
		return nil, err
	}
	message := newMessage()
	if err := unmarshal(stream.Request().Meta.Encoding, streamMsg.Body, message); err != nil {
		streamMsg.Body.Close()
		return nil, err
	}
	if streamMsg.Body != nil {
		streamMsg.Body.Close()
	}
	return message, nil
}
971
func (c *Conn) ReadLine() (text string, ok bool) {
	ok = c.RwcScanner.Scan()
	return c.RwcScanner.Text(), ok
}
910085
func (r *copyReader) Read(b []byte) (int, error) {
	if r.rerr != nil {
		return 0, r.rerr
	}

	r.once.Do(r.init)
	return r.rbuf.Read(b)
}