Returns whether the source has zero chars. The default implementation first checks {@link #lengthIfKnown}, returning true if it's known to be zero and false if it's known to be non-zero. If the length is not known, it falls back to opening a stream and checking for EOF. <p>Note that, in cases where
()
| 414 | * @since 15.0 |
| 415 | */ |
| 416 | public boolean isEmpty() throws IOException { |
| 417 | Optional<Long> lengthIfKnown = lengthIfKnown(); |
| 418 | if (lengthIfKnown.isPresent()) { |
| 419 | return lengthIfKnown.get() == 0L; |
| 420 | } |
| 421 | Closer closer = Closer.create(); |
| 422 | try { |
| 423 | Reader reader = closer.register(openStream()); |
| 424 | return reader.read() == -1; |
| 425 | } catch (Throwable e) { |
| 426 | throw closer.rethrow(e); |
| 427 | } finally { |
| 428 | closer.close(); |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | /** |
| 433 | * Concatenates multiple {@link CharSource} instances into a single source. Streams returned from |