The code follows ==
s := strings.NewReader("ABCDEFGJHIJK")
fmt.Printf("pa is %d
", s.GetValueI()) //GetValueI() returns the value of r.i
br := bufio.NewReader(s)
fmt.Printf("papa is %d
", s.GetValueI())
cc, _ := br.ReadByte()
fmt.Printf("%c
", cc)
fmt.Printf("papapa is %d
", s.GetValueI())
The prints shows: pa is 0 papa is 0 A papapa is 12
So weired Results.. why papapa is 12 when bufio call ReadByte() ? It really confuse me a lot ..
The point of a buffered reader is to read the data stream more efficiently, no matter what size reads are requested.
When you call ReadByte
, if the internal buffer is empty, it calls its internal fill()
method to refill the buffer, which in this case consumes the entire strings.Reader
. The single byte is then returned from this internal buffer.