Class StoredEntry


  • public class StoredEntry
    extends java.lang.Object
    A 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 StoredEntry class 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 using ZFile.get(String) or ZFile.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 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.IOException
        Obtains 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.IOException
        Obtains 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.IOException
        Obtains 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.IOException
        Deletes 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 entry
        java.lang.IllegalStateException - if the zip file was open in read-only mode
      • isDeleted

        public boolean isDeleted()
        Returns true if 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.IOException
        Requests that this entry be realigned. If this entry is already aligned according to the rules in ZFile then 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