MCPcopy
hub / github.com/google/guava / isEmpty

Method isEmpty

guava/src/com/google/common/io/ByteSource.java:151–165  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

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

Callers 1

testConcatMethod · 0.95

Calls 9

sizeIfKnownMethod · 0.95
createMethod · 0.95
registerMethod · 0.95
openStreamMethod · 0.95
rethrowMethod · 0.95
closeMethod · 0.95
getMethod · 0.65
isPresentMethod · 0.45
readMethod · 0.45

Tested by 1

testConcatMethod · 0.76