mirror of
https://github.com/revanced/Apktool.git
synced 2025-04-30 22:24:25 +02:00
re-add copy() method using try-with-resources
This commit is contained in:
parent
10afb3cd56
commit
7326867b09
@ -409,8 +409,7 @@ public class Androlib {
|
|||||||
if (apkOptions.forceBuildAll || isModified(newFiles(APK_RESOURCES_FILENAMES, appDir),
|
if (apkOptions.forceBuildAll || isModified(newFiles(APK_RESOURCES_FILENAMES, appDir),
|
||||||
newFiles(APK_RESOURCES_FILENAMES, apkDir))) {
|
newFiles(APK_RESOURCES_FILENAMES, apkDir))) {
|
||||||
LOGGER.info("Copying raw resources...");
|
LOGGER.info("Copying raw resources...");
|
||||||
appDir.getDirectory()
|
appDir.getDirectory().copyToDir(apkDir, APK_RESOURCES_FILENAMES);
|
||||||
.copyToDir(apkDir, APK_RESOURCES_FILENAMES);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} catch (DirectoryException ex) {
|
} catch (DirectoryException ex) {
|
||||||
@ -569,7 +568,7 @@ public class Androlib {
|
|||||||
|
|
||||||
try (
|
try (
|
||||||
ZipFile inputFile = new ZipFile(tempFile);
|
ZipFile inputFile = new ZipFile(tempFile);
|
||||||
ZipOutputStream actualOutput = new ZipOutputStream(new FileOutputStream(outFile));
|
ZipOutputStream actualOutput = new ZipOutputStream(new FileOutputStream(outFile))
|
||||||
) {
|
) {
|
||||||
copyExistingFiles(inputFile, actualOutput);
|
copyExistingFiles(inputFile, actualOutput);
|
||||||
copyUnknownFiles(appDir, actualOutput, files);
|
copyUnknownFiles(appDir, actualOutput, files);
|
||||||
@ -587,17 +586,14 @@ public class Androlib {
|
|||||||
Enumeration<? extends ZipEntry> entries = inputFile.entries();
|
Enumeration<? extends ZipEntry> entries = inputFile.entries();
|
||||||
while (entries.hasMoreElements()) {
|
while (entries.hasMoreElements()) {
|
||||||
ZipEntry entry = new ZipEntry(entries.nextElement());
|
ZipEntry entry = new ZipEntry(entries.nextElement());
|
||||||
|
|
||||||
// We can't reuse the compressed size because it depends on compression sizes.
|
// We can't reuse the compressed size because it depends on compression sizes.
|
||||||
entry.setCompressedSize(-1);
|
entry.setCompressedSize(-1);
|
||||||
outputFile.putNextEntry(entry);
|
outputFile.putNextEntry(entry);
|
||||||
|
|
||||||
// No need to create directory entries in the final apk
|
// No need to create directory entries in the final apk
|
||||||
if (! entry.isDirectory()) {
|
if (! entry.isDirectory()) {
|
||||||
try (
|
BrutIO.copy(inputFile, outputFile, entry);
|
||||||
InputStream is = inputFile.getInputStream(entry)
|
|
||||||
){
|
|
||||||
IOUtils.copy(is, outputFile);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
outputFile.closeEntry();
|
outputFile.closeEntry();
|
||||||
@ -625,18 +621,12 @@ public class Androlib {
|
|||||||
BufferedInputStream unknownFile = new BufferedInputStream(new FileInputStream(inputFile));
|
BufferedInputStream unknownFile = new BufferedInputStream(new FileInputStream(inputFile));
|
||||||
CRC32 crc = BrutIO.calculateCrc(unknownFile);
|
CRC32 crc = BrutIO.calculateCrc(unknownFile);
|
||||||
newEntry.setCrc(crc.getValue());
|
newEntry.setCrc(crc.getValue());
|
||||||
|
|
||||||
LOGGER.fine("\tsize: " + newEntry.getSize());
|
|
||||||
} else {
|
} else {
|
||||||
newEntry.setMethod(ZipEntry.DEFLATED);
|
newEntry.setMethod(ZipEntry.DEFLATED);
|
||||||
}
|
}
|
||||||
outputFile.putNextEntry(newEntry);
|
outputFile.putNextEntry(newEntry);
|
||||||
|
|
||||||
try (
|
BrutIO.copy(inputFile, outputFile);
|
||||||
FileInputStream fis = new FileInputStream(inputFile)
|
|
||||||
){
|
|
||||||
IOUtils.copy(fis, outputFile);
|
|
||||||
}
|
|
||||||
outputFile.closeEntry();
|
outputFile.closeEntry();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,9 @@ package brut.util;
|
|||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.zip.CRC32;
|
import java.util.zip.CRC32;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipFile;
|
||||||
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
|
||||||
@ -70,4 +73,20 @@ public class BrutIO {
|
|||||||
return crc;
|
return crc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void copy(File inputFile, ZipOutputStream outputFile) throws IOException {
|
||||||
|
try (
|
||||||
|
FileInputStream fis = new FileInputStream(inputFile)
|
||||||
|
) {
|
||||||
|
IOUtils.copy(fis, outputFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void copy(ZipFile inputFile, ZipOutputStream outputFile, ZipEntry entry) throws IOException {
|
||||||
|
try (
|
||||||
|
InputStream is = inputFile.getInputStream(entry)
|
||||||
|
) {
|
||||||
|
IOUtils.copy(is, outputFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user