Adapted from com.google.common.io.ByteStreams.copy().
(InputStream from, OutputStream to)
| 267 | |
| 268 | /** Adapted from {@code com.google.common.io.ByteStreams.copy()}. */ |
| 269 | private static long copy(InputStream from, OutputStream to) throws IOException { |
| 270 | checkNotNull(from, "from"); |
| 271 | checkNotNull(to, "to"); |
| 272 | byte[] buf = new byte[BUF_SIZE]; |
| 273 | long total = 0; |
| 274 | while (true) { |
| 275 | int r = from.read(buf); |
| 276 | if (r == -1) { |
| 277 | break; |
| 278 | } |
| 279 | to.write(buf, 0, r); |
| 280 | total += r; |
| 281 | } |
| 282 | return total; |
| 283 | } |
| 284 | |
| 285 | public static String decodeOrDefault(byte[] data, Charset charset, String defaultValue) { |
| 286 | if (data == null) { |
no test coverage detected