Package com.iizix.util
Interface IJarFile
- All Superinterfaces:
AutoCloseable
,Closeable
- All Known Implementing Classes:
MemoryJarFile
,XJarFile
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
Modifier and TypeMethodDescriptionvoid
close()
Closes the Jar file.entries()
Returns an enumeration of the Jar file entries.Returns the zip file entry for the specified name, or null if not found.byte[]
getEntryData
(String name) Gets the byte [] data for an entry if present.byte[]
getEntryData
(ZipEntry ze) Gets the byte [] data for an entry if present.Gets the URL stream handler.Returns an input stream for reading the contents of the specified Zip/Jar file entry.JarEntry[]
Gets all Jar entries if the Jar file is loaded into memory.getJarEntry
(String name) Returns theJarEntry
for the given entry name ornull
if not found.Gets the file of the Jar file.Returns the Jar file manifest, ornull
if none.getName()
Returns the path name of the Zip/Jar file.getURL()
Gets the MemoryJar URL to be used with e.g.Gets the MemoryJar URL to be used with e.g.Gets the MemoryJar URL to be used with e.g.default boolean
Checks if the Jar file has changed since last call to this method, i.e.long
Returns the time that the file denoted by this abstract pathname was last modified.stream()
Returns a stream of Jar entries.
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, ornull
for a memory Jar as there is no validFile
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 theFiles.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), or0L
if the file does not exist or if an I/O error occurs - Throws:
SecurityException
- If a security manager exists and its
method denies read access to the fileSecurityManager.checkRead(java.lang.String)
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
Returns the Jar file manifest, ornull
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
Returns a stream of Jar entries.- Returns:
- an ordered, distinct, immutable and non-null stream of the Jar file entries.
getEntry
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
Returns theJarEntry
for the given entry name ornull
if not found.- Parameters:
name
- The Jar file entry name.- Returns:
- The
JarEntry
for the given entry name ornull
if not found. - Throws:
IllegalStateException
- May be thrown if the Jar file has been closed.- See Also:
getInputStream
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
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
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
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
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
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 interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
- if an I/O error has occurred.