Class X7875_NewUnix

java.lang.Object
org.apache.commons.compress.archivers.zip.X7875_NewUnix
All Implemented Interfaces:
Serializable, Cloneable, ZipExtraField

public class X7875_NewUnix extends Object implements ZipExtraField, Cloneable, Serializable
An extra field that stores UNIX UID/GID data (owner & group ownership) for a given zip entry. We're using the field definition given in Info-Zip's source archive: zip-3.0.tar.gz/proginfo/extrafld.txt
 Local-header version:

 Value         Size        Description
 -----         ----        -----------
 0x7875        Short       tag for this extra block type ("ux")
 TSize         Short       total data size for this block
 Version       1 byte      version of this extra field, currently 1
 UIDSize       1 byte      Size of UID field
 UID           Variable    UID for this entry (little endian)
 GIDSize       1 byte      Size of GID field
 GID           Variable    GID for this entry (little endian)

 Central-header version:

 Value         Size        Description
 -----         ----        -----------
 0x7855        Short       tag for this extra block type ("Ux")
 TSize         Short       total data size for this block (0)
 
Since:
1.5
See Also:
  • Field Details

    • HEADER_ID

      private static final ZipShort HEADER_ID
    • ZERO

      private static final ZipShort ZERO
    • ONE_THOUSAND

      private static final BigInteger ONE_THOUSAND
    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • version

      private int version
    • uid

      private BigInteger uid
    • gid

      private BigInteger gid
  • Constructor Details

    • X7875_NewUnix

      public X7875_NewUnix()
      Constructor for X7875_NewUnix.
  • Method Details

    • getHeaderId

      public ZipShort getHeaderId()
      The Header-ID.
      Specified by:
      getHeaderId in interface ZipExtraField
      Returns:
      the value for the header id for this extrafield
    • getUID

      public long getUID()
      Gets the UID as a long. UID is typically a 32 bit unsigned value on most UNIX systems, so we return a long to avoid integer overflow into the negatives in case values above and including 2^31 are being used.
      Returns:
      the UID value.
    • getGID

      public long getGID()
      Gets the GID as a long. GID is typically a 32 bit unsigned value on most UNIX systems, so we return a long to avoid integer overflow into the negatives in case values above and including 2^31 are being used.
      Returns:
      the GID value.
    • setUID

      public void setUID(long l)
      Sets the UID.
      Parameters:
      l - UID value to set on this extra field.
    • setGID

      public void setGID(long l)
      Sets the GID.
      Parameters:
      l - GID value to set on this extra field.
    • getLocalFileDataLength

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

      public ZipShort getCentralDirectoryLength()
      Length of the extra field in the central directory data - without Header-ID or length specifier.
      Specified by:
      getCentralDirectoryLength in interface ZipExtraField
      Returns:
      a ZipShort for the length of the data of this extra field
    • 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
      Returns:
      get the data
    • getCentralDirectoryData

      public byte[] getCentralDirectoryData()
      The actual data to put into central directory data - without Header-ID or length specifier.
      Specified by:
      getCentralDirectoryData in interface ZipExtraField
      Returns:
      get the data
    • 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
      Parameters:
      data - an array of bytes
      offset - the start offset
      length - the number of bytes in the array from offset
      Throws:
      ZipException - on error
    • parseFromCentralDirectoryData

      public void parseFromCentralDirectoryData(byte[] buffer, int offset, int length) throws ZipException
      Doesn't do anything since this class doesn't store anything inside the central directory.
      Specified by:
      parseFromCentralDirectoryData in interface ZipExtraField
      Parameters:
      buffer - the buffer to read data from
      offset - offset into buffer to read data
      length - the length of data
      Throws:
      ZipException - on error
    • reset

      private void reset()
      Reset state back to newly constructed state. Helps us make sure parse() calls always generate clean results.
    • toString

      public String toString()
      Returns a String representation of this class useful for debugging purposes.
      Overrides:
      toString in class Object
      Returns:
      A String representation of this class useful for debugging purposes.
    • clone

      public Object clone() throws CloneNotSupportedException
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • trimLeadingZeroesForceMinLength

      static byte[] trimLeadingZeroesForceMinLength(byte[] array)
      Not really for external usage, but marked "package" visibility to help us JUnit it. Trims a byte array of leading zeroes while also enforcing a minimum length, and thus it really trims AND pads at the same time.
      Parameters:
      array - byte[] array to trim & pad.
      Returns:
      trimmed & padded byte[] array.