use of java.util.zip.ZipOutputStream in project bazel by bazelbuild.
the class SplitZipFiltersTest method createZip.
private File createZip(String... entries) throws FileNotFoundException, IOException {
File zip = tmp.newFile();
int count = 0;
try (ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(zip))) {
for (String entry : entries) {
zout.putNextEntry(new ZipEntry(entry));
// unique content
zout.write(("contents" + count++).getBytes(UTF_8));
zout.closeEntry();
}
}
return zip;
}
use of java.util.zip.ZipOutputStream in project platform_frameworks_base by android.
the class PackageHelper method extractPublicFiles.
/**
* Extract public files for the single given APK.
*/
public static long extractPublicFiles(File apkFile, File publicZipFile) throws IOException {
final FileOutputStream fstr;
final ZipOutputStream publicZipOutStream;
if (publicZipFile == null) {
fstr = null;
publicZipOutStream = null;
} else {
fstr = new FileOutputStream(publicZipFile);
publicZipOutStream = new ZipOutputStream(fstr);
Log.d(TAG, "Extracting " + apkFile + " to " + publicZipFile);
}
long size = 0L;
try {
final ZipFile privateZip = new ZipFile(apkFile.getAbsolutePath());
try {
// Copy manifest, resources.arsc and res directory to public zip
for (final ZipEntry zipEntry : Collections.list(privateZip.entries())) {
final String zipEntryName = zipEntry.getName();
if ("AndroidManifest.xml".equals(zipEntryName) || "resources.arsc".equals(zipEntryName) || zipEntryName.startsWith("res/")) {
size += zipEntry.getSize();
if (publicZipFile != null) {
copyZipEntry(zipEntry, privateZip, publicZipOutStream);
}
}
}
} finally {
try {
privateZip.close();
} catch (IOException e) {
}
}
if (publicZipFile != null) {
publicZipOutStream.finish();
publicZipOutStream.flush();
FileUtils.sync(fstr);
publicZipOutStream.close();
FileUtils.setPermissions(publicZipFile.getAbsolutePath(), FileUtils.S_IRUSR | FileUtils.S_IWUSR | FileUtils.S_IRGRP | FileUtils.S_IROTH, -1, -1);
}
} finally {
IoUtils.closeQuietly(publicZipOutStream);
}
return size;
}
use of java.util.zip.ZipOutputStream in project gradle by gradle.
the class RuntimeShadedJarCreator method openJarOutputStream.
private ZipOutputStream openJarOutputStream(File outputJar) {
try {
ZipOutputStream outputStream = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outputJar), BUFFER_SIZE));
outputStream.setLevel(0);
return outputStream;
} catch (IOException e) {
throw UncheckedException.throwAsUncheckedException(e);
}
}
use of java.util.zip.ZipOutputStream in project gradle by gradle.
the class RuntimeShadedJarCreator method createFatJar.
private void createFatJar(final File outputJar, final Iterable<? extends File> files, final ProgressLogger progressLogger) {
final File tmpFile = tempFileFor(outputJar);
IoActions.withResource(openJarOutputStream(tmpFile), new ErroringAction<ZipOutputStream>() {
@Override
protected void doExecute(ZipOutputStream jarOutputStream) throws Exception {
processFiles(jarOutputStream, files, new byte[BUFFER_SIZE], new HashSet<String>(), new LinkedHashMap<String, List<String>>(), progressLogger);
jarOutputStream.finish();
}
});
GFileUtils.moveFile(tmpFile, outputJar);
}
use of java.util.zip.ZipOutputStream in project j2objc by google.
the class ZipEntryTest method testMaxLengthExtra_zip64.
public void testMaxLengthExtra_zip64() throws Exception {
// Not quite the max length (65535), but large enough that there's no space
// for the zip64 extended info header.
byte[] maxLengthExtra = new byte[65530];
File f = createTemporaryZipFile();
ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(f)), true);
ZipEntry ze = new ZipEntry("x");
ze.setExtra(maxLengthExtra);
try {
out.putNextEntry(ze);
fail();
} catch (ZipException expected) {
}
}
Aggregations