File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
src/_158_ReadNCharactersGivenRead4II Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change 3030 */
3131public class Solution extends Reader4 {
3232
33- private char [] buffer = new char [4 ];
33+ // unread part from last read4 call
34+ private char [] cache = new char [4 ];
3435 private int offset = 0 ;
3536 private int bufsize = 0 ;
3637
3738 /**
38- * Reads from buffer first and then use read4 to read more content.
39+ * Reads from cache first and then use read4 to read more content.
3940 *
40- * @param buf Destination buffer
41+ * @param buf Destination cache
4142 * @param n Maximum number of characters to read
4243 * @return The number of characters read
4344 */
4445 public int read (char [] buf , int n ) {
4546 int readBytes = 0 ;
4647 boolean eof = false ;
4748 while (!eof && readBytes < n ) {
48- int size = (bufsize > 0 ) ? bufsize : read4 (buffer );
49+ int size = (bufsize > 0 ) ? bufsize : read4 (cache );
4950 if (bufsize == 0 && size < 4 ) {
5051 eof = true ;
5152 }
5253 int bytes = Math .min (n - readBytes , size );
5354 for (int i = 0 ; i < bytes ; i ++) {
54- buf [readBytes + i ] = buffer [offset + i ];
55+ buf [readBytes + i ] = cache [offset + i ];
5556 }
5657 offset = (offset + bytes ) % 4 ;
5758 bufsize = size - bytes ;
You can’t perform that action at this time.
0 commit comments