Class ZFileExtension
- java.lang.Object
-
- com.android.tools.build.apkzlib.zip.ZFileExtension
-
public abstract class ZFileExtension extends java.lang.ObjectAn extension of aZFile. 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
beforeUpdatenotification. - E1 adds file F1 to the zip (notifying the addition is suspended because another notification is in progress).
- E2 receives
beforeUpdatenotification. - 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
IOExceptionRunnablethat is invoked whenZFilehas finished notifying all extensions. - E1 receives
-
-
Constructor Summary
Constructors Constructor Description ZFileExtension()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description IOExceptionRunnableadded(StoredEntry entry, StoredEntry replaced)A new entry has been added to the zip, possibly replacing an entry in there.IOExceptionRunnablebeforeUpdate()The zip will be updated.voidclosed()The zip file has been closed.voidentriesWritten()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.IOExceptionRunnableopen()The zip file has been open and the zip's contents have been read.IOExceptionRunnableremoved(StoredEntry entry)An entry has been removed from the zip.voidupdated()The zip file has been updated on disk.
-
-
-
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 returnsnull.- 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 returnsnull.After this notification is received, the extension will receive further
added(StoredEntry, StoredEntry)andremoved(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.IOExceptionThis 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.IOExceptionThe 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 ifZFile.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 returnsnull.- Parameters:
entry- the entry that was addedreplaced- 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 inadded(StoredEntry, StoredEntry). The default implementation does nothing and returnsnull.- Parameters:
entry- the entry that was deleted- Returns:
- an optional runnable to run when notification of all listeners has ended
-
-