MCPcopy Create free account
hub / github.com/antlr/codebuff / size

Method size

corpus/java/training/guava/io/ByteSource.java:192–217  ·  view source on GitHub ↗

Returns the size of this source in bytes, even if doing so requires opening and traversing an entire stream. To avoid a potentially expensive operation, see #sizeIfKnown. The default implementation calls #sizeIfKnown and returns the value if present. If absent, it will fall back

()

Source from the content-addressed store, hash-verified

190 * @throws IOException if an I/O error occurs in the process of reading the size of this source
191 */
192 public long size() throws IOException {
193 Optional<Long> sizeIfKnown = sizeIfKnown();
194 if (sizeIfKnown.isPresent()) {
195 return sizeIfKnown.get();
196 }
197
198 Closer closer = Closer.create();
199 try {
200 InputStream in = closer.register(openStream());
201 return countBySkipping(in);
202 } catch (IOException e) {
203 // skip may not be supported... at any rate, try reading
204 } finally {
205 closer.close();
206 }
207
208 closer = Closer.create();
209 try {
210 InputStream in = closer.register(openStream());
211 return ByteStreams.exhaust(in);
212 } catch (Throwable e) {
213 throw closer.rethrow(e);
214 } finally {
215 closer.close();
216 }
217 }
218
219 /**
220 * Counts the bytes in the given input stream using skip if possible. Returns SKIP_FAILED if the

Callers

nothing calls this directly

Calls 10

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

Tested by

no test coverage detected