Copies the contents of this byte source to the given {@code OutputStream}. Does not close {@code output}. @return the number of bytes copied @throws IOException if an I/O error occurs while reading from this source or writing to {@code output}
(OutputStream output)
| 247 | * output} |
| 248 | */ |
| 249 | @CanIgnoreReturnValue |
| 250 | public long copyTo(OutputStream output) throws IOException { |
| 251 | checkNotNull(output); |
| 252 | |
| 253 | Closer closer = Closer.create(); |
| 254 | try { |
| 255 | InputStream in = closer.register(openStream()); |
| 256 | return ByteStreams.copy(in, output); |
| 257 | } catch (Throwable e) { |
| 258 | throw closer.rethrow(e); |
| 259 | } finally { |
| 260 | closer.close(); |
| 261 | } |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * Copies the contents of this byte source to the given {@code ByteSink}. |