Reads and discards data from the given {@code Readable} until the end of the stream is reached. Returns the total number of chars read. Does not close the stream. @since 20.0
(Readable readable)
| 248 | * @since 20.0 |
| 249 | */ |
| 250 | @CanIgnoreReturnValue |
| 251 | public static long exhaust(Readable readable) throws IOException { |
| 252 | long total = 0; |
| 253 | long read; |
| 254 | CharBuffer buf = createBuffer(); |
| 255 | while ((read = readable.read(buf)) != -1) { |
| 256 | total += read; |
| 257 | Java8Compatibility.clear(buf); |
| 258 | } |
| 259 | return total; |
| 260 | } |
| 261 | |
| 262 | /** |
| 263 | * Discards {@code n} characters of data from the reader. This method will block until the full |