Skips amount characters in this reader. Subsequent calls of read methods will not return these characters unless reset() is used. This method may perform multiple reads to read count characters. @param count the maximum number of characters to skip. @retur
(long count)
| 218 | * @see #reset() |
| 219 | */ |
| 220 | public long skip(long count) throws IOException { |
| 221 | if (count < 0) { |
| 222 | throw new IllegalArgumentException(); |
| 223 | } |
| 224 | synchronized (lock) { |
| 225 | long skipped = 0; |
| 226 | int toRead = count < 512 ? (int) count : 512; |
| 227 | char charsSkipped[] = new char[toRead]; |
| 228 | while (skipped < count) { |
| 229 | int read = read(charsSkipped, 0, toRead); |
| 230 | if (read == -1) { |
| 231 | return skipped; |
| 232 | } |
| 233 | skipped += read; |
| 234 | if (read < toRead) { |
| 235 | return skipped; |
| 236 | } |
| 237 | if (count - skipped < toRead) { |
| 238 | toRead = (int) (count - skipped); |
| 239 | } |
| 240 | } |
| 241 | return skipped; |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * Reads characters and puts them into the {@code target} character buffer. |