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 SummaryFieldsModifier and TypeFieldDescription- 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 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 SummaryConstructorsConstructorDescriptionLoads 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 SummaryModifier and TypeMethodDescription- static voidClears 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, or- nullif 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.- booleanChecks if the Jar file has changed since last call to this method, i.e.- longReturns 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- LOCSIGstatic final long LOCSIG- See Also:
 
- EXTSIGstatic final long EXTSIG- See Also:
 
- CENSIGstatic final long CENSIG- See Also:
 
- ENDSIGstatic final long ENDSIG- See Also:
 
- LOCHDRstatic final int LOCHDR- See Also:
 
- EXTHDRstatic final int EXTHDR- See Also:
 
- CENHDRstatic final int CENHDR- See Also:
 
- ENDHDRstatic final int ENDHDR- See Also:
 
- LOCVERstatic final int LOCVER- See Also:
 
- LOCFLGstatic final int LOCFLG- See Also:
 
- LOCHOWstatic final int LOCHOW- See Also:
 
- LOCTIMstatic final int LOCTIM- See Also:
 
- LOCCRCstatic final int LOCCRC- See Also:
 
- LOCSIZstatic final int LOCSIZ- See Also:
 
- LOCLENstatic final int LOCLEN- See Also:
 
- LOCNAMstatic final int LOCNAM- See Also:
 
- LOCEXTstatic final int LOCEXT- See Also:
 
- EXTCRCstatic final int EXTCRC- See Also:
 
- EXTSIZstatic final int EXTSIZ- See Also:
 
- EXTLENstatic final int EXTLEN- See Also:
 
- CENVEMstatic final int CENVEM- See Also:
 
- CENVERstatic final int CENVER- See Also:
 
- CENFLGstatic final int CENFLG- See Also:
 
- CENHOWstatic final int CENHOW- See Also:
 
- CENTIMstatic final int CENTIM- See Also:
 
- CENCRCstatic final int CENCRC- See Also:
 
- CENSIZstatic final int CENSIZ- See Also:
 
- CENLENstatic final int CENLEN- See Also:
 
- CENNAMstatic final int CENNAM- See Also:
 
- CENEXTstatic final int CENEXT- See Also:
 
- CENCOMstatic final int CENCOM- See Also:
 
- CENDSKstatic final int CENDSK- See Also:
 
- CENATTstatic final int CENATT- See Also:
 
- CENATXstatic final int CENATX- See Also:
 
- CENOFFstatic final int CENOFF- See Also:
 
- ENDSUBstatic final int ENDSUB- See Also:
 
- ENDTOTstatic final int ENDTOT- See Also:
 
- ENDSIZstatic final int ENDSIZ- See Also:
 
- ENDOFFstatic final int ENDOFF- See Also:
 
- ENDCOMstatic final int ENDCOM- See Also:
 
 
- Constructor Details- XJarFileLoads or opens the JAR file "inMemory", without "winStyle", but with "verify".- Parameters:
- name- the file name.
- Throws:
- IOException- for file failures.
 
- XJarFileLoads or opens the JAR file "inMemory", without "winStyle" and "verify".- Parameters:
- file- the file.
- Throws:
- IOException- for file failures.
 
- XJarFileLoads 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.
 
- XJarFileLoads 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- clearLoadedFilesListpublic static void clearLoadedFilesList()Clears the loaded files list.
- getJarFileLoads the requested XJarFile or grabs one from the table of loaded files and reloads it as required.- Throws:
- IOException- for file failures.
 
- getJarFileLoads 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.
 
- lastModifiedpublic 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 the- Files.readAttributesmethod may be used.- Specified by:
- lastModifiedin interface- IJarFile
- 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:
- SecurityException- If a security manager exists and its- SecurityManager.checkRead(java.lang.String)
 
- getJarFileGets the file of the Jar file.- Specified by:
- getJarFilein interface- IJarFile
- Returns:
- The file.
 
- getHandlerGets the URL stream handler for the MemoryJarFile.- Specified by:
- getHandlerin interface- IJarFile
- Returns:
- The stream handler.
 
- getURLGets the XJar URL to be used with e.g. a class loader.
- getURLGets the XJar URL to be used with e.g. a class loader.
- getURLGets the XJar URL to be used with e.g. a class loader.
- hasChangedpublic 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 interface- IJarFile
- Returns:
- true if the file has changed in size or last modified time, false otherwise.
 
- entriesReturns an enumeration of the Jar file entries.
- streamReturns a stream of Jar entries.
- getJarEntriesGets all Jar entries if the Jar file is loaded into memory.- Specified by:
- getJarEntriesin interface- IJarFile
- Returns:
- All the entries as a new array.
 
- getInputStreamReturns an input stream for reading the contents of the specified zip file entry.- Specified by:
- getInputStreamin interface- IJarFile
- Overrides:
- getInputStreamin class- JarFile
- 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.
 
- getJarEntryGets the JAR entry with the specified name.- Specified by:
- getJarEntryin interface- IJarFile
- Overrides:
- getJarEntryin class- JarFile
- Parameters:
- name- The Jar file entry name.
- Returns:
- The JarEntryfor the given entry name ornullif not found.
- See Also:
 
- getEntryGets the ZIP entry with the specified name.
- sizepublic int size()Returns the number of entries in the Jar file.- Overrides:
- sizein class- ZipFile
- Returns:
- the number of entries in the Jar file.
- Throws:
- IllegalStateException- if the Jar file has been closed.
 
- getManifestReturns the jar file manifest, or- nullif none.- Specified by:
- getManifestin interface- IJarFile
- Overrides:
- getManifestin class- JarFile
- Returns:
- the jar file manifest, or nullif none.
- Throws:
- IllegalStateException- may be thrown if the jar file has been closed
- IOException- If an I/O error has occurred.
 
- getEntryDataGets the byte [] data for an entry if present. This method only works when the file has been read into memory.- Specified by:
- getEntryDatain interface- IJarFile
- Parameters:
- name- the name of the entry.
- Returns:
- the byte array or null if not found.
 
- getEntryDataGets the byte [] data for an entry if present. This method only works when the file has been read into memory.- Specified by:
- getEntryDatain interface- IJarFile
- Parameters:
- ze- the name of the entry.
- Returns:
- the byte array or null if not found.
 
- closeCloses the Jar file.- Closing this Jar file will close all of the input streams previously returned by invocations of the - getInputStreammethod.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Specified by:
- closein interface- IJarFile
- Overrides:
- closein class- ZipFile
- Throws:
- IOException- if an I/O error has occurred.