Interface IJarFile

All Superinterfaces:
AutoCloseable, Closeable
All Known Implementing Classes:
MemoryJarFile, XJarFile

public interface IJarFile extends 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 Details

    • getName

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

      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:
      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

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

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

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

      ZipEntry getEntry(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:
      IllegalStateException - If the Zip file has been closed.
    • getJarEntry

      JarEntry getJarEntry(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:
      IllegalStateException - May be thrown if the Jar file has been closed.
      See Also:
    • getInputStream

      InputStream getInputStream(ZipEntry ze) throws 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:
      ZipException - If a Zip/Jar file format error has occurred.
      IOException - If an I/O error has occurred.
      SecurityException - If any of the Jar file entries are incorrectly signed.
      IllegalStateException - May be thrown if the Jar file has been closed.
    • getURL

      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

      URL getURL(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

      URL getURL(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

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

      byte[] getEntryData(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(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

      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 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 AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - if an I/O error has occurred.