Copies all bytes from the input stream to the output stream. Does not close or flush either stream. @param from the input stream to read from @param to the output stream to write to @return the number of bytes copied @throws IOException if an I/O error occurs
(InputStream from, OutputStream to)
| 98 | * @throws IOException if an I/O error occurs |
| 99 | */ |
| 100 | @CanIgnoreReturnValue |
| 101 | public static long copy(InputStream from, OutputStream to) throws IOException { |
| 102 | checkNotNull(from); |
| 103 | checkNotNull(to); |
| 104 | byte[] buf = createBuffer(); |
| 105 | long total = 0; |
| 106 | while (true) { |
| 107 | int r = from.read(buf); |
| 108 | if (r == -1) { |
| 109 | break; |
| 110 | } |
| 111 | to.write(buf, 0, r); |
| 112 | total += r; |
| 113 | } |
| 114 | return total; |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Copies all bytes from the readable channel to the writable channel. Does not close or flush |
no test coverage detected