From e94217555947daf9f1809d48ebfd88e19dd3595b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien?= <43724816+Aurelien30000@users.noreply.github.com> Date: Tue, 2 Aug 2022 11:25:56 +0200 Subject: [PATCH] Improve ``MainUtil#copyFile`` (#1888) --- .../fastasyncworldedit/core/util/MainUtil.java | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/MainUtil.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/MainUtil.java index 0875df13c..86370747d 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/MainUtil.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/util/MainUtil.java @@ -560,18 +560,14 @@ public class MainUtil { return newFile; } try (InputStream stream = Fawe.class.getResourceAsStream(resource.startsWith("/") ? resource : "/" + resource)) { - byte[] buffer = new byte[2048]; if (stream == null) { try (ZipInputStream zis = new ZipInputStream(new FileInputStream(jar))) { ZipEntry ze = zis.getNextEntry(); while (ze != null) { String name = ze.getName(); if (name.equals(resource)) { - try (FileOutputStream fos = new FileOutputStream(newFile)) { - int len; - while ((len = zis.read(buffer)) > 0) { - fos.write(buffer, 0, len); - } + try (OutputStream outputStream = Files.newOutputStream(newFile.toPath())) { + zis.transferTo(outputStream); } ze = null; } else { @@ -587,11 +583,8 @@ public class MainUtil { parent.mkdirs(); } newFile.createNewFile(); - try (FileOutputStream fos = new FileOutputStream(newFile)) { - int len; - while ((len = stream.read(buffer)) > 0) { - fos.write(buffer, 0, len); - } + try (OutputStream outputStream = Files.newOutputStream(newFile.toPath())) { + stream.transferTo(outputStream); } return newFile; }