Package org.apache.felix.framework.util
Class WeakZipFileFactory.WeakZipFile
java.lang.Object
org.apache.felix.framework.util.WeakZipFileFactory.WeakZipFile
- Enclosing class:
WeakZipFileFactory
This 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 ClassesModifier and TypeClassDescription(package private) class
This 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 -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
WeakZipFile
(File file) Constructor is private since instances need to be centrally managed. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
__close()
This internal method is used to clear the zip file from the data structures and reset its state.private void
Thie internal method is used to reopen a weakly closed zip file.private void
This method is used internally to weakly close a zip file.void
close()
This method permanently closes the zip file.(package private) void
Weakly closes the zip file, which means that it will be reopened if anyone tries to use it again.private void
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.entries()
Returns an enumeration of zip entries from the zip file.Returns the specified entry from the zip file.Returns an input stream for the specified zip entry.
-
Field Details
-
m_file
-
m_localMutex
-
m_zipFile
-
m_status
private int m_status -
m_timestamp
private long m_timestamp
-
-
Constructor Details
-
WeakZipFile
Constructor is private since instances need to be centrally managed.- Parameters:
file
- the target zip file.- Throws:
IOException
- if the zip file could not be opened.
-
-
Method Details
-
getEntry
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
Returns an enumeration of zip entries from the zip file.- Returns:
- an enumeration of zip entries.
-
getInputStream
Returns 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:
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
This method permanently closes the zip file.- Throws:
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
Thie 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:
IOException
-