Package com.iizix.util
Class MemoryJarFile
java.lang.Object
java.util.zip.ZipFile
java.util.jar.JarFile
com.iizix.util.MemoryJarFile
- 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 is used to load entirely into memory and supports decryption on entry basis.
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
- Method SummaryModifier and TypeMethodDescription- void- close()Closes the ZIP file.- static MemoryJarFile- createJarFile- (File file, boolean verify, boolean winStyle, MemoryJarFileDecrypter streamDecrypter, MemoryJarFileDecrypter entryDecrypter) Creates a memory Jar file.- static MemoryJarFile- createJarFile- (InputStream in, boolean verify, boolean winStyle, MemoryJarFileDecrypter streamDecrypter, MemoryJarFileDecrypter entryDecrypter, long lastModified) Creates a memory Jar file.- static MemoryJarFile- createJarFile- (String fileName, boolean verify, boolean winStyle, MemoryJarFileDecrypter streamDecrypter, MemoryJarFileDecrypter entryDecrypter) Creates a memory Jar file.- static MemoryJarFile- createJarFile- (JarInputStream jin, boolean winStyle, long lastModified) Creates a memory Jar file.- static MemoryJarFile- createJarFile- (JarInputStream jin, boolean winStyle, MemoryJarFileDecrypter decrypter, long lastModified) Creates a memory Jar file.- static MemoryJarFile- createJarFile- (JarInputStream jin, long lastModified) Creates a memory Jar file.- entries()Returns an enumeration of the Jar file entries.- byte[]- getByteArray- (ZipEntry ze) Returns the byte array of the contents of the specified zip file entry.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.Returns the Jar file manifest, or- nullif none.- getName()Gets the name of the 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.- longReturns the time that the file denoted by this abstract pathname was last modified.- voidSets the name of the Jar file.- 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- Methods inherited from class java.lang.Object- clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait- Methods inherited from interface com.iizix.util.IJarFile- hasChanged
- 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:
 
 
- Method Details- createJarFileCreates a memory Jar file. The Jar input stream is closed before returning, the new Jar file will not have the 'winStyle' parameter set.- Parameters:
- jin- the Jar input stream.
- lastModified- time for last file modification, -1L for when the first empty Jar was created.
- Throws:
- IOException- for file failures.
 
- createJarFilepublic static MemoryJarFile createJarFile- (JarInputStream jin, boolean winStyle, long lastModified) throws IOException Creates a memory Jar file. The Jar input stream is closed before returning.- Parameters:
- jin- the Jar input stream.
- winStyle- if true, the entries are case insensitive and backslash can be used with forward slash as well.
- lastModified- time for last file modification, -1L for when the first empty Jar was created.
- Throws:
- IOException- for file failures.
 
- createJarFilepublic static MemoryJarFile createJarFile- (JarInputStream jin, boolean winStyle, MemoryJarFileDecrypter decrypter, long lastModified) throws IOException Creates a memory Jar file. The Jar input stream is closed before returning.- Parameters:
- jin- the Jar input stream.
- winStyle- if true, the entries are case insensitive and backslash can be used with forward slash as well.
- decrypter- an instance of a class implementing the MemoryJarFileDecrypter interface to provide decryption of an entry.
- lastModified- time for last file modification, -1L for when the first empty Jar was created.
- Throws:
- IOException- for file failures.
 
- createJarFilepublic static MemoryJarFile createJarFile- (InputStream in, boolean verify, boolean winStyle, MemoryJarFileDecrypter streamDecrypter, MemoryJarFileDecrypter entryDecrypter, long lastModified) throws IOException Creates a memory Jar file. The input stream is closed before returning.- Parameters:
- in- an input stream.
- verify- set to true to verify the Jar file for correctness.
- winStyle- if true, the entries are case insensitive and backslash can be used with forward slash as well.
- streamDecrypter- an instance of a class implementing the MemoryJarFileDecrypter interface to provide decryption of the entire input stream data, set to- nullfor no decryption.
- entryDecrypter- an instance of a class implementing the MemoryJarFileDecrypter interface to provide decryption of an entry, set to- nullfor no decryption.
- lastModified- time for last file modification, -1L for when the first empty Jar was created.
- Throws:
- IOException- for file failures.
 
