use of java.util.zip.ZipFile in project buck by facebook.
the class ZipWriteTest method main.
public static void main(String[] args) throws IOException, InterruptedException {
try (CustomZipOutputStream zipOut = ZipOutputStreams.newOutputStream(Paths.get("/dev/null"), ZipOutputStreams.HandleDuplicates.APPEND_TO_ZIP)) {
try (ZipFile zipIn = new ZipFile(new File(args[0]))) {
for (Enumeration<? extends ZipEntry> entries = zipIn.entries(); entries.hasMoreElements(); ) {
ZipEntry entry = entries.nextElement();
ZipEntry newEntry = new ZipEntry(entry);
if (entry.getMethod() == ZipEntry.DEFLATED) {
newEntry.setCompressedSize(-1);
}
zipOut.putNextEntry(newEntry);
InputStream inputStream = zipIn.getInputStream(entry);
ByteStreams.copy(inputStream, zipOut);
zipOut.closeEntry();
}
}
}
System.gc();
Thread.sleep(TimeUnit.SECONDS.toMillis(1));
System.gc();
Thread.sleep(TimeUnit.SECONDS.toMillis(5));
}
use of java.util.zip.ZipFile in project buck by facebook.
the class GenAidlIntegrationTest method rootDirectoryDoesntChangeBuild.
@Test
public void rootDirectoryDoesntChangeBuild() throws IOException {
AssumeAndroidPlatform.assumeSdkIsAvailable();
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "cached_build", tmp);
workspace.setUp();
Path outputOne = workspace.buildAndReturnOutput("//:AService");
ProjectWorkspace workspaceTwo = TestDataHelper.createProjectWorkspaceForScenario(this, "cached_build", tmp2);
workspaceTwo.setUp();
Path outputTwo = workspaceTwo.buildAndReturnOutput("//:AService");
assertEquals(workspace.getBuildLog().getRuleKey("//:AService"), workspaceTwo.getBuildLog().getRuleKey("//:AService"));
try (ZipFile zipOne = new ZipFile(outputOne.toFile());
ZipFile zipTwo = new ZipFile(outputTwo.toFile())) {
Enumeration<? extends ZipEntry> entriesOne = zipOne.entries(), entriesTwo = zipTwo.entries();
while (entriesOne.hasMoreElements()) {
assertTrue(entriesTwo.hasMoreElements());
ZipEntry entryOne = entriesOne.nextElement(), entryTwo = entriesTwo.nextElement();
// Compare data first, otherwise crc difference will cause a failure and you don't get to
// see the actual difference.
assertEquals(zipEntryData(zipOne, entryOne), zipEntryData(zipTwo, entryTwo));
assertEquals(zipEntryDebugString(entryOne), zipEntryDebugString(entryTwo));
}
assertFalse(entriesTwo.hasMoreElements());
}
assertEquals(new String(Files.readAllBytes(outputOne)), new String(Files.readAllBytes(outputTwo)));
}
use of java.util.zip.ZipFile in project buck by facebook.
the class DefaultJavaLibraryIntegrationTest method testBuildJavaLibraryExportsDirectoryEntries.
@Test
public void testBuildJavaLibraryExportsDirectoryEntries() throws IOException {
workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "export_directory_entries", tmp);
workspace.setUp();
// Run `buck build`.
BuildTarget target = BuildTargetFactory.newInstance("//:empty_directory_entries");
ProcessResult buildResult = workspace.runBuckBuild(target.getFullyQualifiedName());
buildResult.assertSuccess();
Path outputFile = workspace.getPath(BuildTargets.getGenPath(filesystem, target, "lib__%s__output/" + target.getShortName() + ".jar"));
assertTrue(Files.exists(outputFile));
ImmutableSet.Builder<String> jarContents = ImmutableSet.builder();
try (ZipFile zipFile = new ZipFile(outputFile.toFile())) {
for (ZipEntry zipEntry : Collections.list(zipFile.entries())) {
jarContents.add(zipEntry.getName());
}
}
// TODO(mread): Change the output to the intended output.
assertEquals(jarContents.build(), ImmutableSet.of("META-INF/", "META-INF/MANIFEST.MF", "swag.txt", "yolo.txt"));
workspace.verify();
}
use of java.util.zip.ZipFile in project buck by facebook.
the class AbiClass method extract.
public static AbiClass extract(Path pathToJar, String className) throws IOException {
try (ZipFile zip = new ZipFile(pathToJar.toString())) {
ZipEntry entry = zip.getEntry(className);
if (entry == null) {
return null;
}
try (InputStream entryStream = zip.getInputStream(entry)) {
ClassReader reader = new ClassReader(entryStream);
ClassNode classNode = new ClassNode();
reader.accept(classNode, 0);
return new AbiClass(classNode);
}
}
}
use of java.util.zip.ZipFile in project buck by facebook.
the class GenruleIntegrationTest method assertZipsAreEqual.
private void assertZipsAreEqual(Path zipPathOne, Path zipPathTwo) throws IOException {
try (ZipFile zipOne = new ZipFile(zipPathOne.toFile());
ZipFile zipTwo = new ZipFile(zipPathTwo.toFile())) {
Enumeration<? extends ZipEntry> entriesOne = zipOne.entries(), entriesTwo = zipTwo.entries();
while (entriesOne.hasMoreElements()) {
assertTrue(entriesTwo.hasMoreElements());
ZipEntry entryOne = entriesOne.nextElement(), entryTwo = entriesTwo.nextElement();
assertEquals(zipEntryDebugString(entryOne), zipEntryDebugString(entryTwo));
assertEquals(zipEntryData(zipOne, entryOne), zipEntryData(zipTwo, entryTwo));
}
assertFalse(entriesTwo.hasMoreElements());
}
assertEquals(new String(Files.readAllBytes(zipPathOne)), new String(Files.readAllBytes(zipPathTwo)));
}
Aggregations