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
,java.io.Closeable
,java.lang.AutoCloseable
public class XJarFile extends java.util.jar.JarFile implements IJarFile
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
Fields Modifier and Type Field Description static int
CENATT
static int
CENATX
static int
CENCOM
static int
CENCRC
static int
CENDSK
static int
CENEXT
static int
CENFLG
static int
CENHDR
static int
CENHOW
static int
CENLEN
static int
CENNAM
static int
CENOFF
static long
CENSIG
static int
CENSIZ
static int
CENTIM
static int
CENVEM
static int
CENVER
static int
ENDCOM
static int
ENDHDR
static int
ENDOFF
static long
ENDSIG
static int
ENDSIZ
static int
ENDSUB
static int
ENDTOT
static int
EXTCRC
static int
EXTHDR
static int
EXTLEN
static long
EXTSIG
static int
EXTSIZ
static int
LOCCRC
static int
LOCEXT
static int
LOCFLG
static int
LOCHDR
static int
LOCHOW
static int
LOCLEN
static int
LOCNAM
static long
LOCSIG
static int
LOCSIZ
static int
LOCTIM
static int
LOCVER
Constructor Summary
Constructors Constructor Description XJarFile(java.io.File file)
Loads or opens the JAR file "inMemory", without "winStyle" and "verify".XJarFile(java.io.File file, boolean inMemory, boolean winStyle, boolean verify)
Loads or opens the JAR file.XJarFile(java.lang.String name)
Loads or opens the JAR file "inMemory", without "winStyle", but with "verify".XJarFile(java.lang.String name, boolean inMemory, boolean winStyle, boolean verify)
Loads or opens the JAR file.
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
clearLoadedFilesList()
Clears the loaded files list.void
close()
Closes the Jar file.java.util.Enumeration<java.util.jar.JarEntry>
entries()
Returns an enumeration of the Jar file entries.java.util.zip.ZipEntry
getEntry(java.lang.String name)
Gets the ZIP entry with the specified name.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.Handler
getHandler()
Gets the URL stream handler for the MemoryJarFile.java.io.InputStream
getInputStream(java.util.zip.ZipEntry ze)
Returns an input stream for reading the contents of the specified zip file entry.java.util.jar.JarEntry[]
getJarEntries()
Gets all Jar entries if the Jar file is loaded into memory.java.util.jar.JarEntry
getJarEntry(java.lang.String name)
Gets the JAR entry with the specified name.java.io.File
getJarFile()
Gets the file of the Jar file.static XJarFile
getJarFile(java.io.File file)
Loads the requested XJarFile or grabs one from the table of loaded files and reloads it as required.static XJarFile
getJarFile(java.lang.String fileName)
Loads the requested XJarFile or grabs one from the table of loaded files and reloads it as required.java.util.jar.Manifest
getManifest()
Returns the jar file manifest, ornull
if none.java.net.URL
getURL()
Gets the XJar URL to be used with e.g.java.net.URL
getURL(java.lang.String path)
Gets the XJar URL to be used with e.g.java.net.URL
getURL(java.util.zip.ZipEntry entry)
Gets the XJar URL to be used with e.g.boolean
hasChanged()
Checks if the Jar file has changed since last call to this method, i.e.long
lastModified()
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.java.util.stream.Stream<java.util.jar.JarEntry>
stream()
Returns a stream of Jar entries.Methods inherited from class java.util.jar.JarFile
baseVersion, getVersion, isMultiRelease, runtimeVersion, versionedStream
Field Detail
LOCSIG
public static final long LOCSIG
- See Also:
- Constant Field Values
EXTSIG
public static final long EXTSIG
- See Also:
- Constant Field Values
CENSIG
public static final long CENSIG
- See Also:
- Constant Field Values
ENDSIG
public static final long ENDSIG
- See Also:
- Constant Field Values
LOCHDR
public static final int LOCHDR
- See Also:
- Constant Field Values
EXTHDR
public static final int EXTHDR
- See Also:
- Constant Field Values
CENHDR
public static final int CENHDR
- See Also:
- Constant Field Values
ENDHDR
public static final int ENDHDR
- See Also:
- Constant Field Values
LOCVER
public static final int LOCVER
- See Also:
- Constant Field Values
LOCFLG
public static final int LOCFLG
- See Also:
- Constant Field Values
LOCHOW
public static final int LOCHOW
- See Also:
- Constant Field Values
LOCTIM
public static final int LOCTIM
- See Also:
- Constant Field Values
LOCCRC
public static final int LOCCRC
- See Also:
- Constant Field Values
LOCSIZ
public static final int LOCSIZ
- See Also:
- Constant Field Values
LOCLEN
public static final int LOCLEN
- See Also:
- Constant Field Values
LOCNAM
public static final int LOCNAM
- See Also:
- Constant Field Values
LOCEXT
public static final int LOCEXT
- See Also:
- Constant Field Values
EXTCRC
public static final int EXTCRC
- See Also:
- Constant Field Values
EXTSIZ
public static final int EXTSIZ
- See Also:
- Constant Field Values
EXTLEN
public static final int EXTLEN
- See Also:
- Constant Field Values
CENVEM
public static final int CENVEM
- See Also:
- Constant Field Values
CENVER
public static final int CENVER
- See Also:
- Constant Field Values
CENFLG
public static final int CENFLG
- See Also:
- Constant Field Values
CENHOW
public static final int CENHOW
- See Also:
- Constant Field Values
CENTIM
public static final int CENTIM
- See Also:
- Constant Field Values
CENCRC
public static final int CENCRC
- See Also:
- Constant Field Values
CENSIZ
public static final int CENSIZ
- See Also:
- Constant Field Values
CENLEN
public static final int CENLEN
- See Also:
- Constant Field Values
CENNAM
public static final int CENNAM
- See Also:
- Constant Field Values
CENEXT
public static final int CENEXT
- See Also:
- Constant Field Values
CENCOM
public static final int CENCOM
- See Also:
- Constant Field Values
CENDSK
public static final int CENDSK
- See Also:
- Constant Field Values
CENATT
public static final int CENATT
- See Also:
- Constant Field Values
CENATX
public static final int CENATX
- See Also:
- Constant Field Values
CENOFF
public static final int CENOFF
- See Also:
- Constant Field Values
ENDSUB
public static final int ENDSUB
- See Also:
- Constant Field Values
ENDTOT
public static final int ENDTOT
- See Also:
- Constant Field Values
ENDSIZ
public static final int ENDSIZ
- See Also:
- Constant Field Values
ENDOFF
public static final int ENDOFF
- See Also:
- Constant Field Values
ENDCOM
public static final int ENDCOM
- See Also:
- Constant Field Values
Constructor Detail
XJarFile
public XJarFile(java.lang.String name) throws java.io.IOException
Loads or opens the JAR file "inMemory", without "winStyle", but with "verify".- Parameters:
name
- the file name.- Throws:
java.io.IOException
- for file failures.
XJarFile
public XJarFile(java.io.File file) throws java.io.IOException
Loads or opens the JAR file "inMemory", without "winStyle" and "verify".- Parameters:
file
- the file.- Throws:
java.io.IOException
- for file failures.
XJarFile
public XJarFile(java.lang.String name, boolean inMemory, boolean winStyle, boolean verify) throws java.io.IOException
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:
java.io.IOException
- for file failures.
XJarFile
public XJarFile(java.io.File file, boolean inMemory, boolean winStyle, boolean verify) throws java.io.IOException
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:
java.io.IOException
- for file failures.
Method Detail
clearLoadedFilesList
public static void clearLoadedFilesList()
Clears the loaded files list.
getJarFile
public static XJarFile getJarFile(java.lang.String fileName) throws java.io.IOException
Loads the requested XJarFile or grabs one from the table of loaded files and reloads it as required.- Throws:
java.io.IOException
- for file failures.
getJarFile
public static XJarFile getJarFile(java.io.File file) throws java.io.IOException
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:
java.io.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:
java.lang.SecurityException
- If a security manager exists and its
method denies read access to the fileSecurityManager.checkRead(java.lang.String)
getJarFile
public java.io.File getJarFile()
Gets the file of the Jar file.- Specified by:
getJarFile
in interfaceIJarFile
- Returns:
- The file.
getHandler
public Handler getHandler()
Gets the URL stream handler for the MemoryJarFile.- Specified by:
getHandler
in interfaceIJarFile
- Returns:
- The stream handler.
getURL
public java.net.URL getURL()
Gets the XJar URL to be used with e.g. a class loader.
getURL
public java.net.URL getURL(java.util.zip.ZipEntry entry)
Gets the XJar URL to be used with e.g. a class loader.
getURL
public java.net.URL getURL(java.lang.String path)
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
public java.util.Enumeration<java.util.jar.JarEntry> entries()
Returns an enumeration of the Jar file entries.
stream
public java.util.stream.Stream<java.util.jar.JarEntry> stream()
Returns a stream of Jar entries.
getJarEntries
public java.util.jar.JarEntry[] 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
public 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 file entry.- Specified by:
getInputStream
in interfaceIJarFile
- Overrides:
getInputStream
in classjava.util.jar.JarFile
- Parameters:
ze
- The Zip or Jar file entry.- Returns:
- an input stream for reading the contents of the specified zip file entry
- Throws:
java.util.zip.ZipException
- if a zip 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.
getJarEntry
public java.util.jar.JarEntry getJarEntry(java.lang.String name)
Gets the JAR entry with the specified name.- Specified by:
getJarEntry
in interfaceIJarFile
- Overrides:
getJarEntry
in classjava.util.jar.JarFile
- Parameters:
name
- The Jar file entry name.- Returns:
- The
JarEntry
for the given entry name ornull
if not found. - See Also:
JarEntry
getEntry
public java.util.zip.ZipEntry getEntry(java.lang.String name)
Gets the ZIP entry with the specified name.
size
public int size()
Returns the number of entries in the Jar file.- Overrides:
size
in classjava.util.zip.ZipFile
- Returns:
- the number of entries in the Jar file.
- Throws:
java.lang.IllegalStateException
- if the Jar file has been closed.
getManifest
public java.util.jar.Manifest getManifest() throws java.io.IOException
Returns the jar file manifest, ornull
if none.- Specified by:
getManifest
in interfaceIJarFile
- Overrides:
getManifest
in classjava.util.jar.JarFile
- Returns:
- the jar file manifest, or
null
if none. - Throws:
java.lang.IllegalStateException
- may be thrown if the jar file has been closedjava.io.IOException
- If an I/O error has occurred.
getEntryData
public byte[] getEntryData(java.lang.String name)
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
public byte[] getEntryData(java.util.zip.ZipEntry ze)
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
public 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.