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
()
| 205 | |
| 206 | |
| 207 | public long size() throws IOException { |
| 208 | Optional<Long> sizeIfKnown = sizeIfKnown(); |
| 209 | if (sizeIfKnown.isPresent()) { |
| 210 | return sizeIfKnown.get(); |
| 211 | } |
| 212 | Closer closer = Closer.create(); |
| 213 | try { |
| 214 | InputStream in = closer.register(openStream()); |
| 215 | return countBySkipping(in); |
| 216 | } catch (IOException e) { |
| 217 | // skip may not be supported... at any rate, try reading |
| 218 | } finally { |
| 219 | closer.close(); |
| 220 | } |
| 221 | closer = Closer.create(); |
| 222 | try { |
| 223 | InputStream in = closer.register(openStream()); |
| 224 | return ByteStreams.exhaust(in); |
| 225 | } catch (Throwable e) { |
| 226 | throw closer.rethrow(e); |
| 227 | } finally { |
| 228 | closer.close(); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Counts the bytes in the given input stream using skip if possible. Returns SKIP_FAILED if the |
nothing calls this directly
no test coverage detected