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
,java.io.Closeable
,java.lang.AutoCloseable
public class MemoryJarFile 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 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 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
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the ZIP file.static MemoryJarFile
createJarFile(java.io.File file, boolean verify, boolean winStyle, MemoryJarFileDecrypter streamDecrypter, MemoryJarFileDecrypter entryDecrypter)
Creates a memory Jar file.static MemoryJarFile
createJarFile(java.io.InputStream in, boolean verify, boolean winStyle, MemoryJarFileDecrypter streamDecrypter, MemoryJarFileDecrypter entryDecrypter, long lastModified)
Creates a memory Jar file.static MemoryJarFile
createJarFile(java.lang.String fileName, boolean verify, boolean winStyle, MemoryJarFileDecrypter streamDecrypter, MemoryJarFileDecrypter entryDecrypter)
Creates a memory Jar file.static MemoryJarFile
createJarFile(java.util.jar.JarInputStream jin, boolean winStyle, long lastModified)
Creates a memory Jar file.static MemoryJarFile
createJarFile(java.util.jar.JarInputStream jin, boolean winStyle, MemoryJarFileDecrypter decrypter, long lastModified)
Creates a memory Jar file.static MemoryJarFile
createJarFile(java.util.jar.JarInputStream jin, long lastModified)
Creates a memory Jar file.java.util.Enumeration<java.util.jar.JarEntry>
entries()
Returns an enumeration of the Jar file entries.byte[]
getByteArray(java.util.zip.ZipEntry ze)
Returns the byte array of the contents of the specified zip file entry.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.java.util.jar.Manifest
getManifest()
Returns the Jar file manifest, ornull
if none.java.lang.String
getName()
Gets the name of the Jar file.java.net.URL
getURL()
Gets the MemoryJar URL to be used with e.g.java.net.URL
getURL(java.lang.String path)
Gets the MemoryJar URL to be used with e.g.java.net.URL
getURL(java.util.zip.ZipEntry entry)
Gets the MemoryJar URL to be used with e.g.long
lastModified()
Returns the time that the file denoted by this abstract pathname was last modified.void
setName(java.lang.String name)
Sets the name of the Jar file.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
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.iizix.util.IJarFile
hasChanged
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
Method Detail
createJarFile
public static MemoryJarFile createJarFile(java.util.jar.JarInputStream jin, long lastModified) throws java.io.IOException
Creates 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:
java.io.IOException
- for file failures.
createJarFile
public static MemoryJarFile createJarFile(java.util.jar.JarInputStream jin, boolean winStyle, long lastModified) throws java.io.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:
java.io.IOException
- for file failures.
createJarFile
public static MemoryJarFile createJarFile(java.util.jar.JarInputStream jin, boolean winStyle, MemoryJarFileDecrypter decrypter, long lastModified) throws java.io.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:
java.io.IOException
- for file failures.
createJarFile
public static MemoryJarFile createJarFile(java.io.InputStream in, boolean verify, boolean winStyle, MemoryJarFileDecrypter streamDecrypter, MemoryJarFileDecrypter entryDecrypter, long lastModified) throws java.io.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 tonull
for no decryption.entryDecrypter
- an instance of a class implementing the MemoryJarFileDecrypter interface to provide decryption of an entry, set tonull
for no decryption.lastModified
- time for last file modification, -1L for when the first empty Jar was created.- Throws:
java.io.IOException
- for file failures.
createJarFile
public static MemoryJarFile createJarFile(java.lang.String fileName, boolean verify, boolean winStyle, MemoryJarFileDecrypter streamDecrypter, MemoryJarFileDecrypter entryDecrypter) throws java.io.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 tonull
for no decryption.entryDecrypter
- an instance of a class implementing the MemoryJarFileDecrypter interface to provide decryption of an entry, set tonull
for no decryption.- Throws:
java.io.IOException
- for file failures.
createJarFile
public static MemoryJarFile createJarFile(java.io.File file, boolean verify, boolean winStyle, MemoryJarFileDecrypter streamDecrypter, MemoryJarFileDecrypter entryDecrypter) throws java.io.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 tonull
for no decryption.entryDecrypter
- an instance of a class implementing the MemoryJarFileDecrypter interface to provide decryption of an entry, set tonull
for no decryption.- Throws:
java.io.IOException
- for file failures.
getJarFile
public java.io.File getJarFile()
Gets the file of the Jar file.- Specified by:
getJarFile
in interfaceIJarFile
- Returns:
- Always returns
null
as there is noFile
representation for a memory Jar.
lastModified
public long lastModified()
Returns the time that the file denoted by this abstract pathname was last modified.- 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
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 MemoryJar URL to be used with e.g. a class loader.
getURL
public java.net.URL getURL(java.util.zip.ZipEntry entry)
Gets the MemoryJar URL to be used with e.g. a class loader.
getURL
public java.net.URL getURL(java.lang.String path)
Gets the MemoryJar URL to be used with e.g. a class loader.
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.FileNotFoundException
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.io.FileNotFoundException
- if the entry isn't found.
getByteArray
public byte[] getByteArray(java.util.zip.ZipEntry ze) throws java.io.FileNotFoundException
Returns 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:
java.io.FileNotFoundException
- if the entry isn't found.
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
- 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:
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.
getManifest
public java.util.jar.Manifest getManifest()
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.
getName
public java.lang.String getName()
Gets the name of the Jar file. If no name has been assigned usingsetName
, the "real" temporary Jar file name from the temporary directory is returned.
setName
public void setName(java.lang.String name)
Sets the name of the Jar file. ThegetName
method will return that name (if non-null), or the "real" temporary Jar file name from the temporary directory if thename
parameter isnull
.- Parameters:
name
- the name of the Jar file or null to reset it to the "real" temporary Jar file.
getEntryData
public byte[] getEntryData(java.lang.String name)
Gets the byte [] data for an entry if present.- 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.- 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 ZIP file.Closing this ZIP file will close all of the input streams previously returned by invocations of the
getInputStream
method.