use of com.android.zipflinger.LargeFileSource in project bundletool by google.
the class ApkSetWriter method zip.
/**
* Creates ApkSet writer which stores all splits as ZIP archive.
*/
static ApkSetWriter zip(Path tempDirectory, Path outputFile) {
return new ApkSetWriter() {
@Override
public Path getSplitsDirectory() {
return tempDirectory;
}
@Override
public void writeApkSet(BuildApksResult toc) throws IOException {
Stream<ApkDescription> apks = toc.getVariantList().stream().flatMap(variant -> variant.getApkSetList().stream()).flatMap(apkSet -> apkSet.getApkDescriptionList().stream());
Stream<ApkDescription> assets = toc.getAssetSliceSetList().stream().flatMap(assetSliceSet -> assetSliceSet.getApkDescriptionList().stream());
ImmutableSet<String> apkRelativePaths = Stream.concat(apks, assets).map(ApkDescription::getPath).sorted().collect(toImmutableSet());
zipApkSet(apkRelativePaths, toc.toByteArray());
}
@Override
public void writeApkSet(BuildSdkApksResult toc) throws IOException {
Stream<ApkDescription> apks = toc.getVariantList().stream().flatMap(variant -> variant.getApkSetList().stream()).flatMap(apkSet -> apkSet.getApkDescriptionList().stream());
ImmutableSet<String> apkRelativePaths = apks.map(ApkDescription::getPath).sorted().collect(toImmutableSet());
zipApkSet(apkRelativePaths, toc.toByteArray());
}
private void zipApkSet(ImmutableSet<String> apkRelativePaths, byte[] tocBytes) throws IOException {
try (ZipArchive zipArchive = new ZipArchive(outputFile)) {
zipArchive.add(new BytesSource(tocBytes, TABLE_OF_CONTENTS_FILE, Deflater.NO_COMPRESSION));
for (String relativePath : apkRelativePaths) {
zipArchive.add(new LargeFileSource(getSplitsDirectory().resolve(relativePath), /* tmpStorage= */
null, relativePath, Deflater.NO_COMPRESSION));
}
}
}
};
}
Aggregations