RFR: 8211917: (zipfs) Creating or updating a JAR file system should put the MANIFEST.MF at the start

Jaikiran Pai jai.forums2013 at gmail.com
Tue Feb 18 08:29:05 UTC 2020


Hello Christoph,

On 17/02/20 9:56 pm, Langer, Christoph wrote:
> Hi Jaikiran, Lance,
>
> I'm a bit late to the game. It occurred to me, whether we could maybe use the streams API to process the inodes. Something like this:
>
> diff --git a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java
> --- a/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java
> +++ b/src/jdk.zipfs/share/classes/jdk/nio/zipfs/ZipFileSystem.java
> @@ -56,6 +56,7 @@
>  import java.util.jar.Attributes;
>  import java.util.jar.Manifest;
>  import java.util.regex.Pattern;
> +import java.util.stream.Stream;
>  import java.util.zip.CRC32;
>  import java.util.zip.Deflater;
>  import java.util.zip.DeflaterOutputStream;
> @@ -1730,7 +1731,17 @@
>              Entry e;
>
>              // write loc
> -            for (IndexNode inode : inodes.values()) {
> +
> +            // write the manifest inode (if any) first in the loc so that the
> +            // java.util.jar.JarInputStream can find it, since it expects it to be
> +            // the first or second entry in the jar
> +            final IndexNode manifestInode = getInode(getBytes("/META-INF/MANIFEST.MF"));
> +            final Stream<IndexNode> inodeStream = manifestInode == null ?
> +                inodes.values().stream() :
> +                Stream.concat(Stream.of(manifestInode),
> +                    inodes.values().stream().filter(node -> !manifestInode.equals(node)));
> +
> +            for (IndexNode inode : (Iterable<IndexNode>)inodeStream::iterator) {


I don't have any practical experience with Stream and how it performs.
Would using Stream here introduce any kind of performance penalty,
especially when the number of entries in the jar is high?

-Jaikiran



More information about the nio-dev mailing list