Class TarHeader
java.lang.Object
org.jboss.shrinkwrap.impl.base.io.tar.TarHeader
- All Implemented Interfaces:
Cloneable
This class encapsulates the Tar Entry Header used in Tar Archives. The class also holds a number of tar constants,
used mostly in headers.
-
Field Summary
FieldsModifier and TypeFieldDescriptionint
The entry's checksum.static final int
The length of the checksum field in a header buffer.static final int
The length of the devices field in a header buffer.int
The entry's major device number.int
The entry's minor device number.static final int
The length of the group id field in a header buffer.static final int
The length of the group name field in a header buffer.static final String
The magic tag representing a GNU tar archive.int
The entry's group id.The entry's group name.static final byte
Block device file type.static final byte
Character device file type.static final byte
Contiguous file type.static final byte
Directory file type.static final byte
FIFO (pipe) file type.static final byte
Link file type.static final byte
Normal file type.static final byte
LF_ constants represent the "link flag" of an entry, or more commonly, the "entry type".static final byte
Symbolic link file type.byte
The entry's link flag.The entry's link name.The entry's magic tag.static final int
The length of the magic field in a header buffer.int
The entry's permission mode.static final int
The length of the mode field in a header buffer.long
The entry's modification time.static final int
The length of the modification time field in a header buffer.The entry's name.static final int
The length of the name field in a header buffer.static final int
The offset of the name field in a header buffer.static final int
The length of the name prefix field in a header buffer.static final int
The offset of the name prefix field in a header buffer.long
The entry's size.static final int
The length of the size field in a header buffer.static final String
The magic tag representing a POSIX tar archive.static final int
The length of the user id field in a header buffer.static final int
The length of the user name field in a header buffer.int
The entry's user id.The entry's user name. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()
TarHeaders can be cloned.static int
getCheckSumOctalBytes
(long value, byte[] buf, int offset, int length) Parse the checksum octal integer from a header buffer.static int
getFileNameBytes
(String newName, byte[] outbuf) This method, like getNameBytes(), is intended to place a name into a TarHeader's buffer.static int
getLongOctalBytes
(long value, byte[] buf, int offset, int length) Parse an octal long integer from a header buffer.getName()
Get the name of this entry.static int
getNameBytes
(StringBuffer name, byte[] buf, int offset, int length) Move the bytes from the name StringBuffer into the header's buffer.static int
getOctalBytes
(long value, byte[] buf, int offset, int length) Parse an octal integer from a header buffer.static StringBuffer
parseFileName
(byte[] header) Parse a file name from a header buffer.static StringBuffer
parseName
(byte[] header, int offset, int length) Parse an entry name from a header buffer.static long
parseOctal
(byte[] header, int offset, int length) Parse an octal string from a header buffer.
-
Field Details
-
NAMELEN
public static final int NAMELENThe length of the name field in a header buffer.- See Also:
-
NAMEOFFSET
public static final int NAMEOFFSETThe offset of the name field in a header buffer.- See Also:
-
PREFIXLEN
public static final int PREFIXLENThe length of the name prefix field in a header buffer.- See Also:
-
PREFIXOFFSET
public static final int PREFIXOFFSETThe offset of the name prefix field in a header buffer.- See Also:
-
MODELEN
public static final int MODELENThe length of the mode field in a header buffer.- See Also:
-
UIDLEN
public static final int UIDLENThe length of the user id field in a header buffer.- See Also:
-
GIDLEN
public static final int GIDLENThe length of the group id field in a header buffer.- See Also:
-
CHKSUMLEN
public static final int CHKSUMLENThe length of the checksum field in a header buffer.- See Also:
-
SIZELEN
public static final int SIZELENThe length of the size field in a header buffer.- See Also:
-
MAGICLEN
public static final int MAGICLENThe length of the magic field in a header buffer.- See Also:
-
MODTIMELEN
public static final int MODTIMELENThe length of the modification time field in a header buffer.- See Also:
-
UNAMELEN
public static final int UNAMELENThe length of the user name field in a header buffer.- See Also:
-
GNAMELEN
public static final int GNAMELENThe length of the group name field in a header buffer.- See Also:
-
DEVLEN
public static final int DEVLENThe length of the devices field in a header buffer.- See Also:
-
LF_OLDNORM
public static final byte LF_OLDNORMLF_ constants represent the "link flag" of an entry, or more commonly, the "entry type". This is the "old way" of indicating a normal file.- See Also:
-
LF_NORMAL
public static final byte LF_NORMALNormal file type.- See Also:
-
LF_LINK
public static final byte LF_LINKLink file type.- See Also:
-
LF_SYMLINK
public static final byte LF_SYMLINKSymbolic link file type.- See Also:
-
LF_CHR
public static final byte LF_CHRCharacter device file type.- See Also:
-
LF_BLK
public static final byte LF_BLKBlock device file type.- See Also:
-
LF_DIR
public static final byte LF_DIRDirectory file type.- See Also:
-
LF_FIFO
public static final byte LF_FIFOFIFO (pipe) file type.- See Also:
-
LF_CONTIG
public static final byte LF_CONTIGContiguous file type.- See Also:
-
TMAGIC
The magic tag representing a POSIX tar archive.- See Also:
-
GNU_TMAGIC
The magic tag representing a GNU tar archive.- See Also:
-
name
The entry's name. -
mode
public int modeThe entry's permission mode. -
userId
public int userIdThe entry's user id. -
groupId
public int groupIdThe entry's group id. -
size
public long sizeThe entry's size. -
modTime
public long modTimeThe entry's modification time. -
checkSum
public int checkSumThe entry's checksum. -
linkFlag
public byte linkFlagThe entry's link flag. -
linkName
The entry's link name. -
magic
The entry's magic tag. -
userName
The entry's user name. -
groupName
The entry's group name. -
devMajor
public int devMajorThe entry's major device number. -
devMinor
public int devMinorThe entry's minor device number.
-
-
Constructor Details
-
TarHeader
public TarHeader()
-
-
Method Details
-
clone
TarHeaders can be cloned. -
getName
Get the name of this entry.- Returns:
- Teh entry's name.
-
parseOctal
Parse an octal string from a header buffer. This is used for the file permission mode value.- Parameters:
header
- The header buffer from which to parse.offset
- The offset into the buffer from which to parse.length
- The number of header bytes to parse.- Returns:
- The long value of the octal string.
- Throws:
InvalidHeaderException
-
parseFileName
Parse a file name from a header buffer. This is different from parseName() in that is recognizes 'ustar' names and will handle adding on the "prefix" field to the name. Contributed by Dmitri Tikhonov invalid input: '<'dxt2431@yahoo.com>- Parameters:
header
- The header buffer from which to parse.offset
- The offset into the buffer from which to parse.length
- The number of header bytes to parse.- Returns:
- The header's entry name.
-
parseName
public static StringBuffer parseName(byte[] header, int offset, int length) throws InvalidHeaderException Parse an entry name from a header buffer.- Parameters:
header
- The header buffer from which to parse.offset
- The offset into the buffer from which to parse.length
- The number of header bytes to parse.- Returns:
- The header's entry name.
- Throws:
InvalidHeaderException
-
getFileNameBytes
This method, like getNameBytes(), is intended to place a name into a TarHeader's buffer. However, this method is sophisticated enough to recognize long names (name.length() > NAMELEN). In these cases, the method will break the name into a prefix and suffix and place the name in the header in 'ustar' format. It is up to the TarEntry to manage the "entry header format". This method assumes the name is valid for the type of archive being generated.- Parameters:
newName
- The new name to place into the header buffer.outbuf
- The buffer containing the entry header to modify.- Returns:
- The current offset in the tar header (always TarHeader.NAMELEN).
- Throws:
InvalidHeaderException
- If the name will not fit in the header.
-
getNameBytes
Move the bytes from the name StringBuffer into the header's buffer.- Parameters:
offset
- The offset into the buffer at which to store.length
- The number of header bytes to store.header
- The header buffer into which to copy the name.- Returns:
- The new offset (offset + length).
-
getOctalBytes
public static int getOctalBytes(long value, byte[] buf, int offset, int length) Parse an octal integer from a header buffer.- Parameters:
offset
- The offset into the buffer from which to parse.length
- The number of header bytes to parse.header
- The header buffer from which to parse.- Returns:
- The integer value of the octal bytes.
-
getLongOctalBytes
public static int getLongOctalBytes(long value, byte[] buf, int offset, int length) Parse an octal long integer from a header buffer.- Parameters:
offset
- The offset into the buffer from which to parse.length
- The number of header bytes to parse.header
- The header buffer from which to parse.- Returns:
- The long value of the octal bytes.
-
getCheckSumOctalBytes
public static int getCheckSumOctalBytes(long value, byte[] buf, int offset, int length) Parse the checksum octal integer from a header buffer.- Parameters:
offset
- The offset into the buffer from which to parse.length
- The number of header bytes to parse.header
- The header buffer from which to parse.- Returns:
- The integer value of the entry's checksum.
-