Skip to content

Commit

Permalink
Improve/document stream usages.
Browse files Browse the repository at this point in the history
  • Loading branch information
lazaroclapp committed Jun 24, 2020
1 parent 4ee7c6b commit 1a94206
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Expand Up @@ -278,6 +278,8 @@ public static void annotateBytecodeInJar(
// Do not use JarInputStream in place of JarFile/JarEntry. JarInputStream misses MANIFEST.MF
// while iterating over the entries in the stream.
// Reference: https://bugs.openjdk.java.net/browse/JDK-8215788
// Note: we can't just put the code below inside stream().forach(), because it can throw
// IOException.
for (JarEntry jarEntry : inputJar.stream().collect(ImmutableList.toImmutableList())) {
InputStream is = inputJar.getInputStream(jarEntry);
copyAndAnnotateJarEntry(
Expand Down
Expand Up @@ -16,6 +16,7 @@
package com.uber.nullaway.jarinfer;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
Expand Down Expand Up @@ -43,11 +44,11 @@ public static boolean compareEntriesInJars(String jarFile1, String jarFile2) thr
Preconditions.checkArgument(jarFile1.endsWith(".jar"), "invalid jar file: " + jarFile1);
Preconditions.checkArgument(jarFile2.endsWith(".jar"), "invalid jar file: " + jarFile2);
JarFile jar1 = new JarFile(jarFile1);
Set<String> jar1Entries = new HashSet<>();
jar1.stream().forEach(entry -> jar1Entries.add(entry.getName()));
JarFile jar2 = new JarFile(jarFile2);
Set<String> jar2Entries = new HashSet<>();
jar2.stream().forEach(entry -> jar2Entries.add(entry.getName()));
Set<String> jar1Entries =
jar1.stream().map(ZipEntry::getName).collect(ImmutableSet.toImmutableSet());
Set<String> jar2Entries =
jar2.stream().map(ZipEntry::getName).collect(ImmutableSet.toImmutableSet());
return jar1Entries.equals(jar2Entries);
}

Expand All @@ -65,11 +66,11 @@ public static boolean compareEntriesInAars(String aarFile1, String aarFile2) thr
Preconditions.checkArgument(aarFile1.endsWith(".aar"), "invalid aar file: " + aarFile1);
Preconditions.checkArgument(aarFile2.endsWith(".aar"), "invalid aar file: " + aarFile2);
ZipFile zip1 = new ZipFile(aarFile1);
Set<String> zip1Entries = new HashSet<>();
zip1.stream().forEach(entry -> zip1Entries.add(entry.getName()));
ZipFile zip2 = new ZipFile(aarFile2);
Set<String> zip2Entries = new HashSet<>();
zip2.stream().forEach(entry -> zip2Entries.add(entry.getName()));
Set<String> zip1Entries =
zip1.stream().map(ZipEntry::getName).collect(ImmutableSet.toImmutableSet());
Set<String> zip2Entries =
zip2.stream().map(ZipEntry::getName).collect(ImmutableSet.toImmutableSet());
if (!zip1Entries.equals(zip2Entries)) {
return false;
}
Expand Down

0 comments on commit 1a94206

Please sign in to comment.