Class ZipNioArchive

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, Archive

    public class ZipNioArchive
    extends java.lang.Object
    Archive leveraging Java NIO File and its Zip File System Provider.

    It doesn't support accessing nested zip files (for subpackages, compare with JDK-8247441)

    Since:
    3.5.2 (package version 2.11.0)
    • Constructor Detail

      • ZipNioArchive

        public ZipNioArchive​(java.nio.file.Path path)
        Shortcut for ZipNioArchive(Path, boolean) with false as second parameter.
        Parameters:
        path - the path of the zip file
      • ZipNioArchive

        public ZipNioArchive​(java.nio.file.Path path,
                             boolean deleteAtClose)
        Parameters:
        path - the path of the zip file
        deleteAtClose - if true removes the file with the given path during close()
    • Method Detail

      • open

        public void open​(boolean strict)
                  throws java.io.IOException
        Description copied from interface: Archive
        Opens the archive.
        Parameters:
        strict - if true open will fail if there was an internal error while parsing meta data.
        Throws:
        java.io.IOException - if an error occurs
      • openInputStream

        @Nullable
        public @Nullable java.io.InputStream openInputStream​(@Nullable
                                                             @Nullable Archive.Entry entry)
                                                      throws java.io.IOException
        Description copied from interface: Archive
        Opens an input stream for the given entry. Requires a previous call to Archive.open(boolean).
        Parameters:
        entry - the entry
        Returns:
        the input stream or null if the entry can't be read
        Throws:
        java.io.IOException - if an error occurs
      • getInputSource

        @Nullable
        public @Nullable VaultInputSource getInputSource​(@Nullable
                                                         @Nullable Archive.Entry entry)
                                                  throws java.io.IOException
        Description copied from interface: Archive
        Returns an input source for the given entry. Requires a previous call to Archive.open(boolean).
        Parameters:
        entry - the entry
        Returns:
        the input source or null if the entry can't be read
        Throws:
        java.io.IOException - if an error occurs
      • getRoot

        @NotNull
        public @NotNull Archive.Entry getRoot()
                                       throws java.io.IOException
        Description copied from interface: Archive
        Returns the root entry. Requires a previous call to Archive.open(boolean).
        Returns:
        the root entry.
        Throws:
        java.io.IOException - if an error occurs
      • getMetaInf

        @NotNull
        public @NotNull MetaInf getMetaInf()
        Description copied from interface: Archive
        Returns the meta inf. If the archive provides no specific meta data, a default, empty meta inf is returned. Requires a previous call to Archive.open(boolean).
        Returns:
        the meta inf.
      • close

        public void close()
        Description copied from interface: Archive
        Closes the archive. Only necessary to call if the archive has been opened.
      • getEntry

        public Archive.Entry getEntry​(java.lang.String path)
                               throws java.io.IOException
        Description copied from interface: Archive
        Returns the entry specified by path. Requires a previous call to Archive.open(boolean).
        Specified by:
        getEntry in interface Archive
        Parameters:
        path - the path
        Returns:
        the entry or null if not found.
        Throws:
        java.io.IOException - if an error occurs
      • getJcrRoot

        public Archive.Entry getJcrRoot()
                                 throws java.io.IOException
        Description copied from interface: Archive
        Returns the entry that specifies the "jcr_root". if no such entry exists, null is returned. Requires a previous call to Archive.open(boolean).
        Specified by:
        getJcrRoot in interface Archive
        Returns:
        the jcr_root entry or null
        Throws:
        java.io.IOException - if an error occurs
      • getSubArchive

        public Archive getSubArchive​(java.lang.String rootPath,
                                     boolean asJcrRoot)
                              throws java.io.IOException
        Description copied from interface: Archive
        Returns a sub archive that is rooted at the given path. Note that sub archives currently can't have their own meta inf and are closed automatically if their container archive is closed. Requires a previous call to Archive.open(boolean).
        Specified by:
        getSubArchive in interface Archive
        Parameters:
        rootPath - root path
        asJcrRoot - if true the given root is the jcr_root
        Returns:
        the archive or null if entry specified by root does not exist.
        Throws:
        java.io.IOException - if an error occurs