TarEntries that are created from the header bytes read from an archive are instantiated with the TarEntry(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 TarEntry(File) 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[NAMSIZ];
char mode[8];
char uid[8];
char gid[8];
char size[12];
char mtime[12];
char chksum[8];
char linkflag;
char linkname[NAMSIZ];
char magic[8];
char uname[TUNMLEN];
char gname[TGNMLEN];
char devmajor[8];
char devminor[8];
} 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.
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
};
| Modifier and Type | Field and Description |
|---|---|
| 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 File | 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 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 long | modTime
The entry's modification time. |
| private String | name
The entry's name. |
| private long | realSize
The entry's real size in case of a sparse file. |
| private long | size
The entry's size. |
| 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 | |
| public | |
| public | |
| public | |
| public | |
| public | |
| public | TarEntry(byte[]
The header bytes from a tar archive entry. headerBuf)Construct an entry from an archive's header bytes. |
| public | TarEntry(byte[]
The header bytes from a tar archive entry. headerBuf, ZipEncoding encoding to use for file names encoding)Construct an entry from an archive's header bytes. |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | |
| public boolean | Returns: True if the entries are equal.Entry to be checked for equality. it)Overrides java. |
| private int | Returns: format typeThe tar entry header buffer to evaluate the format for. header)Evaluate an entry's header format from a header buffer. |
| public int | |
| public int | |
| public TarEntry[] | 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 File | |
| public int | Returns: This entry's group id.
Deprecated
use #getLongGroupId instead as group ids can be
bigger than
Get this entry's group id.
Integer#MAX_VALUE
|
| public String | |
| public byte | |
| public String | |
| public long | |
| public long | |
| public int | |
| public Date | |
| public String | |
| public long | Returns: This entry's real file size.Get this entry's real file size in case of a sparse file. |
| public long | |
| public int | Returns: This entry's user id.
Deprecated
use #getLongUserId instead as user ids can be
bigger than
Get this entry's user id.
Integer#MAX_VALUE
|
| public String | |
| public int | Returns: the entry hashcodeOverrides java. |
| public boolean | |
| public boolean | Returns: true if it is a character device entryCheck if this is a character device entry. |
| public boolean | Returns: True if entry is a descendant of this.Entry to be checked as a descendant of this. desc)Determine if the given entry is a descendant of this entry. |
| public boolean | Returns: True if this entry is a directory.Return whether or not this entry represents a directory. |
| private static boolean | Returns: true if buffer1 and buffer2 have same contents, having regard to trailing nullsbyte[] buffer1, final int int offset1, final int int length1, final byte[] byte[] buffer2, final int int offset2, final int int length2, boolean boolean ignoreTrailingNulls)Compare byte buffers, optionally ignoring trailing nulls |
| public boolean | Returns: true if an extension sparse header follows.Indicates in case of a 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 tarIndicate if this entry is a GNU long linkname block |
| public boolean | Returns: true if this is a long name extension provided by GNU tarIndicate if this entry is a GNU long name block |
| public boolean | Returns: true if this is a sparse extension provided by GNU tarIndicate if this entry is a GNU sparse block. |
| public boolean | |
| public boolean | |
| public boolean | |
| private static boolean | Returns: true if buffer is the same as the expected stringString expected, byte[] byte[] buffer, int int offset, int int length)Check if buffer contents matches Ascii String. |
| private static String | normalizeFileName(String fileName, boolean preserveLeadingSlashes)
Strips Windows' drive letter as well as any leading slashes, turns path separators into forward slashes. |
| public void | parseTarHeader(byte[]
The tar entry header buffer to get information from. header)Parse an entry's header information from a header buffer. |
| public void | parseTarHeader(byte[]
The tar entry header buffer to get information from. header, ZipEncoding encoding to use for file names encoding)Parse an entry's header information from a header buffer. |
| private void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | setIds(int
This entry's new user id. userId, int This entry's new group id. groupId)Convenience method to set this entry's group and user ids. |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | |
| public void | writeEntryHeader(byte[]
The tar entry header buffer to fill in. outbuf)Write an entry's header information to a header buffer. |
| public void | writeEntryHeader(byte[]
The tar entry header buffer to fill in. outbuf, ZipEncoding encoding to use when writing the file name. encoding, 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)Write an entry's header information to a header buffer. |
| private int |
| DEFAULT_DIR_MODE | back to summary |
|---|---|
| public static final int DEFAULT_DIR_MODE Default permissions bits for directories | |
| DEFAULT_FILE_MODE | back to summary |
|---|---|
| public static final int DEFAULT_FILE_MODE Default permissions bits for files | |
| devMajor | back to summary |
|---|---|
| private int devMajor The entry's major device number. | |
| devMinor | back to summary |
|---|---|
| private int devMinor The entry's minor device number. | |
| file | back to summary |
|---|---|
| private File file The entry's file reference | |
| groupId | back to summary |
|---|---|
| private long groupId The entry's group id. | |
| groupName | back to summary |
|---|---|
| private String groupName The entry's group name. | |
| isExtended | back to summary |
|---|---|
| private boolean isExtended If an extension sparse header follows. | |
| linkFlag | back to summary |
|---|---|
| private byte linkFlag The entry's link flag. | |
| linkName | back to summary |
|---|---|
| private String linkName The entry's link name. | |
| magic | back to summary |
|---|---|
| private String magic The entry's magic tag. | |
| MAX_NAMELEN | back to summary |
|---|---|
| public static final int MAX_NAMELEN Maximum length of a user's name in the tar file | |
| MILLIS_PER_SECOND | back to summary |
|---|---|
| public static final int MILLIS_PER_SECOND Convert millis to seconds | |
| mode | back to summary |
|---|---|
| private int mode The entry's permission mode. | |
| modTime | back to summary |
|---|---|
| private long modTime The entry's modification time. | |
| name | back to summary |
|---|---|
| private String name The entry's name. | |
| realSize | back to summary |
|---|---|
| private long realSize The entry's real size in case of a sparse file. | |
| size | back to summary |
|---|---|
| private long size The entry's size. | |
| userId | back to summary |
|---|---|
| private long userId The entry's user id. | |
| userName | back to summary |
|---|---|
| private String userName The entry's user name. | |
| version | back to summary |
|---|---|
| private String version The version of the format | |
| TarEntry | back to summary |
|---|---|
| private TarEntry() Construct an empty entry and prepares the header values. | |
| TarEntry | back to summary |
|---|---|
| public TarEntry(String name) Construct an entry with only a name. This allows the programmer to construct the entry's header "by hand". File is set to null.
| |
| TarEntry | back to summary |
|---|---|
| public TarEntry(String name, boolean preserveLeadingSlashes) Construct an entry with only a name. This allows the programmer to construct the entry's header "by hand". File is set to null.
| |
| TarEntry | back to summary |
|---|---|
| public TarEntry(String name, byte linkFlag) Construct an entry with a name and a link flag.
| |
| TarEntry | back to summary |
|---|---|
| public TarEntry(File file) Construct an entry for a file. File is set to file, and the header is constructed from information from the file. The name is set from the normalized file path.
| |
| TarEntry | back to summary |
|---|---|
| public TarEntry(File file, String fileName) Construct an entry for a file. File is set to file, and the header is constructed from information from the file. | |
| TarEntry | back to summary |
|---|---|
| public TarEntry(byte[] headerBuf) Construct an entry from an archive's header bytes. File is set to null.
| |
| TarEntry | back to summary |
|---|---|
| public TarEntry(byte[] headerBuf, ZipEncoding encoding) throws IOException Construct an entry from an archive's header bytes. File is set to null.
| |
| equals | back to summary |
|---|---|
| public boolean equals(TarEntry it) Determine if the two entries are equal. Equality is determined by the header names being equal.
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object it) Overrides java. Determine if the two entries are equal. Equality is determined by the header names being equal. | |
| evaluateType | back to summary |
|---|---|
| private int evaluateType(byte[] header) Evaluate an entry's header format from a header buffer.
| |
| getDevMajor | back to summary |
|---|---|
| public int getDevMajor() Get this entry's major device number.
| |
| getDevMinor | back to summary |
|---|---|
| public int getDevMinor() Get this entry's minor device number.
| |
| getDirectoryEntries | back to summary |
|---|---|
| public TarEntry[] getDirectoryEntries() If this entry represents a file, and the file is a directory, return an array of TarEntries for this entry's children.
| |
| getFile | back to summary |
|---|---|
| public File getFile() Get this entry's file.
| |
| getGroupId | back to summary |
|---|---|
| public int getGroupId()
Deprecated use #getLongGroupId instead as group ids can be
bigger than Get this entry's group id.
| |
| getGroupName | back to summary |
|---|---|
| public String getGroupName() Get this entry's group name.
| |
| getLinkFlag | back to summary |
|---|---|
| public byte getLinkFlag() Get this entry's link flag.
| |
| getLinkName | back to summary |
|---|---|
| public String getLinkName() Get this entry's link name.
| |
| getLongGroupId | back to summary |
|---|---|
| public long getLongGroupId() Get this entry's group id.
| |
| getLongUserId | back to summary |
|---|---|
| public long getLongUserId() Get this entry's user id.
| |
| getMode | back to summary |
|---|---|
| public int getMode() Get this entry's mode.
| |
| getModTime | back to summary |
|---|---|
| public Date getModTime() Set this entry's modification time.
| |
| getName | back to summary |
|---|---|
| public String getName() Get this entry's name.
| |
| getRealSize | back to summary |
|---|---|
| public long getRealSize() Get this entry's real file size in case of a sparse file.
| |
| getSize | back to summary |
|---|---|
| public long getSize() Get this entry's file size.
| |
| getUserId | back to summary |
|---|---|
| public int getUserId()
Deprecated use #getLongUserId instead as user ids can be
bigger than Get this entry's user id.
| |
| getUserName | back to summary |
|---|---|
| public String getUserName() Get this entry's user name.
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Hashcodes are based on entry names.
| |
| isBlockDevice | back to summary |
|---|---|
public boolean isBlockDevice()
| |
| isCharacterDevice | back to summary |
|---|---|
| public boolean isCharacterDevice() Check if this is a character device entry.
| |
| isDescendent | back to summary |
|---|---|
| public boolean isDescendent(TarEntry desc) Determine if the given entry is a descendant of this entry. Descendancy is determined by the name of the descendant starting with this entry's name.
| |
| isDirectory | back to summary |
|---|---|
| public boolean isDirectory() Return whether or not this entry represents a directory.
| |
| isEqual | back to summary |
|---|---|
| private static boolean isEqual(final byte[] buffer1, final int offset1, final int length1, final byte[] buffer2, final int offset2, final int length2, boolean ignoreTrailingNulls) Compare byte buffers, optionally ignoring trailing nulls
| |
| isExtended | back to summary |
|---|---|
| public boolean isExtended() Indicates in case of a sparse file if an extension sparse header follows.
| |
| isFIFO | back to summary |
|---|---|
public boolean isFIFO()
| |
| isFile | back to summary |
|---|---|
| public boolean isFile() Check if this is a "normal file".
| |
| isGlobalPaxHeader | back to summary |
|---|---|
| public boolean isGlobalPaxHeader() Check if this is a Pax header.
| |
| isGNULongLinkEntry | back to summary |
|---|---|
| public boolean isGNULongLinkEntry() Indicate if this entry is a GNU long linkname block
| |
| isGNULongNameEntry | back to summary |
|---|---|
| public boolean isGNULongNameEntry() Indicate if this entry is a GNU long name block
| |
| isGNUSparse | back to summary |
|---|---|
| public boolean isGNUSparse() Indicate if this entry is a GNU sparse block.
| |
| isLink | back to summary |
|---|---|
| public boolean isLink() Check if this is a link entry.
| |
| isPaxHeader | back to summary |
|---|---|
| public boolean isPaxHeader() Check if this is a Pax header.
| |
| isSymbolicLink | back to summary |
|---|---|
| public boolean isSymbolicLink() Check if this is a symbolic link entry.
| |
| matchAsciiBuffer | back to summary |
|---|---|
| private static boolean matchAsciiBuffer(String expected, byte[] buffer, int offset, int length) Check if buffer contents matches Ascii String.
| |
| normalizeFileName | back to summary |
|---|---|
| private static String normalizeFileName(String fileName, boolean preserveLeadingSlashes) Strips Windows' drive letter as well as any leading slashes, turns path separators into forward slashes. | |
| parseTarHeader | back to summary |
|---|---|
| public void parseTarHeader(byte[] header) Parse an entry's header information from a header buffer.
| |
| parseTarHeader | back to summary |
|---|---|
| public void parseTarHeader(byte[] header, ZipEncoding encoding) throws IOException Parse an entry's header information from a header buffer.
| |
| parseTarHeader | back to summary |
|---|---|
| private void parseTarHeader(byte[] header, ZipEncoding encoding, final boolean oldStyle) throws IOException | |
| setDevMajor | back to summary |
|---|---|
| public void setDevMajor(int devNo) Set this entry's major device number.
| |
| setDevMinor | back to summary |
|---|---|
| public void setDevMinor(int devNo) Set this entry's minor device number.
| |
| setGroupId | back to summary |
|---|---|
| public void setGroupId(int groupId) Set this entry's group id.
| |
| setGroupId | back to summary |
|---|---|
| public void setGroupId(long groupId) Set this entry's group id.
| |
| setGroupName | back to summary |
|---|---|
| public void setGroupName(String groupName) Set this entry's group name.
| |
| setIds | back to summary |
|---|---|
| public void setIds(int userId, int groupId) Convenience method to set this entry's group and user ids.
| |
| setLinkFlag | back to summary |
|---|---|
| public void setLinkFlag(byte linkFlag) Set this entry's link flag.
| |
| setLinkName | back to summary |
|---|---|
| public void setLinkName(String link) Set this entry's link name.
| |
| setMode | back to summary |
|---|---|
| public void setMode(int mode) Set the mode for this entry
| |
| setModTime | back to summary |
|---|---|
| public void setModTime(long time) Set this entry's modification time. The parameter passed to this method is in "Java time".
| |
| setModTime | back to summary |
|---|---|
| public void setModTime(Date time) Set this entry's modification time.
| |
| setName | back to summary |
|---|---|
| public void setName(String name) Set this entry's name.
| |
| setNames | back to summary |
|---|---|
| public void setNames(String userName, String groupName) Convenience method to set this entry's group and user names. | |
| setSize | back to summary |
|---|---|
| public void setSize(long size) Set this entry's file size.
| |
| setUserId | back to summary |
|---|---|
| public void setUserId(int userId) Set this entry's user id.
| |
| setUserId | back to summary |
|---|---|
| public void setUserId(long userId) Set this entry's user id.
| |
| setUserName | back to summary |
|---|---|
| public void setUserName(String userName) Set this entry's user name.
| |
| writeEntryHeader | back to summary |
|---|---|
| public void writeEntryHeader(byte[] outbuf) Write an entry's header information to a header buffer. This method does not use the star/GNU tar/BSD tar extensions.
| |
| writeEntryHeader | back to summary |
|---|---|
| public void writeEntryHeader(byte[] outbuf, ZipEncoding encoding, boolean starMode) throws IOException Write an entry's header information to a header buffer.
| |
| writeEntryHeaderField | back to summary |
|---|---|
| private int writeEntryHeaderField(long value, byte[] outbuf, int offset, int length, boolean starMode) | |