Package com.iizix.util
Class XJarFile
java.lang.Object
java.util.zip.ZipFile
java.util.jar.JarFile
com.iizix.util.XJarFile
- All Implemented Interfaces:
IJarFile
,Closeable
,AutoCloseable
Extends the normal JAR file for processing files with various character case, and mixture of forward and backslashes. It also supports loading the entire file into memory and then unlocking the file in the file system. A check if the file has changed is also supported, in order to create manual or automatic file reload (i.e. application re-deploy).
Please note that this class currently only supports file items smaller than 2 GB, i.e. a 31 bit long positive integer value.
- Author:
- Christopher Mindus
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final long
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final long
static final int
static final int
static final int
static final int
static final int
static final int
static final long
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final long
static final int
static final int
static final int
Fields inherited from class java.util.jar.JarFile
MANIFEST_NAME
Fields inherited from class java.util.zip.ZipFile
OPEN_DELETE, OPEN_READ
Constructor Summary
ConstructorDescriptionLoads or opens the JAR file "inMemory", without "winStyle" and "verify".Loads or opens the JAR file.Loads or opens the JAR file "inMemory", without "winStyle", but with "verify".Loads or opens the JAR file.Method Summary
Modifier and TypeMethodDescriptionstatic void
Clears the loaded files list.void
close()
Closes the Jar file.entries()
Returns an enumeration of the Jar file entries.Gets the ZIP entry with the specified name.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 for the MemoryJarFile.Returns an input stream for reading the contents of the specified zip file entry.JarEntry[]
Gets all Jar entries if the Jar file is loaded into memory.getJarEntry
(String name) Gets the JAR entry with the specified name.Gets the file of the Jar file.static XJarFile
getJarFile
(File file) Loads the requested XJarFile or grabs one from the table of loaded files and reloads it as required.static XJarFile
getJarFile
(String fileName) Loads the requested XJarFile or grabs one from the table of loaded files and reloads it as required.Returns the jar file manifest, ornull
if none.getURL()
Gets the XJar URL to be used with e.g.Gets the XJar URL to be used with e.g.Gets the XJar URL to be used with e.g.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.int
size()
Returns the number of entries in the Jar file.stream()
Returns a stream of Jar entries.Methods inherited from class java.util.jar.JarFile
baseVersion, getVersion, isMultiRelease, runtimeVersion, versionedStream
Methods inherited from class java.util.zip.ZipFile
getComment, getName
Field Details
LOCSIG
static final long LOCSIG- See Also:
EXTSIG
static final long EXTSIG- See Also:
CENSIG
static final long CENSIG- See Also:
ENDSIG
static final long ENDSIG- See Also:
LOCHDR
static final int LOCHDR- See Also:
EXTHDR
static final int EXTHDR- See Also:
CENHDR
static final int CENHDR- See Also:
ENDHDR
static final int ENDHDR- See Also:
LOCVER
static final int LOCVER- See Also:
LOCFLG
static final int LOCFLG- See Also:
LOCHOW
static final int LOCHOW- See Also:
LOCTIM
static final int LOCTIM- See Also:
LOCCRC
static final int LOCCRC- See Also:
LOCSIZ
static final int LOCSIZ- See Also:
LOCLEN
static final int LOCLEN- See Also:
LOCNAM
static final int LOCNAM- See Also:
LOCEXT
static final int LOCEXT- See Also:
EXTCRC
static final int EXTCRC- See Also:
EXTSIZ
static final int EXTSIZ- See Also:
EXTLEN
static final int EXTLEN- See Also:
CENVEM
static final int CENVEM- See Also:
CENVER
static final int CENVER- See Also:
CENFLG
static final int CENFLG- See Also:
CENHOW
static final int CENHOW- See Also:
CENTIM
static final int CENTIM- See Also:
CENCRC
static final int CENCRC- See Also:
CENSIZ
static final int CENSIZ- See Also:
CENLEN
static final int CENLEN- See Also:
CENNAM
static final int CENNAM- See Also:
CENEXT
static final int CENEXT- See Also:
CENCOM
static final int CENCOM- See Also:
CENDSK
static final int CENDSK- See Also:
CENATT
static final int CENATT- See Also:
CENATX
static final int CENATX- See Also:
CENOFF
static final int CENOFF- See Also:
ENDSUB
static final int ENDSUB- See Also:
ENDTOT
static final int ENDTOT- See Also:
ENDSIZ
static final int ENDSIZ- See Also:
ENDOFF
static final int ENDOFF- See Also:
ENDCOM
static final int ENDCOM- See Also:
Constructor Details
XJarFile
Loads or opens the JAR file "inMemory", without "winStyle", but with "verify".- Parameters:
name
- the file name.- Throws:
IOException
- for file failures.
XJarFile
Loads or opens the JAR file "inMemory", without "winStyle" and "verify".- Parameters:
file
- the file.- Throws:
IOException
- for file failures.
XJarFile
Loads or opens the JAR file.- Parameters:
name
- the file name.inMemory
- if true, the entire Jar file is loaded into memory and then closed. Subsequent operations can be performed as normal.winStyle
- if true, the entries are case insensitive and backslash can be used with forward slash as well.verify
- if the Jar file should be verified.- Throws:
IOException
- for file failures.
XJarFile
Loads or opens the JAR file.- Parameters:
file
- the file.inMemory
- if true, the entire Jar file is loaded into memory and then closed. Subsequent operations can be performed as normal.winStyle
- if true, the entries are case insensitive and backslash can be used with forward slash as well.verify
- if the Jar file should be verified.- Throws:
IOException
- for file failures.
Method Details
clearLoadedFilesList
public static void clearLoadedFilesList()Clears the loaded files list.getJarFile
Loads the requested XJarFile or grabs one from the table of loaded files and reloads it as required.- Throws:
IOException
- for file failures.
getJarFile
Loads the requested XJarFile or grabs one from the table of loaded files and reloads it as required. If the loading of this Jar file is done in another thread, this thread will first complete it's loading.- Throws:
IOException
- for file failures.
lastModified
public long lastModified()Returns the time that the file denoted by this abstract pathname was last modified.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.- Specified by:
lastModified
in interfaceIJarFile
- 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)
getJarFile
Gets the file of the Jar file.- Specified by:
getJarFile
in interfaceIJarFile
- Returns:
- The file.
getHandler
Gets the URL stream handler for the MemoryJarFile.- Specified by:
getHandler
in interfaceIJarFile
- Returns:
- The stream handler.
getURL
Gets the XJar URL to be used with e.g. a class loader.getURL
Gets the XJar URL to be used with e.g. a class loader.getURL
Gets the XJar URL to be used with e.g. a class loader.hasChanged
public 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.- Specified by:
hasChanged
in interfaceIJarFile
- Returns:
- true if the file has changed in size or last modified time, false otherwise.
entries
Returns an enumeration of the Jar file entries.stream
Returns a stream of Jar entries.getJarEntries
Gets all Jar entries if the Jar file is loaded into memory.- Specified by:
getJarEntries
in interfaceIJarFile
- Returns:
- All the entries as a new array.
getInputStream
Returns an input stream for reading the contents of the specified zip file entry.- Specified by:
getInputStream
in interfaceIJarFile
- Overrides:
getInputStream
in classJarFile
- Parameters:
ze
- The Zip or Jar file entry.- Returns:
- an input stream for reading the contents of the specified zip file entry
- Throws:
ZipException
- if a zip 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.
getJarEntry
Gets the JAR entry with the specified name.- Specified by:
getJarEntry
in interfaceIJarFile
- Overrides:
getJarEntry
in classJarFile
- Parameters:
name
- The Jar file entry name.- Returns:
- The
JarEntry
for the given entry name ornull
if not found. - See Also:
getEntry
Gets the ZIP entry with the specified name.size
public int size()Returns the number of entries in the Jar file.- Overrides:
size
in classZipFile
- Returns:
- the number of entries in the Jar file.
- Throws:
IllegalStateException
- if the Jar file has been closed.
getManifest
Returns the jar file manifest, ornull
if none.- Specified by:
getManifest
in interfaceIJarFile
- Overrides:
getManifest
in classJarFile
- Returns:
- the jar file manifest, or
null
if none. - Throws:
IllegalStateException
- may be thrown if the jar file has been closedIOException
- If an I/O error has occurred.
getEntryData
Gets the byte [] data for an entry if present. This method only works when the file has been read into memory.- Specified by:
getEntryData
in interfaceIJarFile
- 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. This method only works when the file has been read into memory.- Specified by:
getEntryData
in interfaceIJarFile
- Parameters:
ze
- the name of the entry.- Returns:
- the byte array or null if not found.
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
- Specified by:
close
in interfaceIJarFile
- Overrides:
close
in classZipFile
- Throws:
IOException
- if an I/O error has occurred.