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)
| 100 | */ |
| 101 | |
| 102 | @CanIgnoreReturnValue |
| 103 | public static long copy(InputStream from, OutputStream to) throws IOException { |
| 104 | checkNotNull(from); |
| 105 | checkNotNull(to); |
| 106 | byte[] buf = createBuffer(); |
| 107 | long total = 0; |
| 108 | while (true) { |
| 109 | int r = from.read(buf); |
| 110 | if (r == -1) { |
| 111 | break; |
| 112 | } |
| 113 | to.write(buf, 0, r); |
| 114 | total += r; |
| 115 | } |
| 116 | return total; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Copies all bytes from the readable channel to the writable channel. Does not close or flush |
no test coverage detected