Returns whether the source has zero bytes. The default implementation first checks {@link #sizeIfKnown}, returning true if it's known to be zero and false if it's known to be non-zero. If the size is not known, it falls back to opening a stream and checking for EOF. <p>Note that, in cases where {@c
()
| 149 | * @since 15.0 |
| 150 | */ |
| 151 | public boolean isEmpty() throws IOException { |
| 152 | Optional<Long> sizeIfKnown = sizeIfKnown(); |
| 153 | if (sizeIfKnown.isPresent()) { |
| 154 | return sizeIfKnown.get() == 0L; |
| 155 | } |
| 156 | Closer closer = Closer.create(); |
| 157 | try { |
| 158 | InputStream in = closer.register(openStream()); |
| 159 | return in.read() == -1; |
| 160 | } catch (Throwable e) { |
| 161 | throw closer.rethrow(e); |
| 162 | } finally { |
| 163 | closer.close(); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Returns the size of this source in bytes, if the size can be easily determined without actually |