mirror of
https://github.com/iBotPeaches/Apktool.git
synced 2024-12-04 18:46:49 +00:00
Moving a couple utility functions into BrutIO. Also, formatting change to match spec.
This commit is contained in:
parent
472a02db41
commit
39a2848340
@ -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()) {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user