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 intCENATTstatic intCENATXstatic intCENCOMstatic intCENCRCstatic intCENDSKstatic intCENEXTstatic intCENFLGstatic intCENHDRstatic intCENHOWstatic intCENLENstatic intCENNAMstatic intCENOFFstatic longCENSIGstatic intCENSIZstatic intCENTIMstatic intCENVEMstatic intCENVERstatic intENDCOMstatic intENDHDRstatic intENDOFFstatic longENDSIGstatic intENDSIZstatic intENDSUBstatic intENDTOTstatic intEXTCRCstatic intEXTHDRstatic intEXTLENstatic longEXTSIGstatic intEXTSIZstatic intLOCCRCstatic intLOCEXTstatic intLOCFLGstatic intLOCHDRstatic intLOCHOWstatic intLOCLENstatic intLOCNAMstatic longLOCSIGstatic intLOCSIZstatic intLOCTIMstatic intLOCVER
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 voidclearLoadedFilesList()Clears the loaded files list.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)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.HandlergetHandler()Gets the URL stream handler for the MemoryJarFile.java.io.InputStreamgetInputStream(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.JarEntrygetJarEntry(java.lang.String name)Gets the JAR entry with the specified name.java.io.FilegetJarFile()Gets the file of the Jar file.static XJarFilegetJarFile(java.io.File file)Loads the requested XJarFile or grabs one from the table of loaded files and reloads it as required.static XJarFilegetJarFile(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.ManifestgetManifest()Returns the jar file manifest, ornullif none.java.net.URLgetURL()Gets the XJar URL to be used with e.g.java.net.URLgetURL(java.lang.String path)Gets the XJar URL to be used with e.g.java.net.URLgetURL(java.util.zip.ZipEntry entry)Gets the XJar URL to be used with e.g.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.intsize()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.IOExceptionLoads 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.IOExceptionLoads 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.IOExceptionLoads 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.IOExceptionLoads 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
0Lis 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.readAttributesmethod may be used.- Specified by:
lastModifiedin interfaceIJarFile- Returns:
- A
longvalue representing the time the file was last modified, measured in milliseconds since the epoch (00:00:00 GMT, January 1, 1970), or0Lif the file does not exist or if an I/O error occurs - Throws:
java.lang.SecurityException- If a security manager exists and itsmethod 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:
getJarFilein interfaceIJarFile- Returns:
- The file.
getHandler
public Handler getHandler()
Gets the URL stream handler for the MemoryJarFile.- Specified by:
getHandlerin 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:
hasChangedin 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:
getJarEntriesin interfaceIJarFile- Returns:
- All the entries as a new array.
getInputStream
public java.io.InputStream getInputStream(java.util.zip.ZipEntry ze) throws java.io.IOExceptionReturns an input stream for reading the contents of the specified zip file entry.- Specified by:
getInputStreamin interfaceIJarFile- Overrides:
getInputStreamin 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:
getJarEntryin interfaceIJarFile- Overrides:
getJarEntryin classjava.util.jar.JarFile- Parameters:
name- The Jar file entry name.- Returns:
- The
JarEntryfor the given entry name ornullif 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:
sizein 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.IOExceptionReturns the jar file manifest, ornullif none.- Specified by:
getManifestin interfaceIJarFile- Overrides:
getManifestin classjava.util.jar.JarFile- Returns:
- the jar file manifest, or
nullif 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:
getEntryDatain 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:
getEntryDatain interfaceIJarFile- Parameters:
ze- the name of the entry.- Returns:
- the byte array or null if not found.
close
public void close() throws java.io.IOExceptionCloses the Jar file.Closing this Jar file will close all of the input streams previously returned by invocations of the
getInputStreammethod.