本文整理了Java中com.android.tools.build.apkzlib.zip.ZFile
类的一些代码示例,展示了ZFile
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZFile
类的具体详情如下:
包路径:com.android.tools.build.apkzlib.zip.ZFile
类名称:ZFile
暂无
代码示例来源:origin: google/bundletool
minSdkVersion);
ZFile zAapt2Files =
new ZFile(binaryApk.toFile(), createZFileOptions(tempDir), /* readOnly= */ true)) {
zOutputApk.mergeFrom(zAapt2Files, /* ignoreFilter= */ Predicates.alwaysFalse());
zOutputApk.sortZipContents();
} catch (IOException e) {
throw new UncheckedIOException(
代码示例来源:origin: google/bundletool
/** Takes the given APK and adds the files that weren't processed by AAPT2. */
private void addNonAapt2Files(ZFile zFile, ModuleSplit split) throws IOException {
boolean extractNativeLibs = split.getAndroidManifest().getExtractNativeLibsValue().orElse(true);
// Add the non-Aapt2 files.
for (ModuleEntry entry : split.getEntries()) {
ZipPath pathInApk = toApkEntryPath(entry.getPath());
if (!FILES_FOR_AAPT2.apply(pathInApk)) {
try (InputStream entryInputStream = entry.getContent()) {
zFile.add(
pathInApk.toString(),
entryInputStream,
shouldCompress(pathInApk, !extractNativeLibs, entry.shouldCompress()));
}
}
}
}
代码示例来源:origin: google/bundletool
/**
* Checks whether a zip file has been correctly zipaligned.
*
* @return {@code true} if the file has been correctly zipaligned.
*/
public static boolean checkAlignment(File zip) throws IOException {
try (ZFile zfile = new ZFile(zip)) {
for (StoredEntry entry : zfile.entries()) {
CentralDirectoryHeader header = entry.getCentralDirectoryHeader();
// Alignment only applies to uncompressed files.
if (header.getCompressionInfoWithWait().getMethod().equals(CompressionMethod.STORE)) {
int expectedAligment =
NATIVE_LIB_PATTERN.matcher(header.getName()).matches()
? PAGE_ALIGNMENT
: FOUR_BYTE_ALIGNMENT;
long dataOffset = header.getOffset() + entry.getLocalHeaderSize();
if (dataOffset % expectedAligment != 0) {
System.out.println(
String.format(
"File '%s' is not aligned. dataOffset=%d, expectedAlignment=%d",
header.getName(), dataOffset, expectedAligment));
return false;
}
}
}
}
return true;
}
内容来源于网络,如有侵权,请联系作者删除!