Class ZFileExtension


  • public abstract class ZFileExtension
    extends java.lang.Object
    An extension of a ZFile. Extensions are notified when files are open, updated, closed and when files are added or removed from the zip. These notifications are received after the zip has been updated in memory for open, when files are added or removed and when the zip has been updated on disk or closed.

    An extension is also notified before the file is updated, allowing it to modify the file before the update happens. If it does, then all extensions are notified of the changes on the zip file. Because the order of the notifications is preserved, all extensions are notified in the same order. For example, if two extensions E1 and E2 are registered and they both add a file at update time, this would be the flow:

    • E1 receives beforeUpdate notification.
    • E1 adds file F1 to the zip (notifying the addition is suspended because another notification is in progress).
    • E2 receives beforeUpdate notification.
    • E2 adds file F2 to the zip (notifying the addition is suspended because another notification is in progress).
    • E1 is notified F1 was added.
    • E2 is notified F1 was added.
    • E1 is notified F2 was added.
    • E2 is notified F2 was added.
    • (zip file is updated on disk)
    • E1 is notified the zip was updated.
    • E2 is notified the zip was updated.

    An extension should not modify the zip file when notified of changes. If allowed, this would break event notification order in case multiple extensions are registered with the zip file. To allow performing changes to the zip file, all notification method return a IOExceptionRunnable that is invoked when ZFile has finished notifying all extensions.

    • Constructor Detail

      • ZFileExtension

        public ZFileExtension()
    • Method Detail

      • open

        @Nullable
        public IOExceptionRunnable open()
                                 throws java.io.IOException
        The zip file has been open and the zip's contents have been read. The default implementation does nothing and returns null.
        Returns:
        an optional runnable to run when notification of all listeners has ended
        Throws:
        java.io.IOException - failed to process the event
      • beforeUpdate

        @Nullable
        public IOExceptionRunnable beforeUpdate()
                                         throws java.io.IOException
        The zip will be updated. This method allows the extension to register changes to the zip file before the file is written. The default implementation does nothing and returns null.

        After this notification is received, the extension will receive further added(StoredEntry, StoredEntry) and removed(StoredEntry) notifications if it or other extensions add or remove files before update.

        When no more files are updated, the entriesWritten() notification is sent.

        Returns:
        an optional runnable to run when notification of all listeners has ended
        Throws:
        java.io.IOException - failed to process the event
      • entriesWritten

        public void entriesWritten()
                            throws java.io.IOException
        This notification is sent when all entries have been written in the file but the central directory and the EOCD have not yet been written. No entries should be added, removed or updated during this notification. If this method forces an update of either the central directory or EOCD, then this method will be invoked again for all extensions with the new central directory and EOCD.

        After this notification, updated() is sent.

        Throws:
        java.io.IOException - failed to process the event
      • updated

        public void updated()
                     throws java.io.IOException
        The zip file has been updated on disk. The default implementation does nothing.
        Throws:
        java.io.IOException - failed to perform update tasks
      • closed

        public void closed()
        The zip file has been closed. Note that if ZFile.close() requires that the zip file be updated (because it had in-memory changes), updated() will be called before this method. The default implementation does nothing.
      • added

        @Nullable
        public IOExceptionRunnable added​(StoredEntry entry,
                                         @Nullable
                                         StoredEntry replaced)
        A new entry has been added to the zip, possibly replacing an entry in there. The default implementation does nothing and returns null.
        Parameters:
        entry - the entry that was added
        replaced - the entry that was replaced, if any
        Returns:
        an optional runnable to run when notification of all listeners has ended
      • removed

        @Nullable
        public IOExceptionRunnable removed​(StoredEntry entry)
        An entry has been removed from the zip. This method is not invoked for entries that have been replaced. Those entries are notified using replaced in added(StoredEntry, StoredEntry). The default implementation does nothing and returns null.
        Parameters:
        entry - the entry that was deleted
        Returns:
        an optional runnable to run when notification of all listeners has ended