Package org.apache.felix.framework.util
Class WeakZipFileFactory.WeakZipFile
- java.lang.Object
-
- org.apache.felix.framework.util.WeakZipFileFactory.WeakZipFile
-
- Enclosing class:
- WeakZipFileFactory
public class WeakZipFileFactory.WeakZipFile extends java.lang.ObjectThis class wraps a ZipFile to making it possible to weakly close it; this means the underlying zip file will be automatically reopened on demand if anyone tries to use it.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classWeakZipFileFactory.WeakZipFile.WeakZipInputStreamThis is an InputStream wrapper that will properly reopen the underlying zip file if it is weakly closed and create the underlying input stream.
-
Field Summary
Fields Modifier and Type Field Description private java.io.Filem_fileprivate Mutexm_localMutexprivate intm_statusprivate longm_timestampprivate java.util.zip.ZipFilem_zipFile
-
Constructor Summary
Constructors Modifier Constructor Description privateWeakZipFile(java.io.File file)Constructor is private since instances need to be centrally managed.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void__close()This internal method is used to clear the zip file from the data structures and reset its state.private void__reopenZipFile()Thie internal method is used to reopen a weakly closed zip file.private void_closeWeakly()This method is used internally to weakly close a zip file.voidclose()This method permanently closes the zip file.(package private) voidcloseWeakly()Weakly closes the zip file, which means that it will be reopened if anyone tries to use it again.private voidensureZipFileIsOpen()This method ensures that the zip file associated with this weak zip file instance is actually open and acquires the local weak zip file mutex.java.util.Enumeration<java.util.zip.ZipEntry>entries()Returns an enumeration of zip entries from the zip file.java.util.zip.ZipEntrygetEntry(java.lang.String name)Returns the specified entry from the zip file.java.io.InputStreamgetInputStream(java.util.zip.ZipEntry ze)Returns an input stream for the specified zip entry.
-
-
-
Field Detail
-
m_file
private final java.io.File m_file
-
m_localMutex
private final Mutex m_localMutex
-
m_zipFile
private java.util.zip.ZipFile m_zipFile
-
m_status
private int m_status
-
m_timestamp
private long m_timestamp
-
-
Method Detail
-
getEntry
public java.util.zip.ZipEntry getEntry(java.lang.String name)
Returns the specified entry from the zip file.- Parameters:
name- the name of the entry to return.- Returns:
- the zip entry associated with the specified name or null if it does not exist.
-
entries
public java.util.Enumeration<java.util.zip.ZipEntry> entries()
Returns an enumeration of zip entries from the zip file.- Returns:
- an enumeration of zip entries.
-
getInputStream
public java.io.InputStream getInputStream(java.util.zip.ZipEntry ze) throws java.io.IOExceptionReturns an input stream for the specified zip entry.- Parameters:
ze- the zip entry whose input stream is to be retrieved.- Returns:
- an input stream to the zip entry.
- Throws:
java.io.IOException- if the input stream cannot be opened.
-
closeWeakly
void closeWeakly()
Weakly closes the zip file, which means that it will be reopened if anyone tries to use it again.
-
_closeWeakly
private void _closeWeakly()
This method is used internally to weakly close a zip file. It should only be called when already holding the global lock, otherwise use closeWeakly().
-
close
public void close() throws java.io.IOExceptionThis method permanently closes the zip file.- Throws:
java.io.IOException- if any error occurs while trying to close the zip file.
-
__close
private void __close()
This internal method is used to clear the zip file from the data structures and reset its state. It should only be called when holding the global and local mutexes.
-
ensureZipFileIsOpen
private void ensureZipFileIsOpen()
This method ensures that the zip file associated with this weak zip file instance is actually open and acquires the local weak zip file mutex. If the underlying zip file is closed, then the local mutex is released and an IllegalStateException is thrown. If the zip file is weakly closed, then it is reopened. If the zip file is already opened, then no additional action is necessary. If this method does not throw an exception, then the end result is the zip file member field is non-null and the local mutex has been acquired.
-
__reopenZipFile
private void __reopenZipFile() throws java.io.IOExceptionThie internal method is used to reopen a weakly closed zip file. It makes a best effort, but may fail and leave the zip file member field null. Any failure reopening a zip file results in it being permanently closed. This method should only be invoked when holding the global and local mutexes.- Throws:
java.io.IOException
-
-