mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-22 17:27:38 +00:00
Improve `MainUtil#copyFile
` (#1888)
This commit is contained in:
parent
7a498497c5
commit
e942175559
@ -560,18 +560,14 @@ public class MainUtil {
|
|||||||
return newFile;
|
return newFile;
|
||||||
}
|
}
|
||||||
try (InputStream stream = Fawe.class.getResourceAsStream(resource.startsWith("/") ? resource : "/" + resource)) {
|
try (InputStream stream = Fawe.class.getResourceAsStream(resource.startsWith("/") ? resource : "/" + resource)) {
|
||||||
byte[] buffer = new byte[2048];
|
|
||||||
if (stream == null) {
|
if (stream == null) {
|
||||||
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(jar))) {
|
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(jar))) {
|
||||||
ZipEntry ze = zis.getNextEntry();
|
ZipEntry ze = zis.getNextEntry();
|
||||||
while (ze != null) {
|
while (ze != null) {
|
||||||
String name = ze.getName();
|
String name = ze.getName();
|
||||||
if (name.equals(resource)) {
|
if (name.equals(resource)) {
|
||||||
try (FileOutputStream fos = new FileOutputStream(newFile)) {
|
try (OutputStream outputStream = Files.newOutputStream(newFile.toPath())) {
|
||||||
int len;
|
zis.transferTo(outputStream);
|
||||||
while ((len = zis.read(buffer)) > 0) {
|
|
||||||
fos.write(buffer, 0, len);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ze = null;
|
ze = null;
|
||||||
} else {
|
} else {
|
||||||
@ -587,11 +583,8 @@ public class MainUtil {
|
|||||||
parent.mkdirs();
|
parent.mkdirs();
|
||||||
}
|
}
|
||||||
newFile.createNewFile();
|
newFile.createNewFile();
|
||||||
try (FileOutputStream fos = new FileOutputStream(newFile)) {
|
try (OutputStream outputStream = Files.newOutputStream(newFile.toPath())) {
|
||||||
int len;
|
stream.transferTo(outputStream);
|
||||||
while ((len = stream.read(buffer)) > 0) {
|
|
||||||
fos.write(buffer, 0, len);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return newFile;
|
return newFile;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user