- createJarFilepublic static MemoryJarFile createJarFile- (String fileName, boolean verify, boolean winStyle, MemoryJarFileDecrypter streamDecrypter, MemoryJarFileDecrypter entryDecrypter) throws IOException Creates a memory Jar file. The file is closed before returning.- Parameters:
- fileName- the file name of Jar file to read.
- verify- set to true to verify the Jar file for correctness.
- winStyle- if true, the entries are case insensitive and backslash can be used with forward slash as well.
- streamDecrypter- an instance of a class implementing the MemoryJarFileDecrypter interface to provide decryption of the entire input stream data, set to- nullfor no decryption.
- entryDecrypter- an instance of a class implementing the MemoryJarFileDecrypter interface to provide decryption of an entry, set to- nullfor no decryption.
- Throws:
- IOException- for file failures.
 
- createJarFilepublic static MemoryJarFile createJarFile- (File file, boolean verify, boolean winStyle, MemoryJarFileDecrypter streamDecrypter, MemoryJarFileDecrypter entryDecrypter) throws IOException Creates a memory Jar file. The File is closed before returning.- Parameters:
- file- the Jar File instance to read.
- verify- set to true to verify the Jar file for correctness.
- winStyle- if true, the entries are case insensitive and backslash can be used with forward slash as well.
- streamDecrypter- an instance of a class implementing the MemoryJarFileDecrypter interface to provide decryption of the entire input stream data, set to- nullfor no decryption.
- entryDecrypter- an instance of a class implementing the MemoryJarFileDecrypter interface to provide decryption of an entry, set to- nullfor no decryption.
- Throws:
- IOException- for file failures.
 
- getJarFileGets the file of the Jar file.- Specified by:
- getJarFilein interface- IJarFile
- Returns:
- Always returns nullas there is noFilerepresentation for a memory Jar.
 
- lastModifiedpublic long lastModified()Returns the time that the file denoted by this abstract pathname was last modified.- 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
 
- getHandlerGets the URL stream handler for the MemoryJarFile.- Specified by:
- getHandlerin interface- IJarFile
- Returns:
- The stream handler.
 
- getURLGets the MemoryJar URL to be used with e.g. a class loader.
- getURLGets the MemoryJar URL to be used with e.g. a class loader.
- getURLGets the MemoryJar URL to be used with e.g. a class loader.
- 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:
- FileNotFoundException- if the entry isn't found.
 
- getByteArrayReturns the byte array of the contents of the specified zip file entry.- Returns:
- the byte array of the contents of the specified zip file entry
- Throws:
- FileNotFoundException- if the entry isn't found.
 
- getJarEntryGets the Jar entry with the specified name.- Specified by:
- getJarEntryin interface- IJarFile
- Overrides:
- getJarEntryin class- JarFile
- Parameters:
- name- name of the Jar entry, 'winStyle' parameter applies, i.e. '\' is translated to '/' and the name check is done case insensitive.
- Returns:
- the JarEntry found, or null for not found.
- See Also:
 
- getEntryGets the Zip entry with the specified name.
- sizepublic int size()Returns the number of entries in the Jar file.
- 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.
 
- getNameGets the name of the Jar file. If no name has been assigned using- setName, the "real" temporary Jar file name from the temporary directory is returned.
- setNameSets the name of the Jar file. The- getNamemethod will return that name (if non-null), or the "real" temporary Jar file name from the temporary directory if the- nameparameter is- null.- Parameters:
- name- the name of the Jar file or null to reset it to the "real" temporary Jar file.
 
- getEntryDataGets the byte [] data for an entry if present.- 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.- Specified by:
- getEntryDatain interface- IJarFile
- Parameters:
- ze- the name of the entry.
- Returns:
- the byte array or null if not found.
 
- closeCloses the ZIP file.- Closing this ZIP 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