Class StoredEntry
- java.lang.Object
-
- com.android.tools.build.apkzlib.zip.StoredEntry
-
public class StoredEntry extends java.lang.ObjectA stored entry represents a file in the zip. The entry may or may not be written to the zip file.Stored entries provide the operations that are related to the files themselves, not to the zip. It is through the
StoredEntryclass that entries can be deleted (delete(), open (open()) or realigned (realign()).Entries are not created directly. They are created using
ZFile.add(String, InputStream, boolean)and obtained from the zip file usingZFile.get(String)orZFile.entries().Most of the data in the an entry is in the Central Directory Header. This includes the name, compression method, file compressed and uncompressed sizes, CRC32 checksum, etc. The CDH can be obtained using the
getCentralDirectoryHeader()method.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddelete()Deletes this entry from the zip file.CentralDirectoryHeadergetCentralDirectoryHeader()Obtains the CDH associated with this entry.DataDescriptorTypegetDataDescriptorType()Obtains the type of data descriptor used in the entry.ExtraFieldgetLocalExtra()Obtains the contents of the local extra field.intgetLocalHeaderSize()Obtains the size of the local header of this entry.StoredEntryTypegetType()Obtains the type of entry.VerifyLoggetVerifyLog()Obtains the verify log for the entry.booleanisDeleted()Returnstrueif this entry has been deleted/replaced.java.io.InputStreamopen()Obtains a stream that allows reading from the entry.byte[]read()Obtains the contents of the file.intread(byte[] bytes)Obtains the contents of the file in an existing buffer.booleanrealign()Requests that this entry be realigned.voidsetLocalExtra(ExtraField localExtra)Sets the contents of the local extra field.
-
-
-
Method Detail
-
getLocalHeaderSize
public int getLocalHeaderSize()
Obtains the size of the local header of this entry.- Returns:
- the local header size in bytes
-
open
public java.io.InputStream open() throws java.io.IOExceptionObtains a stream that allows reading from the entry.- Returns:
- a stream that will return as many bytes as the uncompressed entry size
- Throws:
java.io.IOException- failed to open the stream
-
read
public byte[] read() throws java.io.IOExceptionObtains the contents of the file.- Returns:
- a byte array with the contents of the file (uncompressed if the file was compressed)
- Throws:
java.io.IOException- failed to read the file
-
read
public int read(byte[] bytes) throws java.io.IOExceptionObtains the contents of the file in an existing buffer.- Parameters:
bytes- buffer to read the file contents in.- Returns:
- the number of bytes read
- Throws:
java.io.IOException- failed to read the file.
-
getType
public StoredEntryType getType()
Obtains the type of entry.- Returns:
- the type of entry
-
delete
public void delete() throws java.io.IOExceptionDeletes this entry from the zip file. Invoking this method doesn't update the zip itself. To eventually write updates to disk,ZFile.update()must be called.- Throws:
java.io.IOException- failed to delete the entryjava.lang.IllegalStateException- if the zip file was open in read-only mode
-
isDeleted
public boolean isDeleted()
Returnstrueif this entry has been deleted/replaced.
-
getCentralDirectoryHeader
public CentralDirectoryHeader getCentralDirectoryHeader()
Obtains the CDH associated with this entry.- Returns:
- the CDH
-
getDataDescriptorType
public DataDescriptorType getDataDescriptorType()
Obtains the type of data descriptor used in the entry.- Returns:
- the type of data descriptor
-
realign
public boolean realign() throws java.io.IOExceptionRequests that this entry be realigned. If this entry is already aligned according to the rules inZFilethen this method does nothing. Otherwise it will move the file's data into memory and place it in a different area of the zip.- Returns:
- has this file been changed? Note that if the entry has not yet been written on the file, realignment does not count as a change as nothing needs to be updated in the file; also, if the entry has been changed, this object may have been marked as deleted and a new stored entry may need to be fetched from the file
- Throws:
java.io.IOException- failed to realign the entry; the entry may no longer exist in the zip file
-
getLocalExtra
public ExtraField getLocalExtra()
Obtains the contents of the local extra field.- Returns:
- the contents of the local extra field
-
setLocalExtra
public void setLocalExtra(ExtraField localExtra) throws java.io.IOException
Sets the contents of the local extra field.- Parameters:
localExtra- the contents of the local extra field- Throws:
java.io.IOException- failed to update the zip file
-
getVerifyLog
public VerifyLog getVerifyLog()
Obtains the verify log for the entry.- Returns:
- the verify log
-
-