mirror of
https://github.com/revanced/multidexlib2.git
synced 2025-04-29 22:24:28 +02:00
Use try-with-resources
This commit is contained in:
parent
f59046497d
commit
36a2aa8c1a
@ -38,11 +38,8 @@ public class RawDexIO {
|
|||||||
|
|
||||||
public static DexBackedDexFile readRawDexFile(File file, Opcodes opcodes) throws IOException {
|
public static DexBackedDexFile readRawDexFile(File file, Opcodes opcodes) throws IOException {
|
||||||
/*
|
/*
|
||||||
InputStream inputStream = new FileInputStream(file);
|
try (InputStream inputStream = new FileInputStream(file)) {
|
||||||
try {
|
|
||||||
return readRawDexFile(inputStream, file.length(), opcodes);
|
return readRawDexFile(inputStream, file.length(), opcodes);
|
||||||
} finally {
|
|
||||||
inputStream.close();
|
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
byte[] buf = Files.toByteArray(file);
|
byte[] buf = Files.toByteArray(file);
|
||||||
|
@ -37,27 +37,21 @@ public class ZipFileDexContainer extends AbstractMultiDexContainer<WrappingMulti
|
|||||||
|
|
||||||
public ZipFileDexContainer(File zip, DexFileNamer namer, Opcodes opcodes) throws IOException {
|
public ZipFileDexContainer(File zip, DexFileNamer namer, Opcodes opcodes) throws IOException {
|
||||||
Map<String, WrappingMultiDexFile<DexBackedDexFile>> entryMap = new TreeMap<>(new DexFileNameComparator(namer));
|
Map<String, WrappingMultiDexFile<DexBackedDexFile>> entryMap = new TreeMap<>(new DexFileNameComparator(namer));
|
||||||
ZipFile zipFile = new ZipFile(zip);
|
try (ZipFile zipFile = new ZipFile(zip)) {
|
||||||
try {
|
|
||||||
Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
|
Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
|
||||||
while (zipEntries.hasMoreElements()) {
|
while (zipEntries.hasMoreElements()) {
|
||||||
ZipEntry zipEntry = zipEntries.nextElement();
|
ZipEntry zipEntry = zipEntries.nextElement();
|
||||||
String entryName = zipEntry.getName();
|
String entryName = zipEntry.getName();
|
||||||
if (namer.isValidName(entryName)) {
|
if (namer.isValidName(entryName)) {
|
||||||
DexBackedDexFile dexFile;
|
DexBackedDexFile dexFile;
|
||||||
InputStream inputStream = zipFile.getInputStream(zipEntry);
|
try (InputStream inputStream = zipFile.getInputStream(zipEntry)) {
|
||||||
try {
|
|
||||||
dexFile = RawDexIO.readRawDexFile(inputStream, zipEntry.getSize(), opcodes);
|
dexFile = RawDexIO.readRawDexFile(inputStream, zipEntry.getSize(), opcodes);
|
||||||
} finally {
|
|
||||||
inputStream.close();
|
|
||||||
}
|
}
|
||||||
WrappingMultiDexFile<DexBackedDexFile> multiDexFile =
|
WrappingMultiDexFile<DexBackedDexFile> multiDexFile =
|
||||||
new BasicMultiDexFile<>(this, entryName, dexFile);
|
new BasicMultiDexFile<>(this, entryName, dexFile);
|
||||||
if (entryMap.put(entryName, multiDexFile) != null) throwDuplicateEntryName(entryName);
|
if (entryMap.put(entryName, multiDexFile) != null) throwDuplicateEntryName(entryName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
|
||||||
zipFile.close();
|
|
||||||
}
|
}
|
||||||
initialize(entryMap, opcodes);
|
initialize(entryMap, opcodes);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user