TarEntries that are created from the header bytes read from an archive are instantiated with the TarArchiveEntry#TarArchiveEntry(byte[]) constructor.
These entries will be used when extracting from or listing the contents of an archive. These entries have their header filled in using the header bytes. They
also set the File to null, since they reference an archive entry not a file.
TarEntries that are created from Files that are to be written into an archive are instantiated with the TarArchiveEntry#TarArchiveEntry(File) or
TarArchiveEntry#TarArchiveEntry(Path) constructor. These entries have their header filled in using the File's information. They also keep a reference
to the File for convenience when writing entries.
Finally, TarEntries can be constructed from nothing but a name. This allows the programmer to construct the entry by hand, for instance when only an InputStream is available for writing to the archive, and the header information is constructed from other information. In this case the header fields are set to defaults and the File is set to null.
The C structure for a Tar Entry's header is:
struct header {
char name[100]; // TarConstants.NAMELEN - offset 0
char mode[8]; // TarConstants.MODELEN - offset 100
char uid[8]; // TarConstants.UIDLEN - offset 108
char gid[8]; // TarConstants.GIDLEN - offset 116
char size[12]; // TarConstants.SIZELEN - offset 124
char mtime[12]; // TarConstants.MODTIMELEN - offset 136
char chksum[8]; // TarConstants.CHKSUMLEN - offset 148
char linkflag[1]; // - offset 156
char linkname[100]; // TarConstants.NAMELEN - offset 157
// The following fields are only present in new-style POSIX tar archives:
char magic[6]; // TarConstants.MAGICLEN - offset 257
char version[2]; // TarConstants.VERSIONLEN - offset 263
char uname[32]; // TarConstants.UNAMELEN - offset 265
char gname[32]; // TarConstants.GNAMELEN - offset 297
char devmajor[8]; // TarConstants.DEVLEN - offset 329
char devminor[8]; // TarConstants.DEVLEN - offset 337
char prefix[155]; // TarConstants.PREFIXLEN - offset 345
// Used if "name" field is not long enough to hold the path
char pad[12]; // NULs - offset 500
} header;
All unused bytes are set to null. New-style GNU tar files are slightly different from the above. For values of size larger than 077777777777L (11 7s) or uid
and gid larger than 07777777L (7 7s) the sign bit of the first byte is set, and the rest of the field is the binary representation of the number. See
TarUtils#parseOctalOrBinary(byte[], int, int).
The C structure for a old GNU Tar Entry's header is:
struct oldgnu_header {
char unused_pad1[345]; // TarConstants.PAD1LEN_GNU - offset 0
char atime[12]; // TarConstants.ATIMELEN_GNU - offset 345
char ctime[12]; // TarConstants.CTIMELEN_GNU - offset 357
char offset[12]; // TarConstants.OFFSETLEN_GNU - offset 369
char longnames[4]; // TarConstants.LONGNAMESLEN_GNU - offset 381
char unused_pad2; // TarConstants.PAD2LEN_GNU - offset 385
struct sparse sp[4]; // TarConstants.SPARSELEN_GNU - offset 386
char isextended; // TarConstants.ISEXTENDEDLEN_GNU - offset 482
char realsize[12]; // TarConstants.REALSIZELEN_GNU - offset 483
char unused_pad[17]; // TarConstants.PAD3LEN_GNU - offset 495
};
Whereas, "struct sparse" is:
struct sparse {
char offset[12]; // offset 0
char numbytes[12]; // offset 12
};
The C structure for a xstar (Jörg Schilling star) Tar Entry's header is:
struct star_header {
char name[100]; // offset 0
char mode[8]; // offset 100
char uid[8]; // offset 108
char gid[8]; // offset 116
char size[12]; // offset 124
char mtime[12]; // offset 136
char chksum[8]; // offset 148
char typeflag; // offset 156
char linkname[100]; // offset 157
char magic[6]; // offset 257
char version[2]; // offset 263
char uname[32]; // offset 265
char gname[32]; // offset 297
char devmajor[8]; // offset 329
char devminor[8]; // offset 337
char prefix[131]; // offset 345
char atime[12]; // offset 476
char ctime[12]; // offset 488
char mfill[8]; // offset 500
char xmagic[4]; // offset 508 "tar\0"
};
which is identical to new-style POSIX up to the first 130 bytes of the prefix.
The C structure for the xstar-specific parts of a xstar Tar Entry's header is:
struct xstar_in_header {
char fill[345]; // offset 0 Everything before t_prefix
char prefix[1]; // offset 345 Prefix for t_name
char fill2; // offset 346
char fill3[8]; // offset 347
char isextended; // offset 355
struct sparse sp[SIH]; // offset 356 8 x 12
char realsize[12]; // offset 452 Real size for sparse data
char offset[12]; // offset 464 Offset for multivolume data
char atime[12]; // offset 476
char ctime[12]; // offset 488
char mfill[8]; // offset 500
char xmagic[4]; // offset 508 "tar\0"
};
| Modifier and Type | Field and Description |
|---|---|
| private FileTime | aTime
The entry's last access time. |
| private FileTime | birthTime
The entry's creation time. |
| private boolean | checkSumOK
If the header checksum is reasonably correct. |
| private FileTime | cTime
The entry's status change time. |
| private long | |
| public static final int | DEFAULT_DIR_MODE
Default permissions bits for directories |
| public static final int | DEFAULT_FILE_MODE
Default permissions bits for files |
| private int | devMajor
The entry's major device number. |
| private int | devMinor
The entry's minor device number. |
| private static final TarArchiveEntry[] | |
| private final Map | extraPaxHeaders
Extra, user supplied pax headers |
| private final Path | file
The entry's file reference |
| private long | groupId
The entry's group id. |
| private String | groupName
The entry's group name. |
| private boolean | isExtended
If an extension sparse header follows. |
| private byte | linkFlag
The entry's link flag. |
| private String | linkName
The entry's link name. |
| private final LinkOption[] | linkOptions
The entry's file linkOptions |
| private String | magic
The entry's magic tag. |
| public static final int | MAX_NAMELEN
Maximum length of a user's name in the tar file |
| public static final int | MILLIS_PER_SECOND
Convert millis to seconds |
| private int | mode
The entry's permission mode. |
| private FileTime | mTime
The entry's modification time. |
| private String | name
The entry's name. |
| private static final Pattern | PAX_EXTENDED_HEADER_FILE_TIMES_PATTERN
Regular expression pattern for validating values in pax extended header file time fields. |
| private boolean | paxGNU1XSparse
is this entry a GNU sparse entry using 1.X PAX formats? |
| private boolean | paxGNUSparse
Is this entry a GNU sparse entry using one of the PAX formats? |
| private final boolean | preserveAbsolutePath
Whether to allow leading slashes or drive names inside the name |
| private long | realSize
The entry's real size in case of a sparse file. |
| private long | size
The entry's size. |
| private List | sparseHeaders
The sparse headers in tar |
| private boolean | starSparse
Is this entry a star sparse entry using the PAX header? |
| public static final long | UNKNOWN
Value used to indicate unknown mode, user/groupids, device numbers and modTime when parsing a file in lenient mode and the archive contains illegal fields. |
| private long | userId
The entry's user id. |
| private String | userName
The entry's user name. |
| private String | version
The version of the format |
| Access | Constructor and Description |
|---|---|
| private | TarArchiveEntry(final boolean preserveAbsolutePath)
Constructs an empty entry and prepares the header values. |
| public | TarArchiveEntry(final byte[]
The header bytes from a tar archive entry. headerBuf)Constructs an entry from an archive's header bytes. |
| public | TarArchiveEntry(final byte[]
The header bytes from a tar archive entry. headerBuf, final ZipEncoding encoding to use for file names encoding)Constructs an entry from an archive's header bytes. |
| public | TarArchiveEntry(final byte[]
The header bytes from a tar archive entry. headerBuf, final ZipEncoding encoding to use for file names encoding, final boolean when set to true illegal values for group/userid, mode, device numbers and timestamp will be ignored and the fields set to
lenient)UNKNOWN. When set to false such illegal fields cause an exception instead.Constructs an entry from an archive's header bytes. |
| public | TarArchiveEntry(final byte[]
the header bytes from a tar archive entry. headerBuf, final ZipEncoding encoding to use for file names. encoding, final boolean when set to true illegal values for group/userid, mode, device numbers and timestamp will be ignored and the fields set to
lenient, final long UNKNOWN. When set to false such illegal fields cause an exception instead.position of the entry data in the random access file. dataOffset)Constructs an entry from an archive's header bytes for random access tar. |
| public | |
| public | TarArchiveEntry(final File
The file that the entry represents. file, final String the name to be used for the entry. fileName)Constructs an entry for a file. |
| public | TarArchiveEntry(final Map<String, String>
the parsed global PAX headers, or null if this is the first one. globalPaxHeaders, final byte[] The header bytes from a tar archive entry. headerBuf, final ZipEncoding encoding to use for file names encoding, final boolean when set to true illegal values for group/userid, mode, device numbers and timestamp will be ignored and the fields set to
lenient)UNKNOWN. When set to false such illegal fields cause an exception instead.Constructs an entry from an archive's header bytes. |
| public | TarArchiveEntry(final Map<String, String>
the parsed global PAX headers, or null if this is the first one. globalPaxHeaders, final byte[] the header bytes from a tar archive entry. headerBuf, final ZipEncoding encoding to use for file names. encoding, final boolean when set to true illegal values for group/userid, mode, device numbers and timestamp will be ignored and the fields set to
lenient, final long UNKNOWN. When set to false such illegal fields cause an exception instead.position of the entry data in the random access file. dataOffset)Constructs an entry from an archive's header bytes for random access tar. |
| public | |
| public | TarArchiveEntry(final Path
The file that the entry represents. file, final String the name to be used for the entry. fileName, final LinkOption... options indicating how symbolic links are handled. linkOptions)Constructs an entry for a file. |
| public | |
| public | TarArchiveEntry(String
the entry name name, final boolean whether to allow leading slashes or drive letters in the name. preserveAbsolutePath)Constructs an entry with only a name. |
| public | TarArchiveEntry(final String
the entry name name, final byte the entry link flag. linkFlag)Constructs an entry with a name and a link flag. |
| public | TarArchiveEntry(final String
the entry name name, final byte the entry link flag. linkFlag, final boolean whether to allow leading slashes or drive letters in the name. preserveAbsolutePath)Constructs an entry with a name and a link flag. |
| Modifier and Type | Method and Description |
|---|---|
| public void | addPaxHeader(final String
The full name of the header to set. name, final String value of header. value)Adds a PAX header to this entry. |
| public void | |
| public boolean | Returns: True if the entries are equal.Entry to be checked for equality. it)Overrides java. |
| public boolean | Returns: True if the entries are equal.Entry to be checked for equality. it)Determine if the two entries are equal. |
| private int | Returns: format typeThe tar entry header buffer to evaluate the format for. header)Evaluates an entry's header format from a header buffer. |
| private static FileTime | |
| private int | |
| private int | |
| pack-priv void | |
| pack-priv void | |
| pack-priv void | |
| public FileTime | |
| public long | getDataOffset()
Implements org. |
| public int | |
| public int | |
| public TarArchiveEntry[] | Returns: An array of TarEntry's for this entry's children.If this entry represents a file, and the file is a directory, return an array of TarEntries for this entry's children. |
| public String | Returns: The value of the header, if any.The full name of an extended PAX header to retrieve name)Gets named extra PAX header |
| public Map | |
| public File | Returns: this entry's file or null if the entry was not created from a file.Gets this entry's file. |
| public int | Returns: This entry's group id.
Deprecated
use #getLongGroupId instead as group ids can be bigger than
Gets this entry's group id.
Integer#MAX_VALUE
|
| public String | |
| public FileTime | |
| public Date | Returns: This entry's modification time.Implements org. |
| public FileTime | |
| public byte | |
| public String | |
| public long | |
| public long | |
| public int | |
| public Date | |
| public String | Returns: This entry's name.Implements org. |
| public List | Returns: immutable list of this entry's sparse headers, never nullGets this entry's sparse headers ordered by offset with all empty sparse sections at the start filtered out. |
| public Path | Returns: this entry's file or null if the entry was not created from a file.Gets this entry's file. |
| public long | Returns: This entry's real file size, if the file is not a sparse file, return size instead of realSize.Gets this entry's real file size in case of a sparse file. |
| public long | Returns: This entry's file size.Implements org. |
| public List | |
| public FileTime | |
| public int | Returns: This entry's user id.
Deprecated
use #getLongUserId instead as user ids can be bigger than
Gets this entry's user id.
Integer#MAX_VALUE
|
| public String | |
| public int | Returns: the entry hash codeOverrides java. |
| public boolean | |
| public boolean | Returns: whether this is a character deviceTests whether this is a character device entry. |
| public boolean | Returns: if the header checksum is reasonably correctTests whether this entry's checksum status. |
| public boolean | Returns: True if entry is a descendant of this.Entry to be checked as a descendent of this. desc)Tests whether the given entry is a descendant of this entry. |
| public boolean | Returns: True if this entry is a directory.Implements org. |
| public boolean | Returns: true if an extension oldgnu sparse header follows.Tests whether in case of an oldgnu sparse file if an extension sparse header follows. |
| public boolean | |
| public boolean | |
| public boolean | |
| public boolean | Returns: true if this is a long name extension provided by GNU tarTests whether this entry is a GNU long linkname block |
| public boolean | Returns: true if this is a long name extension provided by GNU tarTests whether this entry is a GNU long name block |
| public boolean | Returns: true if this is a sparse extension provided by GNU tarTests whether this entry is a GNU sparse block. |
| private boolean | |
| private boolean | |
| public boolean | |
| public boolean | Returns: true if this is a sparse extension provided by GNU tar or starTests whether this entry is a GNU or star sparse block using the oldgnu format. |
| public boolean | Returns: True if this entry is a sparse file with 1.X PAX FormatTests whether this entry is a sparse file with 1.X PAX Format or not |
| public boolean | Returns: true if this is a sparse extension provided by GNU tarTests whether this entry is a GNU sparse block using one of the PAX formats. |
| public boolean | |
| public boolean | |
| public boolean | Returns: true if this is a sparse extension provided by starTests whether this entry is a star sparse block using PAX headers. |
| public boolean | isStreamContiguous()
Implements org. |
| public boolean | Returns: whether this is a symbolic linkTests whether this is a symbolic link entry. |
| private boolean | |
| private static String | normalizeFileName(String fileName, final boolean preserveAbsolutePath)
Strips Windows' drive letter as well as any leading slashes, turns path separators into forward slashes. |
| private static Instant | |
| private long | |
| public void | parseTarHeader(final byte[]
The tar entry header buffer to get information from. header)Parses an entry's header information from a header buffer. |
| public void | parseTarHeader(final byte[]
The tar entry header buffer to get information from. header, final ZipEncoding encoding to use for file names encoding)Parse an entry's header information from a header buffer. |
| private void | parseTarHeader(final byte[] header, final ZipEncoding encoding, final boolean oldStyle, final boolean lenient)
|
| private void | parseTarHeader(final Map<String, String> globalPaxHeaders, final byte[] header, final ZipEncoding encoding, final boolean oldStyle, final boolean lenient)
|
| private void | parseTarHeaderUnwrapped(final Map<String, String> globalPaxHeaders, final byte[] header, final ZipEncoding encoding, final boolean oldStyle, final boolean lenient)
|
| private void | processPaxHeader(final String key, final String val)
Processes one pax header, using the entries extraPaxHeaders map as source for extra headers used when handling entries for sparse files. |
| private void | |
| private void | |
| private void | |
| public void | |
| public void | setDataOffset(final long
the position of the data in the tar. dataOffset)Sets the offset of the data for the tar entry. |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | setIds(final int
This entry's new user id. userId, final int This entry's new group id. groupId)Convenience method to set this entry's group and user ids. |
| public void | setLastAccessTime(final FileTime
This entry's new last access time. time)Sets this entry's last access time. |
| public void | setLastModifiedTime(final FileTime
This entry's new modification time. time)Sets this entry's modification time. |
| public void | |
| public void | |
| public void | |
| public void | setModTime(final FileTime
This entry's new modification time. time)Sets this entry's modification time. |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | setSparseHeaders(final List<TarArchiveStructSparse>
The new sparse headers sparseHeaders)Sets this entry's sparse headers |
| public void | setStatusChangeTime(final FileTime
This entry's new status change time. time)Sets this entry's status change time. |
| public void | |
| public void | |
| public void | |
| pack-priv void | updateEntryFromPaxHeaders(final Map<String, String> headers)
Update the entry using a map of pax headers. |
| public void | writeEntryHeader(final byte[]
The tar entry header buffer to fill in. outbuf)Writes an entry's header information to a header buffer. |
| public void | writeEntryHeader(final byte[]
The tar entry header buffer to fill in. outbuf, final ZipEncoding encoding to use when writing the file name. encoding, final boolean whether to use the star/GNU tar/BSD tar extension for numeric fields if their value doesn't fit in the maximum size of standard tar
archives starMode)Writes an entry's header information to a header buffer. |
| private int | writeEntryHeaderField(final long value, final byte[] outbuf, final int offset, final int length, final boolean starMode)
|
| private int | writeEntryHeaderOptionalTimeField(final FileTime time, int offset, final byte[] outbuf, final int fieldLength)
|