org.apache.commons.compress.archivers.zip

Class X5455_ExtendedTimestamp

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


    public class X5455_ExtendedTimestampextends Objectimplements ZipExtraField, Cloneable, Serializable

    An extra field that stores additional file and directory timestamp data for zip entries. Each zip entry can include up to three timestamps (modify, access, create*). The timestamps are stored as 32 bit unsigned integers representing seconds since UNIX epoch (Jan 1st, 1970, UTC). This field improves on zip's default timestamp granularity, since it allows one to store additional timestamps, and, in addition, the timestamps are stored using per-second granularity (zip's default behaviour can only store timestamps to the nearest even second).

    Unfortunately, 32 (unsigned) bits can only store dates up to the year 2106, and so this extra field will eventually be obsolete. Enjoy it while it lasts!

    • modifyTime: most recent time of file/directory modification (or file/dir creation if the entry has not been modified since it was created).
    • accessTime: most recent time file/directory was opened (e.g., read from disk). Many people disable their operating systems from updating this value using the NOATIME mount option to optimize disk behaviour, and thus it's not always reliable. In those cases it's always equal to modifyTime.
    • *createTime: modern linux file systems (e.g., ext2 and newer) do not appear to store a value like this, and so it's usually omitted altogether in the zip extra field. Perhaps other unix systems track this.

    We're using the field definition given in Info-Zip's source archive: zip-3.0.tar.gz/proginfo/extrafld.txt

     Value         Size        Description -----         ----        ----------- 0x5455        Short       tag for this extra block type ("UT") TSize         Short       total data size for this block Flags         Byte        info bits (ModTime)     Long        time of last modification (UTC/GMT) (AcTime)      Long        time of last access (UTC/GMT) (CrTime)      Long        time of original creation (UTC/GMT) Central-header version: Value         Size        Description -----         ----        ----------- 0x5455        Short       tag for this extra block type ("UT") TSize         Short       total data size for this block Flags         Byte        info bits (refers to local header!) (ModTime)     Long        time of last modification (UTC/GMT) 
    Since:
    1.5
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and TypeField and Description
      static byteACCESS_TIME_BIT
      The bit set inside the flags by when the lasr access time is present in this extra field.
      static byteCREATE_TIME_BIT
      The bit set inside the flags by when the original creation time is present in this extra field.
      static byteMODIFY_TIME_BIT
      The bit set inside the flags by when the last modification time is present in this extra field.
    • Constructor Summary

      Constructors 
      Constructor and Description
      X5455_ExtendedTimestamp()
      Constructor for X5455_ExtendedTimestamp.
    • Method Summary

      Methods 
      Modifier and TypeMethod and Description
      Objectclone() 
      booleanequals(Object o) 
      DategetAccessJavaTime()
      Returns the access time as a java.util.Date of this zip entry, or null if no such timestamp exists in the zip entry.
      ZipLonggetAccessTime()
      Returns the access time (seconds since epoch) of this zip entry as a ZipLong object, or null if no such timestamp exists in the zip entry.
      byte[]getCentralDirectoryData()
      The actual data to put into central directory data - without Header-ID or length specifier.
      ZipShortgetCentralDirectoryLength()
      Length of the extra field in the local file data - without Header-ID or length specifier.
      DategetCreateJavaTime()
      Returns the create time as a a java.util.Date of this zip entry, or null if no such timestamp exists in the zip entry.
      ZipLonggetCreateTime()
      Returns the create time (seconds since epoch) of this zip entry as a ZipLong object, or null if no such timestamp exists in the zip entry.
      bytegetFlags()
      Gets flags byte.
      ZipShortgetHeaderId()
      The Header-ID.
      byte[]getLocalFileDataData()
      The actual data to put into local file data - without Header-ID or length specifier.
      ZipShortgetLocalFileDataLength()
      Length of the extra field in the local file data - without Header-ID or length specifier.
      DategetModifyJavaTime()
      Returns the modify time as a java.util.Date of this zip entry, or null if no such timestamp exists in the zip entry.
      ZipLonggetModifyTime()
      Returns the modify time (seconds since epoch) of this zip entry as a ZipLong object, or null if no such timestamp exists in the zip entry.
      inthashCode() 
      booleanisBit0_modifyTimePresent()
      Returns whether bit0 of the flags byte is set or not, which should correspond to the presence or absence of a modify timestamp in this particular zip entry.
      booleanisBit1_accessTimePresent()
      Returns whether bit1 of the flags byte is set or not, which should correspond to the presence or absence of a "last access" timestamp in this particular zip entry.
      booleanisBit2_createTimePresent()
      Returns whether bit2 of the flags byte is set or not, which should correspond to the presence or absence of a create timestamp in this particular zip entry.
      voidparseFromCentralDirectoryData(byte[] buffer, int offset, int length)
      Doesn't do anything special since this class always uses the same parsing logic for both central directory and local file data.
      voidparseFromLocalFileData(byte[] data, int offset, int length)
      Populate data from this array as if it was in local file data.
      voidsetAccessJavaTime(Date d)
      Sets the access time as a java.util.Date of this zip entry.
      voidsetAccessTime(ZipLong l)
      Sets the access time (seconds since epoch) of this zip entry using a ZipLong object Note: the setters for flags and timestamps are decoupled.
      voidsetCreateJavaTime(Date d)
      Sets the create time as a java.util.Date of this zip entry.
      voidsetCreateTime(ZipLong l)
      Sets the create time (seconds since epoch) of this zip entry using a ZipLong object Note: the setters for flags and timestamps are decoupled.
      voidsetFlags(byte flags)
      Sets flags byte.
      voidsetModifyJavaTime(Date d)
      Sets the modify time as a java.util.Date of this zip entry.
      voidsetModifyTime(ZipLong l)
      Sets the modify time (seconds since epoch) of this zip entry using a ZipLong object.
      StringtoString()
      Returns a String representation of this class useful for debugging purposes.
    • Field Detail

      • MODIFY_TIME_BIT

        public static final byte MODIFY_TIME_BIT
        The bit set inside the flags by when the last modification time is present in this extra field.
        See Also:
        Constant Field Values
      • CREATE_TIME_BIT

        public static final byte CREATE_TIME_BIT
        The bit set inside the flags by when the original creation time is present in this extra field.
        See Also:
        Constant Field Values
    • Method Detail

      • getCentralDirectoryLength

        public ZipShort getCentralDirectoryLength()
        Length of the extra field in the local file data - without Header-ID or length specifier.

        For X5455 the central length is often smaller than the local length, because central cannot contain access or create timestamps.

        Specified by:
        getCentralDirectoryLength in interface ZipExtraField
        Returns:
        a ZipShort for the length of the data of this extra field
      • parseFromCentralDirectoryData

        public void parseFromCentralDirectoryData(byte[] buffer,                                 int offset,                                 int length)                                   throws ZipException
        Doesn't do anything special since this class always uses the same parsing logic for both central directory and local file data.
        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
      • setFlags

        public void setFlags(byte flags)
        Sets flags byte. The flags byte tells us which of the three datestamp fields are present in the data:
         bit0 - modify time bit1 - access time bit2 - create time 
        Only first 3 bits of flags are used according to the latest version of the spec (December 2012).
        Parameters:
        flags - flags byte indicating which of the three datestamp fields are present.
      • getFlags

        public byte getFlags()
        Gets flags byte. The flags byte tells us which of the three datestamp fields are present in the data:
         bit0 - modify time bit1 - access time bit2 - create time 
        Only first 3 bits of flags are used according to the latest version of the spec (December 2012).
        Returns:
        flags byte indicating which of the three datestamp fields are present.
      • isBit0_modifyTimePresent

        public boolean isBit0_modifyTimePresent()
        Returns whether bit0 of the flags byte is set or not, which should correspond to the presence or absence of a modify timestamp in this particular zip entry.
        Returns:
        true if bit0 of the flags byte is set.
      • isBit1_accessTimePresent

        public boolean isBit1_accessTimePresent()
        Returns whether bit1 of the flags byte is set or not, which should correspond to the presence or absence of a "last access" timestamp in this particular zip entry.
        Returns:
        true if bit1 of the flags byte is set.
      • isBit2_createTimePresent

        public boolean isBit2_createTimePresent()
        Returns whether bit2 of the flags byte is set or not, which should correspond to the presence or absence of a create timestamp in this particular zip entry.
        Returns:
        true if bit2 of the flags byte is set.
      • getModifyTime

        public ZipLong getModifyTime()
        Returns the modify time (seconds since epoch) of this zip entry as a ZipLong object, or null if no such timestamp exists in the zip entry.
        Returns:
        modify time (seconds since epoch) or null.
      • getAccessTime

        public ZipLong getAccessTime()
        Returns the access time (seconds since epoch) of this zip entry as a ZipLong object, or null if no such timestamp exists in the zip entry.
        Returns:
        access time (seconds since epoch) or null.
      • getCreateTime

        public ZipLong getCreateTime()

        Returns the create time (seconds since epoch) of this zip entry as a ZipLong object, or null if no such timestamp exists in the zip entry.

        Note: modern linux file systems (e.g., ext2) do not appear to store a "create time" value, and so it's usually omitted altogether in the zip extra field. Perhaps other unix systems track this.

        Returns:
        create time (seconds since epoch) or null.
      • getModifyJavaTime

        public Date getModifyJavaTime()
        Returns the modify time as a java.util.Date of this zip entry, or null if no such timestamp exists in the zip entry. The milliseconds are always zeroed out, since the underlying data offers only per-second precision.
        Returns:
        modify time as java.util.Date or null.
      • getAccessJavaTime

        public Date getAccessJavaTime()
        Returns the access time as a java.util.Date of this zip entry, or null if no such timestamp exists in the zip entry. The milliseconds are always zeroed out, since the underlying data offers only per-second precision.
        Returns:
        access time as java.util.Date or null.
      • getCreateJavaTime

        public Date getCreateJavaTime()

        Returns the create time as a a java.util.Date of this zip entry, or null if no such timestamp exists in the zip entry. The milliseconds are always zeroed out, since the underlying data offers only per-second precision.

        Note: modern linux file systems (e.g., ext2) do not appear to store a "create time" value, and so it's usually omitted altogether in the zip extra field. Perhaps other unix systems track this.

        Returns:
        create time as java.util.Date or null.
      • setModifyTime

        public void setModifyTime(ZipLong l)

        Sets the modify time (seconds since epoch) of this zip entry using a ZipLong object.

        Note: the setters for flags and timestamps are decoupled. Even if the timestamp is not-null, it will only be written out if the corresponding bit in the flags is also set.

        Parameters:
        l - ZipLong of the modify time (seconds per epoch)
      • setAccessTime

        public void setAccessTime(ZipLong l)

        Sets the access time (seconds since epoch) of this zip entry using a ZipLong object

        Note: the setters for flags and timestamps are decoupled. Even if the timestamp is not-null, it will only be written out if the corresponding bit in the flags is also set.

        Parameters:
        l - ZipLong of the access time (seconds per epoch)
      • setCreateTime

        public void setCreateTime(ZipLong l)

        Sets the create time (seconds since epoch) of this zip entry using a ZipLong object

        Note: the setters for flags and timestamps are decoupled. Even if the timestamp is not-null, it will only be written out if the corresponding bit in the flags is also set.

        Parameters:
        l - ZipLong of the create time (seconds per epoch)
      • setModifyJavaTime

        public void setModifyJavaTime(Date d)

        Sets the modify time as a java.util.Date of this zip entry. Supplied value is truncated to per-second precision (milliseconds zeroed-out).

        Note: the setters for flags and timestamps are decoupled. Even if the timestamp is not-null, it will only be written out if the corresponding bit in the flags is also set.

        Parameters:
        d - modify time as java.util.Date
      • setAccessJavaTime

        public void setAccessJavaTime(Date d)

        Sets the access time as a java.util.Date of this zip entry. Supplied value is truncated to per-second precision (milliseconds zeroed-out).

        Note: the setters for flags and timestamps are decoupled. Even if the timestamp is not-null, it will only be written out if the corresponding bit in the flags is also set.

        Parameters:
        d - access time as java.util.Date
      • setCreateJavaTime

        public void setCreateJavaTime(Date d)

        Sets the create time as a java.util.Date of this zip entry. Supplied value is truncated to per-second precision (milliseconds zeroed-out).

        Note: the setters for flags and timestamps are decoupled. Even if the timestamp is not-null, it will only be written out if the corresponding bit in the flags is also set.

        Parameters:
        d - create time as java.util.Date
      • 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.

Copyright © 2016 The Apache Software Foundation. All rights reserved.



NOTHING
NOTHING
Add the Maven Dependecy to your project: maven dependecy for com.amazonaws : aws-java-sdk : 1.3.14