@@ -137,13 +137,12 @@ public void close() throws IOException {
137137 }
138138
139139 /**
140- * Populates the buffer with data . It is an error to call this method when the buffer still contains data; ie. if {@code pos < end}.
140+ * Fills the buffer with characters . It is an error to call this method when the buffer still contains data, that is, if {@code pos < end}.
141141 *
142142 * @return the number of bytes read into the buffer, or -1 if the end of the source stream has been reached.
143143 */
144144 private int fillBuf () throws IOException {
145145 // assert(pos == end);
146-
147146 if (mark == EOF || bufPos - mark >= markLimit ) {
148147 /* mark isn't set or has exceeded its limit. use the whole buffer */
149148 final int result = in .read (buf , 0 , buf .length );
@@ -154,7 +153,6 @@ private int fillBuf() throws IOException {
154153 }
155154 return result ;
156155 }
157-
158156 if (mark == 0 && markLimit > buf .length ) {
159157 /* the only way to make room when mark=0 is by growing the buffer */
160158 int newLength = buf .length * 2 ;
@@ -171,7 +169,6 @@ private int fillBuf() throws IOException {
171169 end -= mark ;
172170 mark = 0 ;
173171 }
174-
175172 /* Set the new position and mark position */
176173 final int count = in .read (buf , bufPos , buf .length - bufPos );
177174 if (count != EOF ) {
@@ -360,7 +357,7 @@ public int read(final char[] buffer, int offset, final int length) throws IOExce
360357
361358 /**
362359 * Returns the next line of text available from this reader. A line is represented by zero or more characters followed by {@code LF}, {@code CR},
363- * {@code "\r\n"} or the end of the reader. The string does not include the newline sequence.
360+ * {@code "\r\n"}, or the end of the reader. The string does not include the newline sequence.
364361 *
365362 * @return the contents of the line or {@code null} if no characters were read before the end of the reader has been reached.
366363 * @throws IOException if this reader is closed or some other I/O error occurs.
@@ -371,6 +368,7 @@ public String readLine() throws IOException {
371368 if (bufPos == end && fillBuf () == EOF ) {
372369 return null ;
373370 }
371+ final int startPos = bufPos ;
374372 for (int charPos = bufPos ; charPos < end ; charPos ++) {
375373 final char ch = buf [charPos ];
376374 if (ch > CR ) {
@@ -379,6 +377,7 @@ public String readLine() throws IOException {
379377 if (ch == LF ) {
380378 final String res = new String (buf , bufPos , charPos - bufPos );
381379 bufPos = charPos + 1 ;
380+ incPos (bufPos - startPos );
382381 return res ;
383382 }
384383 if (ch == CR ) {
@@ -387,18 +386,16 @@ public String readLine() throws IOException {
387386 if ((bufPos < end || fillBuf () != EOF ) && buf [bufPos ] == LF ) {
388387 bufPos ++;
389388 }
389+ incPos (bufPos - startPos );
390390 return res ;
391391 }
392392 }
393-
394393 char eol = NUL ;
394+ // Typical Line Length
395395 final StringBuilder result = new StringBuilder (80 );
396- /* Typical Line Length */
397-
398396 result .append (buf , bufPos , end - bufPos );
399397 while (true ) {
400398 bufPos = end ;
401-
402399 /* Are there buffered characters available? */
403400 if (eol == LF ) {
404401 return result .toString ();
0 commit comments