Class AsiExtraField

All Implemented Interfaces:
Cloneable, UnixStat, ZipExtraField

public class AsiExtraField extends Object implements ZipExtraField, UnixStat, Cloneable
Adds UNIX file permission and UID/GID fields as well as symbolic link handling.

This class uses the ASi extra field in the format:

         Value         Size            Description
         -----         ----            -----------
 (Unix3) 0x756e        Short           tag for this extra block type
         TSize         Short           total data size for this block
         CRC           Long            CRC-32 of the remaining data
         Mode          Short           file permissions
         SizDev        Long            symlink'd size OR major/minor dev num
         UID           Short           user ID
         GID           Short           group ID
         (var.)        variable        symbolic link file name

taken from appnote.iz (Info-ZIP note, 981119) found at

Short is two bytes and Long is four bytes in big-endian byte and word order, device numbers are currently not supported.

This class is not thread-safe

Since the documentation this class is based upon doesn't mention the character encoding of the file name at all, it is assumed that it uses the current platform's default encoding.

  • Constructor Details

    • AsiExtraField

      public AsiExtraField()
      Constructor for AsiExtraField.
  • Method Details

    • clone

      public Object clone()
      clone in class Object
    • getCentralDirectoryData

      public byte[] getCentralDirectoryData()
      Delegate to local file data.
      Specified by:
      getCentralDirectoryData in interface ZipExtraField
      the local file data
    • getCentralDirectoryLength

      Delegate to local file data.
      Specified by:
      getCentralDirectoryLength in interface ZipExtraField
      the centralDirectory length
    • getGroupId

      public int getGroupId()
      Gets the group id.
      the group id
    • getHeaderId

      The Header-ID.
      Specified by:
      getHeaderId in interface ZipExtraField
      the value for the header id for this extrafield
    • getLinkedFile

      Name of linked file
      name of the file this entry links to if it is a symbolic link, the empty string otherwise.
    • getLocalFileDataData

      public byte[] getLocalFileDataData()
      The actual data to put into local file data - without Header-ID or length specifier.
      Specified by:
      getLocalFileDataData in interface ZipExtraField
      get the data
    • getLocalFileDataLength

      Length of the extra field in the local file data - without Header-ID or length specifier.
      Specified by:
      getLocalFileDataLength in interface ZipExtraField
      a ZipShort for the length of the data of this extra field
    • getMode

      public int getMode()
      File mode of this file.
      the file mode
    • getMode

      protected int getMode(int mode)
      Gets the file mode for given permissions with the correct file type.
      mode - the mode
      the type with the mode
    • getUserId

      public int getUserId()
      Gets the user id.
      the user id
    • isDirectory

      public boolean isDirectory()
      Is this entry a directory?
      true if this entry is a directory
    • isLink

      public boolean isLink()
      Is this entry a symbolic link?
      true if this is a symbolic link
    • parseFromCentralDirectoryData

      public void parseFromCentralDirectoryData(byte[] buffer, int offset, int length) throws ZipException
      Doesn't do anything special since this class always uses the same data in central directory and local file data.
      Specified by:
      parseFromCentralDirectoryData in interface ZipExtraField
      buffer - the buffer to read data from
      offset - offset into buffer to read data
      length - the length of data
      ZipException - on error
    • parseFromLocalFileData

      public void parseFromLocalFileData(byte[] data, int offset, int length) throws ZipException
      Populate data from this array as if it was in local file data.
      Specified by:
      parseFromLocalFileData in interface ZipExtraField
      data - an array of bytes
      offset - the start offset
      length - the number of bytes in the array from offset
      ZipException - on error
    • setDirectory

      public void setDirectory(boolean dirFlag)
      Indicate whether this entry is a directory.
      dirFlag - if true, this entry is a directory
    • setGroupId

      public void setGroupId(int gid)
      Sets the group id.
      gid - the group id
    • setLinkedFile

      public void setLinkedFile(String name)
      Indicate that this entry is a symbolic link to the given file name.
      name - Name of the file this entry links to, empty String if it is not a symbolic link.
    • setMode

      public void setMode(int mode)
      File mode of this file.
      mode - the file mode
    • setUserId

      public void setUserId(int uid)
      Sets the user id.
      uid - the user id