use of java.util.zip.ZipInputStream in project buck by facebook.
the class AaptPackageResourcesIntegrationTest method testAaptPackageIsScrubbed.
@Test
public void testAaptPackageIsScrubbed() throws IOException {
AssumeAndroidPlatform.assumeSdkIsAvailable();
workspace.runBuckBuild(MAIN_BUILD_TARGET).assertSuccess();
Path aaptOutput = workspace.getPath(BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance(MAIN_BUILD_TARGET).withFlavors(AndroidBinaryGraphEnhancer.AAPT_PACKAGE_FLAVOR), AaptPackageResources.RESOURCE_APK_PATH_FORMAT));
Date dosEpoch = new Date(ZipUtil.dosToJavaTime(ZipConstants.DOS_FAKE_TIME));
try (ZipInputStream is = new ZipInputStream(new FileInputStream(aaptOutput.toFile()))) {
for (ZipEntry entry = is.getNextEntry(); entry != null; entry = is.getNextEntry()) {
assertThat(entry.getName(), new Date(entry.getTime()), Matchers.equalTo(dosEpoch));
}
}
}
use of java.util.zip.ZipInputStream in project buck by facebook.
the class ProjectFilesystemTest method testCreateZipIgnoresMtimes.
@Test
public void testCreateZipIgnoresMtimes() throws IOException {
// Create a empty executable file.
Path exe = tmp.newFile("foo");
// Archive it into a zipfile using `ProjectFileSystem.createZip`.
Path zipFile = tmp.getRoot().resolve("test.zip");
filesystem.createZip(ImmutableList.of(exe), zipFile);
// Iterate over each of the entries, expecting to see all zeros in the time fields.
Date dosEpoch = new Date(ZipUtil.dosToJavaTime(ZipConstants.DOS_FAKE_TIME));
try (ZipInputStream is = new ZipInputStream(Files.newInputStream(zipFile))) {
for (ZipEntry entry = is.getNextEntry(); entry != null; entry = is.getNextEntry()) {
assertEquals(entry.getName(), dosEpoch, new Date(entry.getTime()));
}
}
}
use of java.util.zip.ZipInputStream in project buck by facebook.
the class JarDirectoryStepTest method jarsShouldContainDirectoryEntries.
@Test
public void jarsShouldContainDirectoryEntries() throws IOException {
Path zipup = folder.newFolder("dir-zip");
Path subdir = zipup.resolve("dir/subdir");
Files.createDirectories(subdir);
Files.write(subdir.resolve("a.txt"), "cake".getBytes());
JarDirectoryStep step = new JarDirectoryStep(new ProjectFilesystem(zipup), Paths.get("output.jar"), ImmutableSortedSet.of(zipup), /* main class */
null, /* manifest file */
null);
ExecutionContext context = TestExecutionContext.newInstance();
int returnCode = step.execute(context).getExitCode();
assertEquals(0, returnCode);
Path zip = zipup.resolve("output.jar");
assertTrue(Files.exists(zip));
// Iterate over each of the entries, expecting to see the directory names as entries.
Set<String> expected = Sets.newHashSet("dir/", "dir/subdir/");
try (ZipInputStream is = new ZipInputStream(Files.newInputStream(zip))) {
for (ZipEntry entry = is.getNextEntry(); entry != null; entry = is.getNextEntry()) {
expected.remove(entry.getName());
}
}
assertTrue("Didn't see entries for: " + expected, expected.isEmpty());
}
use of java.util.zip.ZipInputStream in project tinker by Tencent.
the class DexDiffPatchInternal method patchDexFile.
/**
* Generate patched dex file (May wrapped it by a jar if needed.)
* @param baseApk
* OldApk.
* @param patchPkg
* Patch package, it is also a zip file.
* @param oldDexEntry
* ZipEntry of old dex.
* @param patchFileEntry
* ZipEntry of patch file. (also ends with .dex) This could be null.
* @param patchInfo
* Parsed patch info from package-meta.txt
* @param patchedDexFile
* Patched dex file, may be a jar.
*
* <b>Notice: patchFileEntry and smallPatchInfoFile cannot both be null.</b>
*
* @throws IOException
*/
private static void patchDexFile(ZipFile baseApk, ZipFile patchPkg, ZipEntry oldDexEntry, ZipEntry patchFileEntry, ShareDexDiffPatchInfo patchInfo, File patchedDexFile) throws IOException {
InputStream oldDexStream = null;
InputStream patchFileStream = null;
try {
oldDexStream = new BufferedInputStream(baseApk.getInputStream(oldDexEntry));
patchFileStream = (patchFileEntry != null ? new BufferedInputStream(patchPkg.getInputStream(patchFileEntry)) : null);
final boolean isRawDexFile = SharePatchFileUtil.isRawDexFile(patchInfo.rawName);
if (!isRawDexFile || patchInfo.isJarMode) {
ZipOutputStream zos = null;
try {
zos = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(patchedDexFile)));
zos.putNextEntry(new ZipEntry(ShareConstants.DEX_IN_JAR));
// Old dex is not a raw dex file.
if (!isRawDexFile) {
ZipInputStream zis = null;
try {
zis = new ZipInputStream(oldDexStream);
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
if (ShareConstants.DEX_IN_JAR.equals(entry.getName()))
break;
}
if (entry == null) {
throw new TinkerRuntimeException("can't recognize zip dex format file:" + patchedDexFile.getAbsolutePath());
}
new DexPatchApplier(zis, patchFileStream).executeAndSaveTo(zos);
} finally {
SharePatchFileUtil.closeQuietly(zis);
}
} else {
new DexPatchApplier(oldDexStream, patchFileStream).executeAndSaveTo(zos);
}
zos.closeEntry();
} finally {
SharePatchFileUtil.closeQuietly(zos);
}
} else {
new DexPatchApplier(oldDexStream, patchFileStream).executeAndSaveTo(patchedDexFile);
}
} finally {
SharePatchFileUtil.closeQuietly(oldDexStream);
SharePatchFileUtil.closeQuietly(patchFileStream);
}
}
use of java.util.zip.ZipInputStream in project Fairphone by Kwamecorp.
the class GappsInstallerHelper method unzip.
public void unzip(String filePath, String targetPath) {
new File(targetPath).mkdirs();
try {
FileInputStream fin = new FileInputStream(filePath);
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
Log.d(TAG, "Unzipping " + ze.getName());
if (ze.isDirectory()) {
_dirChecker(ze.getName(), targetPath);
} else {
FileOutputStream fout = new FileOutputStream(targetPath + ze.getName());
byte[] buffer = new byte[2048];
int count = 0;
while ((count = zin.read(buffer)) != -1) {
fout.write(buffer, 0, count);
}
zin.closeEntry();
fout.close();
}
}
zin.close();
fin.close();
} catch (Exception e) {
Log.e("Decompress", "unzip", e);
}
}
Aggregations