Interface IJarFile

  • All Superinterfaces:
    java.lang.AutoCloseable, java.io.Closeable
    All Known Implementing Classes:
    MemoryJarFile, XJarFile

    public interface IJarFile
    extends java.io.Closeable
    Methods to get the URL from the Jar or memory Jar file, its stream handler and the byte array data of an Zip (Jar) entry.
    Author:
    Christopher Mindus
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and TypeMethodDescription
      voidclose()
      Closes the Jar file.
      java.util.Enumeration<java.util.jar.JarEntry>entries()
      Returns an enumeration of the Jar file entries.
      java.util.zip.ZipEntrygetEntry​(java.lang.String name)
      Returns the zip file entry for the specified name, or null if not found.
      byte[]getEntryData​(java.lang.String name)
      Gets the byte [] data for an entry if present.
      byte[]getEntryData​(java.util.zip.ZipEntry ze)
      Gets the byte [] data for an entry if present.
      java.net.URLStreamHandlergetHandler()
      Gets the URL stream handler.
      java.io.InputStreamgetInputStream​(java.util.zip.ZipEntry ze)
      Returns an input stream for reading the contents of the specified Zip/Jar file entry.
      java.util.jar.JarEntry[]getJarEntries()
      Gets all Jar entries if the Jar file is loaded into memory.
      java.util.jar.JarEntrygetJarEntry​(java.lang.String name)
      Returns the JarEntry for the given entry name or null if not found.
      java.io.FilegetJarFile()
      Gets the file of the Jar file.
      java.util.jar.ManifestgetManifest()
      Returns the Jar file manifest, or null if none.
      java.lang.StringgetName()
      Returns the path name of the Zip/Jar file.
      java.net.URLgetURL()
      Gets the MemoryJar URL to be used with e.g.
      java.net.URLgetURL​(java.lang.String path)
      Gets the MemoryJar URL to be used with e.g.
      java.net.URLgetURL​(java.util.zip.ZipEntry entry)
      Gets the MemoryJar URL to be used with e.g.
      default booleanhasChanged()
      Checks if the Jar file has changed since last call to this method, i.e.
      longlastModified()
      Returns the time that the file denoted by this abstract pathname was last modified.
      java.util.stream.Stream<java.util.jar.JarEntry>stream()
      Returns a stream of Jar entries.
    • Method Detail

      • getName

        java.lang.String getName()
        Returns the path name of the Zip/Jar file.
        Returns:
        the path name of the Zip/Jar file.
      • getJarFile

        java.io.File getJarFile()
        Gets the file of the Jar file.
        Returns:
        The Jar File used to load the Jar file, or null for a memory Jar as there is no valid File representation for it.
      • lastModified

        long lastModified()
        Returns the time that the file denoted by this abstract pathname was last modified.

        If it's a memory Jar file, this is provided when creating the memory Jar file.

        Where it is required to distinguish an I/O exception from the case where 0L is returned, or where several attributes of the same file are required at the same time, or where the time of last access or the creation time are required, then the Files.readAttributes method may be used.

        Returns:
        A long value representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs
        Throws:
        java.lang.SecurityException - If a security manager exists and its SecurityManager.checkRead(java.lang.String) method denies read access to the file
      • hasChanged

        default boolean hasChanged()
        Checks if the Jar file has changed since last call to this method, i.e. this means that the new last modified time and file size is saved.
        Returns:
        true if the file has changed in size or last modified time, false otherwise.
      • getManifest

        java.util.jar.Manifest getManifest()
                                    throws java.io.IOException
        Returns the Jar file manifest, or null if none.
        Returns:
        the Jar file manifest, or null if none
        Throws:
        java.lang.IllegalStateException - May be thrown if the Jar file has been closed.
        java.io.IOException - If an I/O error has occurred.
      • entries

        java.util.Enumeration<java.util.jar.JarEntry> entries()
        Returns an enumeration of the Jar file entries.
        Returns:
        An enumeration of the JarEntry's.
      • stream

        java.util.stream.Stream<java.util.jar.JarEntry> stream()
        Returns a stream of Jar entries.
        Returns:
        an ordered, distinct, immutable and non-null stream of the Jar file entries.
      • getEntry

        java.util.zip.ZipEntry getEntry​(java.lang.String name)
        Returns the zip file entry for the specified name, or null if not found.
        Parameters:
        name - The name of the entry.
        Returns:
        The Zip file entry, or null if not found.
        Throws:
        java.lang.IllegalStateException - If the Zip file has been closed.
      • getJarEntry

        java.util.jar.JarEntry getJarEntry​(java.lang.String name)
        Returns the JarEntry for the given entry name or null if not found.
        Parameters:
        name - The Jar file entry name.
        Returns:
        The JarEntry for the given entry name or null if not found.
        Throws:
        java.lang.IllegalStateException - May be thrown if the Jar file has been closed.
        See Also:
        JarEntry
      • getInputStream

        java.io.InputStream getInputStream​(java.util.zip.ZipEntry ze)
                                    throws java.io.IOException
        Returns an input stream for reading the contents of the specified Zip/Jar file entry.
        Parameters:
        ze - The Zip or Jar file entry.
        Returns:
        An input stream for reading the contents of the specified Zip/Jar file entry.
        Throws:
        java.util.zip.ZipException - If a Zip/Jar file format error has occurred.
        java.io.IOException - If an I/O error has occurred.
        java.lang.SecurityException - If any of the Jar file entries are incorrectly signed.
        java.lang.IllegalStateException - May be thrown if the Jar file has been closed.
      • getURL

        java.net.URL getURL()
        Gets the MemoryJar URL to be used with e.g. a class loader.
        Returns:
        An URL with the stream handler initialized to this Jar file.
      • getURL

        java.net.URL getURL​(java.util.zip.ZipEntry entry)
        Gets the MemoryJar URL to be used with e.g. a class loader.
        Parameters:
        entry - The Jar entry.
        Returns:
        An URL with the stream handler initialized to this Jar file.
      • getURL

        java.net.URL getURL​(java.lang.String path)
        Gets the MemoryJar URL to be used with e.g. a class loader.
        Parameters:
        path - A path specification.
        Returns:
        An URL with the stream handler initialized to this Jar file.
      • getHandler

        java.net.URLStreamHandler getHandler()
        Gets the URL stream handler.
        Returns:
        The URL stream handler.
      • getEntryData

        byte[] getEntryData​(java.lang.String name)
        Gets the byte [] data for an entry if present.
        Parameters:
        name - the name of the entry.
        Returns:
        the byte array or null if not found.
      • getEntryData

        byte[] getEntryData​(java.util.zip.ZipEntry ze)
        Gets the byte [] data for an entry if present.
        Parameters:
        ze - the name of the entry.
        Returns:
        the byte array or null if not found.
      • getJarEntries

        java.util.jar.JarEntry[] getJarEntries()
        Gets all Jar entries if the Jar file is loaded into memory.
        Returns:
        All the entries as a new array.
      • close

        void close()
            throws java.io.IOException
        Closes the Jar file.

        Closing this Jar file will close all of the input streams previously returned by invocations of the getInputStream method.

        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException - if an I/O error has occurred.