@@ -42,7 +42,8 @@ private static ArrayList<String> createLibraryBlacklist() {
4242 }
4343
4444 private static String getAarArchitectureName () {
45- switch (Architecture .getDeviceArchitecture ()) {
45+ int architecture = Architecture .getDeviceArchitecture ();
46+ switch (architecture ) {
4647 case Architecture .ARCH_ARM :
4748 return "armeabi-v7a" ;
4849 case Architecture .ARCH_ARM64 :
@@ -52,37 +53,33 @@ private static String getAarArchitectureName() {
5253 case Architecture .ARCH_X86_64 :
5354 return "x86_64" ;
5455 }
55- throw new RuntimeException ("Unknown CPU architecture!" );
56+ throw new RuntimeException ("Unknown CPU architecture: " + architecture );
5657 }
5758
5859 public void extractFromAar (File source ) throws IOException {
59- try (FileInputStream fileInputStream = new FileInputStream (source )) {
60- try (ZipInputStream zipInputStream = new ZipInputStream (fileInputStream )) {
61- // Wrap the ZIP input stream into a non-closeable stream to
62- // avoid it being closed by processEntry()
63- NonCloseableInputStream entryCopyStream = new NonCloseableInputStream (zipInputStream );
64-
65- while (true ) {
66- ZipEntry entry = zipInputStream .getNextEntry ();
67- if (entry == null ) break ;
68-
69- String entryName = entry .getName ();
70- if (!entryName .startsWith (mLibraryLocation ) || entry .isDirectory ()) continue ;
71- // Entry name is actually the full path, so we need to strip the path before extraction
72- entryName = FileUtils .getFileName (entryName );
73- // getFileName may make the file name null, avoid that case.
74- if (entryName == null || LIBRARY_BLACKLIST .contains (entryName )) continue ;
75-
76- processEntry (entryCopyStream , entry , new File (mDestinationDir , entryName ));
77- }
60+ byte [] buffer = new byte [8192 ];
61+ try (FileInputStream fileInputStream = new FileInputStream (source );
62+ ZipInputStream zipInputStream = new ZipInputStream (fileInputStream )) {
63+ // Wrap the ZIP input stream into a non-closeable stream to
64+ // avoid it being closed by processEntry()
65+ NonCloseableInputStream entryCopyStream = new NonCloseableInputStream (zipInputStream );
66+ ZipEntry entry ;
67+ while ((entry = zipInputStream .getNextEntry ()) != null ) {
68+ String entryName = entry .getName ();
69+ if (!entryName .startsWith (mLibraryLocation ) || entry .isDirectory ()) continue ;
70+ // Entry name is actually the full path, so we need to strip the path before extraction
71+ entryName = FileUtils .getFileName (entryName );
72+ // getFileName may make the file name null, avoid that case.
73+ if (entryName == null || LIBRARY_BLACKLIST .contains (entryName )) continue ;
74+
75+ processEntry (entryCopyStream , entry , new File (mDestinationDir , entryName ), buffer );
7876 }
7977 }
8078 }
8179
82- private static long fileCrc32 (File target ) throws IOException {
80+ private static long fileCrc32 (File target , byte [] buffer ) throws IOException {
8381 try (FileInputStream fileInputStream = new FileInputStream (target )) {
8482 CRC32 crc32 = new CRC32 ();
85- byte [] buffer = new byte [1024 ];
8683 int len ;
8784 while ((len = fileInputStream .read (buffer )) != -1 ) {
8885 crc32 .update (buffer , 0 , len );
@@ -91,12 +88,12 @@ private static long fileCrc32(File target) throws IOException {
9188 }
9289 }
9390
94- private void processEntry (InputStream sourceStream , ZipEntry zipEntry , File entryDestination ) throws IOException {
91+ private void processEntry (InputStream sourceStream , ZipEntry zipEntry , File entryDestination , byte [] buffer ) throws IOException {
9592 if (entryDestination .exists ()) {
9693 long expectedSize = zipEntry .getSize ();
9794 long expectedCrc32 = zipEntry .getCrc ();
9895 long realSize = entryDestination .length ();
99- long realCrc32 = fileCrc32 (entryDestination );
96+ long realCrc32 = fileCrc32 (entryDestination , buffer );
10097 // File in archive is the same as the local one, don't extract
10198 if (realSize == expectedSize && realCrc32 == expectedCrc32 ) return ;
10299 }
0 commit comments