public class X5455_ExtendedTimestamp extends java.lang.Object implements ZipExtraField, java.lang.Cloneable, java.io.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 signed 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 (signed) bits can only store dates up to the year 2037, and so this extra field will eventually be obsolete. Enjoy it while it lasts!
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)
Modifier and Type | Field and Description |
---|---|
static byte |
ACCESS_TIME_BIT
The bit set inside the flags by when the lasr access time is
present in this extra field.
|
static byte |
CREATE_TIME_BIT
The bit set inside the flags by when the original creation time
is present in this extra field.
|
static byte |
MODIFY_TIME_BIT
The bit set inside the flags by when the last modification time
is present in this extra field.
|
EXTRAFIELD_HEADER_SIZE
Constructor and Description |
---|
X5455_ExtendedTimestamp()
Constructor for X5455_ExtendedTimestamp.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone() |
boolean |
equals(java.lang.Object o) |
java.util.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.
|
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.
|
byte[] |
getCentralDirectoryData()
The actual data to put into central directory data - without Header-ID
or length specifier.
|
ZipShort |
getCentralDirectoryLength()
Length of the extra field in the local file data - without
Header-ID or length specifier.
|
java.util.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.
|
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.
|
byte |
getFlags()
Gets flags byte.
|
ZipShort |
getHeaderId()
The Header-ID.
|
byte[] |
getLocalFileDataData()
The actual data to put into local file data - without Header-ID
or length specifier.
|
ZipShort |
getLocalFileDataLength()
Length of the extra field in the local file data - without
Header-ID or length specifier.
|
java.util.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.
|
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.
|
int |
hashCode() |
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.
|
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.
|
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.
|
void |
parseFromCentralDirectoryData(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.
|
void |
parseFromLocalFileData(byte[] data,
int offset,
int length)
Populate data from this array as if it was in local file data.
|
void |
setAccessJavaTime(java.util.Date d)
Sets the access time as a java.util.Date
of this zip entry.
|
void |
setAccessTime(ZipLong l)
Sets the access time (seconds since epoch) of this zip entry
using a ZipLong object
|
void |
setCreateJavaTime(java.util.Date d)
Sets the create time as a java.util.Date
of this zip entry.
|
void |
setCreateTime(ZipLong l)
Sets the create time (seconds since epoch) of this zip entry
using a ZipLong object
|
void |
setFlags(byte flags)
Sets flags byte.
|
void |
setModifyJavaTime(java.util.Date d)
Sets the modify time as a java.util.Date
of this zip entry.
|
void |
setModifyTime(ZipLong l)
Sets the modify time (seconds since epoch) of this zip entry
using a ZipLong object.
|
java.lang.String |
toString()
Returns a String representation of this class useful for
debugging purposes.
|
public static final byte MODIFY_TIME_BIT
public static final byte ACCESS_TIME_BIT
public static final byte CREATE_TIME_BIT
public X5455_ExtendedTimestamp()
public ZipShort getHeaderId()
getHeaderId
in interface ZipExtraField
public ZipShort getLocalFileDataLength()
getLocalFileDataLength
in interface ZipExtraField
ZipShort
for the length of the data of this extra fieldpublic ZipShort getCentralDirectoryLength()
For X5455 the central length is often smaller than the local length, because central cannot contain access or create timestamps.
getCentralDirectoryLength
in interface ZipExtraField
ZipShort
for the length of the data of this extra fieldpublic byte[] getLocalFileDataData()
getLocalFileDataData
in interface ZipExtraField
public byte[] getCentralDirectoryData()
getCentralDirectoryData
in interface ZipExtraField
public void parseFromLocalFileData(byte[] data, int offset, int length) throws java.util.zip.ZipException
parseFromLocalFileData
in interface ZipExtraField
data
- an array of bytesoffset
- the start offsetlength
- the number of bytes in the array from offsetjava.util.zip.ZipException
- on errorpublic void parseFromCentralDirectoryData(byte[] buffer, int offset, int length) throws java.util.zip.ZipException
parseFromCentralDirectoryData
in interface ZipExtraField
buffer
- the buffer to read data fromoffset
- offset into buffer to read datalength
- the length of datajava.util.zip.ZipException
- on errorpublic void setFlags(byte flags)
bit0 - modify time bit1 - access time bit2 - create timeOnly first 3 bits of flags are used according to the latest version of the spec (December 2012).
flags
- flags byte indicating which of the
three datestamp fields are present.public byte getFlags()
bit0 - modify time bit1 - access time bit2 - create timeOnly first 3 bits of flags are used according to the latest version of the spec (December 2012).
public boolean isBit0_modifyTimePresent()
public boolean isBit1_accessTimePresent()
public boolean isBit2_createTimePresent()
public ZipLong getModifyTime()
public ZipLong getAccessTime()
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.
public java.util.Date getModifyJavaTime()
public java.util.Date getAccessJavaTime()
public java.util.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.
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.
l
- ZipLong of the modify time (seconds per epoch)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.
l
- ZipLong of the access time (seconds per epoch)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.
l
- ZipLong of the create time (seconds per epoch)public void setModifyJavaTime(java.util.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.
d
- modify time as java.util.Datepublic void setAccessJavaTime(java.util.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.
d
- access time as java.util.Datepublic void setCreateJavaTime(java.util.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.
d
- create time as java.util.Datepublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"