| 395 | } |
| 396 | |
| 397 | private static void copyInputStream(boolean force, byte[] buffer, File out, InputStream is, Log log) throws IOException { |
| 398 | final boolean exists = out.exists(); |
| 399 | if (force || !exists) { |
| 400 | File dir = out.getParentFile(); |
| 401 | if (!dir.exists() && !dir.mkdirs()) { |
| 402 | if (log != null) { |
| 403 | log.errorW().$("could not create directory [path=").$(dir).I$(); |
| 404 | } |
| 405 | return; |
| 406 | } |
| 407 | try (FileOutputStream fos = new FileOutputStream(out)) { |
| 408 | int n; |
| 409 | while ((n = is.read(buffer, 0, buffer.length)) > 0) { |
| 410 | fos.write(buffer, 0, n); |
| 411 | } |
| 412 | } |
| 413 | if (log != null) { |
| 414 | log.infoW().$("extracted [path=").$(out).I$(); |
| 415 | } |
| 416 | return; |
| 417 | } |
| 418 | if (log != null) { |
| 419 | log.debugW().$("skipped [path=").$(out).I$(); |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | private static void copyResource(String dir, boolean force, byte[] buffer, String res, String dest, Log log) throws IOException { |
| 424 | File out = new File(dir, dest); |