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

Method length

guava/src/com/google/common/io/CharSource.java:213–228  ·  view source on GitHub ↗

Returns the length of this source in chars, even if doing so requires opening and traversing an entire stream. To avoid a potentially expensive operation, see {@link #lengthIfKnown}. <p>The default implementation calls {@link #lengthIfKnown} and returns the value if present. If absent, it will fall

()

Source from the content-addressed store, hash-verified

211 * @since 19.0
212 */
213 public long length() throws IOException {
214 Optional<Long> lengthIfKnown = lengthIfKnown();
215 if (lengthIfKnown.isPresent()) {
216 return lengthIfKnown.get();
217 }
218
219 Closer closer = Closer.create();
220 try {
221 Reader reader = closer.register(openStream());
222 return countBySkipping(reader);
223 } catch (Throwable e) {
224 throw closer.rethrow(e);
225 } finally {
226 closer.close();
227 }
228 }
229
230 private static long countBySkipping(Reader reader) throws IOException {
231 long count = 0;

Callers 15

parseMethod · 0.45
initTableMethod · 0.45
lockedGetOrLoadMethod · 0.45
computeMethod · 0.45
getFirstMethod · 0.45
containsValueMethod · 0.45
putMethod · 0.45
expandMethod · 0.45
replaceMethod · 0.45
removeMethod · 0.45
storeLoadedValueMethod · 0.45

Calls 9

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

Tested by

no test coverage detected