diff --git a/brut.apktool/apktool-lib/src/main/java/brut/androlib/Androlib.java b/brut.apktool/apktool-lib/src/main/java/brut/androlib/Androlib.java index ea09ce30..05377560 100644 --- a/brut.apktool/apktool-lib/src/main/java/brut/androlib/Androlib.java +++ b/brut.apktool/apktool-lib/src/main/java/brut/androlib/Androlib.java @@ -29,13 +29,10 @@ import brut.directory.*; import brut.util.BrutIO; import brut.util.OS; import java.io.*; -import java.nio.file.*; -import java.nio.file.Path; import java.util.*; import java.util.logging.Logger; import java.util.zip.CRC32; import java.util.zip.ZipEntry; -import java.nio.file.Files; import java.util.zip.ZipFile; import java.util.zip.ZipOutputStream; @@ -583,7 +580,7 @@ public class Androlib { // No need to create directory entries in the final apk if (!entry.isDirectory()) { - copy(inputFile.getInputStream(entry), outputFile, buffer); + BrutIO.copy(inputFile.getInputStream(entry), outputFile, buffer); } outputFile.closeEntry(); @@ -609,38 +606,21 @@ public class Androlib { newEntry.setSize(inputFile.length()); newEntry.setCompressedSize(-1); BufferedInputStream unknownFile = new BufferedInputStream(new FileInputStream(inputFile)); - CRC32 crc = calculateCrc(unknownFile, buffer); + CRC32 crc = BrutIO.calculateCrc(unknownFile, buffer); newEntry.setCrc(crc.getValue()); LOGGER.fine("\tsize: " + newEntry.getSize()); - } - else { + } else { newEntry.setMethod(ZipEntry.DEFLATED); } outputFile.putNextEntry(newEntry); BufferedInputStream unknownFile = new BufferedInputStream(new FileInputStream(inputFile)); - copy(unknownFile, outputFile, buffer); + BrutIO.copy(unknownFile, outputFile, buffer); outputFile.closeEntry(); } } - private CRC32 calculateCrc(InputStream input, byte[] buffer) throws IOException { - CRC32 crc = new CRC32(); - int bytesRead = 0; - while((bytesRead = input.read(buffer)) != -1) { - crc.update(buffer, 0, bytesRead); - } - return crc; - } - - private static void copy(InputStream input, OutputStream output, byte[] buffer) throws IOException { - int bytesRead; - while((bytesRead = input.read(buffer)) != -1) { - output.write(buffer, 0, bytesRead); - } - } - public void buildApk(File appDir, File outApk) throws AndrolibException { LOGGER.info("Building apk file..."); if (outApk.exists()) { diff --git a/brut.j.util/src/main/java/brut/util/BrutIO.java b/brut.j.util/src/main/java/brut/util/BrutIO.java index b91c1092..a5ea49fd 100644 --- a/brut.j.util/src/main/java/brut/util/BrutIO.java +++ b/brut.j.util/src/main/java/brut/util/BrutIO.java @@ -17,6 +17,8 @@ package brut.util; import java.io.*; +import java.util.zip.CRC32; + import org.apache.commons.io.IOUtils; /** @@ -59,4 +61,20 @@ public class BrutIO { } return modified; } + + public static CRC32 calculateCrc(InputStream input, byte[] buffer) throws IOException { + CRC32 crc = new CRC32(); + int bytesRead = 0; + while((bytesRead = input.read(buffer)) != -1) { + crc.update(buffer, 0, bytesRead); + } + return crc; + } + + public static void copy(InputStream input, OutputStream output, byte[] buffer) throws IOException { + int bytesRead; + while((bytesRead = input.read(buffer)) != -1) { + output.write(buffer, 0, bytesRead); + } + } }