public int read (char[] b, int offset, int length) throws IOException { int count = 0; if (position >= limit && length < buffer.length) { fill(); } if (position < limit) { int remaining = limit - position; if (remaining > length) { remaining = length; } System.arraycopy(buffer, position, b, offset, remaining); count += remaining; position += remaining; offset += remaining; length -= remaining; } if (length > 0) { int c = in.read(b, offset, length); if (c == -1) { if (count == 0) { count = -1; } } else { count += c; } } return count; }
Exception in thread "main" java.lang.NullPointerException at java.io.FilterInputStream.read(FilterInputStream.java:133) at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284) at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326) at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178) at java.io.InputStreamReader.read(InputStreamReader.java:184) at java.io.BufferedReader.fill(BufferedReader.java:161) at java.io.BufferedReader.readLine(BufferedReader.java:324) at java.io.BufferedReader.readLine(BufferedReader.java:389)
public int read (char[] b, int offset, int length) throws IOException { int count = 0; if (position >= limit && length < buffer.length) { fill(); } if (position < limit) { int remaining = limit - position; if (remaining > length) { remaining = length; } System.arraycopy(buffer, position, b, offset, remaining); count += remaining; position += remaining; offset += remaining; length -= remaining; } if (length > 0) { int c = in.read(b, offset, length); if (c == -1) { if (count == 0) { count = -1; } } else { count += c; } } return count; }
/** * Reads a single character. * * @return The character read, as an integer in the range * 0 to 65535 (<tt>0x00-0xffff</tt>), or -1 if the * end of the stream has been reached * @exception IOException If an I/O error occurs */ public int read() throws IOException { synchronized (lock) { ensureOpen(); for (;;) { if (nextChar >= nChars) { fill(); if (nextChar >= nChars) return -1; } if (skipLF) { skipLF = false; if (cb[nextChar] == '\n') { nextChar++; continue; } } return cb[nextChar++]; } } }
/** * Tells whether this stream is ready to be read. A buffered character * stream is ready if the buffer is not empty, or if the underlying * character stream is ready. * * @exception IOException If an I/O error occurs */ public boolean ready() throws IOException { synchronized (lock) { ensureOpen(); /* * If newline needs to be skipped and the next char to be read * is a newline character, then just skip it right away. */ if (skipLF) { /* Note that in.ready() will return true if and only if the next * read on the stream will not block. */ if (nextChar >= nChars && in.ready()) { fill(); } if (nextChar < nChars) { if (cb[nextChar] == '\n') nextChar++; skipLF = false; } } return (nextChar < nChars) || in.ready(); } }
/** * Reads a single character. * * @return The character read, as an integer in the range * 0 to 65535 (<tt>0x00-0xffff</tt>), or -1 if the * end of the stream has been reached * @exception IOException If an I/O error occurs */ public int read() throws IOException { synchronized (lock) { ensureOpen(); for (;;) { if (nextChar >= nChars) { fill(); if (nextChar >= nChars) return -1; } if (skipLF) { skipLF = false; if (cb[nextChar] == '\n') { nextChar++; continue; } } return cb[nextChar++]; } } }
/** * Tells whether this stream is ready to be read. A buffered character * stream is ready if the buffer is not empty, or if the underlying * character stream is ready. * * @exception IOException If an I/O error occurs */ public boolean ready() throws IOException { synchronized (lock) { ensureOpen(); /* * If newline needs to be skipped and the next char to be read * is a newline character, then just skip it right away. */ if (skipLF) { /* Note that in.ready() will return true if and only if the next * read on the stream will not block. */ if (nextChar >= nChars && in.ready()) { fill(); } if (nextChar < nChars) { if (cb[nextChar] == '\n') nextChar++; skipLF = false; } } return (nextChar < nChars) || in.ready(); } }
while (r > 0) { if (nextChar >= nChars) fill(); if (nextChar >= nChars) /* EOF */ break;
while (r > 0) { if (nextChar >= nChars) fill(); if (nextChar >= nChars) /* EOF */ break;
"main" #1 prio=5 os_prio=31 tid=0x00007fef4d803000 nid=0xf07 waiting for monitor entry [0x000000010b7a3000] java.lang.Thread.State: BLOCKED (on object monitor) at java.io.BufferedReader.close(BufferedReader.java:522) - waiting to lock <0x000000076ac47f78> (a java.io.InputStreamReader) at ReaderService.stop(ReaderService.java:19) at ReaderService.main(ReaderService.java:34) "Thread-0" #10 prio=5 os_prio=31 tid=0x00007fef4c873800 nid=0x5503 runnable [0x000000012b497000] java.lang.Thread.State: RUNNABLE at java.io.FileInputStream.readBytes(Native Method) at java.io.FileInputStream.read(FileInputStream.java:255) at java.io.BufferedInputStream.read1(BufferedInputStream.java:284) at java.io.BufferedInputStream.read(BufferedInputStream.java:345) - locked <0x000000076ab1bf10> (a java.io.BufferedInputStream) at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284) at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326) at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178) - locked <0x000000076ac47f78> (a java.io.InputStreamReader) at java.io.InputStreamReader.read(InputStreamReader.java:184) at java.io.BufferedReader.fill(BufferedReader.java:161) at java.io.BufferedReader.readLine(BufferedReader.java:324) - locked <0x000000076ac47f78> (a java.io.InputStreamReader) at java.io.BufferedReader.readLine(BufferedReader.java:389) at ReaderService.start(ReaderService.java:10) at ReaderService$1.run(ReaderService.java:29) at java.lang.Thread.run(Thread.java:745)
> jps 83518 Test > jstack 83518 2015-12-24 21:25:17 Full thread dump Java HotSpot(TM) 64-Bit Server VM (24.65-b04 mixed mode): ... "main" prio=5 tid=0x00007fbba2001000 nid=0x1903 runnable [0x000000010a560000] java.lang.Thread.State: RUNNABLE at java.io.FileInputStream.readBytes(Native Method) at java.io.FileInputStream.read(FileInputStream.java:272) at java.io.BufferedInputStream.read1(BufferedInputStream.java:273) at java.io.BufferedInputStream.read(BufferedInputStream.java:334) - locked <0x00000007aaa9a5f0> (a java.io.BufferedInputStream) at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:283) at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:325) at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:177) - locked <0x00000007aab2ad88> (a java.io.InputStreamReader) at java.io.InputStreamReader.read(InputStreamReader.java:184) at java.io.BufferedReader.fill(BufferedReader.java:154) at java.io.BufferedReader.readLine(BufferedReader.java:317) - locked <0x00000007aab2ad88> (a java.io.InputStreamReader) at java.io.BufferedReader.readLine(BufferedReader.java:382) at Test.main(Test.java:22) ...
fill(); if (nextChar >= nChars) { /* EOF */ if (s != null && s.length() > 0)
fill(); if (nextChar >= nChars) { /* EOF */ if (s != null && s.length() > 0)
fill(); if (nextChar >= nChars) { /* EOF */ if (s != null && s.length() > 0)