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.
  • Field Details

    • m_file

      private final File m_file
    • m_localMutex

      private final Lock m_localMutex
    • m_zipFile

      private volatile ZipFile m_zipFile
    • m_status

      private volatile int m_status
    • m_timestamp

      private volatile long m_timestamp
    • m_entries

      private volatile SoftReference<LinkedHashMap<String,ZipEntry>> m_entries
  • 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.
    • names

      public Enumeration<String> names()
    • getEntries

      private LinkedHashMap<String,ZipEntry> getEntries(boolean create)
    • 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