Copies all bytes from the input stream to the output stream. Does not close or flush either stream. <p><b>Java 9 users and later:</b> this method should be treated as deprecated; use the equivalent {@link InputStream#transferTo} method instead. @param from the input stream to read from @param to t
(InputStream from, OutputStream to)
| 106 | * @throws IOException if an I/O error occurs |
| 107 | */ |
| 108 | @CanIgnoreReturnValue |
| 109 | public static long copy(InputStream from, OutputStream to) throws IOException { |
| 110 | checkNotNull(from); |
| 111 | checkNotNull(to); |
| 112 | byte[] buf = createBuffer(); |
| 113 | long total = 0; |
| 114 | while (true) { |
| 115 | int r = from.read(buf); |
| 116 | if (r == -1) { |
| 117 | break; |
| 118 | } |
| 119 | to.write(buf, 0, r); |
| 120 | total += r; |
| 121 | } |
| 122 | return total; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Copies all bytes from the readable channel to the writable channel. Does not close or flush |
no test coverage detected