Skip to content
This repository has been archived by the owner on Sep 21, 2020. It is now read-only.

Commit

Permalink
fix #94: file channel not closed when close apk file
Browse files Browse the repository at this point in the history
  • Loading branch information
hsiafan committed Jun 6, 2019
1 parent 302e282 commit 037d668
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/main/java/net/dongliu/apk/parser/ApkFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.dongliu.apk.parser.bean.ApkSignStatus;
import net.dongliu.apk.parser.utils.Inputs;

import javax.annotation.Nullable;
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
Expand All @@ -25,6 +26,8 @@ public class ApkFile extends AbstractApkFile implements Closeable {

private final ZipFile zf;
private File apkFile;
@Nullable
private FileChannel fileChannel;

public ApkFile(File apkFile) throws IOException {
this.apkFile = apkFile;
Expand Down Expand Up @@ -66,8 +69,8 @@ public byte[] getFileData(String path) throws IOException {

@Override
protected ByteBuffer fileData() throws IOException {
FileChannel channel = new FileInputStream(apkFile).getChannel();
return channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
fileChannel = new FileInputStream(apkFile).getChannel();
return fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileChannel.size());
}


Expand Down Expand Up @@ -110,8 +113,16 @@ public ApkSignStatus verifyApk() throws IOException {

@Override
public void close() throws IOException {
super.close();
zf.close();
try (Closeable superClosable = new Closeable() {
@Override
public void close() throws IOException {
ApkFile.super.close();
}
};
Closeable zipFileClosable = zf;
Closeable fileChannelClosable = fileChannel) {

}
}

}

0 comments on commit 037d668

Please sign in to comment.