Class TarEntry

java.lang.Object
org.apache.tools.tar.TarEntry
All Implemented Interfaces:
TarConstants

public class TarEntry extends Object implements TarConstants
This class represents an entry in a Tar archive. It consists of the entry's header, as well as the entry's File. Entries can be instantiated in one of three ways, depending on how they are to be used.

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
 };