Class WeakZipFileFactory.WeakZipFile

java.lang.Object
org.apache.felix.framework.util.WeakZipFileFactory.WeakZipFile
Enclosing class:
WeakZipFileFactory

public class WeakZipFileFactory.WeakZipFile extends Object
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 Classes
    Modifier and Type
    Class
    Description
    (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
    Modifier and Type
    Field
    Description
    private final File
     
    private final Mutex
     
    private int
     
    private long
     
    private ZipFile
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Constructor is private since instances need to be centrally managed.
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    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
    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.
    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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • m_file

      private final File m_file
    • m_localMutex

      private final Mutex m_localMutex
    • m_zipFile

      private ZipFile m_zipFile
    • m_status

      private int m_status
    • m_timestamp

      private long m_timestamp
  • Constructor Details

    • WeakZipFile

      private WeakZipFile(File file) throws IOException
      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

      public ZipEntry getEntry(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 Enumeration<ZipEntry> entries()
      Returns an enumeration of zip entries from the zip file.
      Returns:
      an enumeration of zip entries.
    • getInputStream

      public InputStream getInputStream(ZipEntry ze) throws IOException
      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

      public void close() throws IOException
      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

      private void __reopenZipFile() throws IOException
      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