Reads the full contents of this byte source as a byte array. @throws IOException if an I/O error occurs while reading from this source
()
| 290 | * @throws IOException if an I/O error occurs while reading from this source |
| 291 | */ |
| 292 | public byte[] read() throws IOException { |
| 293 | Closer closer = Closer.create(); |
| 294 | try { |
| 295 | InputStream in = closer.register(openStream()); |
| 296 | Optional<Long> size = sizeIfKnown(); |
| 297 | return size.isPresent() |
| 298 | ? ByteStreams.toByteArray(in, size.get()) |
| 299 | : ByteStreams.toByteArray(in); |
| 300 | } catch (Throwable e) { |
| 301 | throw closer.rethrow(e); |
| 302 | } finally { |
| 303 | closer.close(); |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | /** |
| 308 | * Reads the contents of this byte source using the given {@code processor} to process bytes as |