Maven module :un.storage : archive-tar :
Class : un.storage.archive.tar.TarEntry
Extends/Implements : -
Subclasses : -

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.



Original Unix Tar Header:

Field Field Field
Width Name Meaning
----- --------- ---------------------------
100 name name of file
8 mode file mode
8 uid owner user ID
8 gid owner group ID
12 size length of file in bytes
12 mtime modify time of file
8 chksum checksum for header
1 link indicator for links
100 linkname name of linked file





POSIX "ustar" Style Tar Header:

Field Field Field
Width Name Meaning
----- --------- ---------------------------
100 name name of file
8 mode file mode
8 uid owner user ID
8 gid owner group ID
12 size length of file in bytes
12 mtime modify time of file
8 chksum checksum for header
1 typeflag type of file
100 linkname name of linked file
6 magic USTAR indicator
2 version USTAR version
32 uname owner user name
32 gname owner group name
8 devmajor device major number
8 devminor device minor number
155 prefix prefix for file name

struct posix_header
{ byte offset
char name[100]; 0
char mode[8]; 100
char uid[8]; 108
char gid[8]; 116
char size[12]; 124
char mtime[12]; 136
char chksum[8]; 148
char typeflag; 156
char linkname[100]; 157
char magic[6]; 257
char version[2]; 263
char uname[32]; 265
char gname[32]; 297
char devmajor[8]; 329
char devminor[8]; 337
char prefix[155]; 345
}; 500



Note that while the class does recognize GNU formatted headers, it does not
perform proper processing of GNU archives. I hope to add the GNU support
someday.

Directory "size" fix contributed by: Bert Becker

@author Timothy Gerard Endres,


Variables : file, header, unixFormat, ustarFormat, gnuFormat
Functions : TarEntry, TarEntry, TarEntry, TarEntry, isUSTarFormat, setUSTarFormat, isGNUTarFormat, setGNUTarFormat, isUnixTarFormat, setUnixTarFormat, equals, isDescendent, getHeader, getName, setName, getUserId, setUserId, getGroupId, setGroupId, getUserName, setUserName, getGroupName, setGroupName, setIds, setNames, setModTime, getFile, getSize, setSize, isDirectory, getFileTarHeader, getDirectoryEntries, computeCheckSum, writeEntryHeader, parseTarHeader, nameTarHeader, toString



If this entry represents a File, this references it.
protected File file


This is the entry's header information.
protected TarHeader header


Set to true if this is a "old-unix" format entry.
protected boolean unixFormat


Set to true if this is a 'ustar' format entry.
protected boolean ustarFormat


Set to true if this is a GNU 'ustar' format entry.
protected boolean gnuFormat



Construct an entry with only a name. This allows the programmer to
construct the entry's header "by hand". File is set to null.
public void TarEntry (String name)


Construct an entry for a file. File is set to file, and the header is
constructed from information from the file.
param  file The file that the entry represents.
public void TarEntry (File file)


Construct an entry from an archive's header bytes. File is set to null.
param  headerBuf The header bytes from a tar archive entry.
public void TarEntry (byte[] headerBuf)


Construct an entry from an archive's header bytes. File is set to null.
param  headerBuf The header bytes from a tar archive entry.
public void TarEntry (TarEntry toCopy)


Returns true if this entry's header is in "ustar" format.

@return True if the entry's header is in "ustar" format.
public boolean isUSTarFormat ()


Sets this entry's header format to "ustar".
public void setUSTarFormat ()


Returns true if this entry's header is in the GNU 'ustar' format.

@return True if the entry's header is in the GNU 'ustar' format.
public boolean isGNUTarFormat ()


Sets this entry's header format to GNU "ustar".
public void setGNUTarFormat ()


Returns true if this entry's header is in the old "unix-tar" format.

@return True if the entry's header is in the old "unix-tar" format.
public boolean isUnixTarFormat ()


Sets this entry's header format to "unix-style".
public void setUnixTarFormat ()


Determine if the two entries are equal. Equality is determined by the
header names being equal.
return  it Entry to be checked for equality.
return  True if the entries are equal.
public boolean equals (TarEntry it)


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.
param  desc Entry to be checked as a descendent of this.
return  True if entry is a descendant of this.
public boolean isDescendent (TarEntry desc)


Get this entry's header.

@return This entry's TarHeader.
public TarHeader getHeader ()


Get this entry's name.

@return This entry's name.
public String getName ()


Set this entry's name.

@param name This entry's new name.
public void setName (String name)


Get this entry's user id.

@return This entry's user id.
public int getUserId ()


Set this entry's user id.

@param userId This entry's new user id.
public void setUserId (int userId)


Get this entry's group id.

@return This entry's group id.
public int getGroupId ()


Set this entry's group id.

@param groupId This entry's new group id.
public void setGroupId (int groupId)


Get this entry's user name.

@return This entry's user name.
public String getUserName ()


Set this entry's user name.

@param userName This entry's new user name.
public void setUserName (String userName)


Get this entry's group name.

@return This entry's group name.
public String getGroupName ()


Set this entry's group name.

@param groupName This entry's new group name.
public void setGroupName (String groupName)


Convenience method to set this entry's group and user ids.

@param userId This entry's new user id.
@param groupId This entry's new group id.
public void setIds (int userId, int groupId)


Convenience method to set this entry's group and user names.

@param userName This entry's new user name.
@param groupName This entry's new group name.
public void setNames (String userName, String groupName)


Set this entry's modification time. The parameter passed to this method
is in "Java time".

@param time This entry's new modification time.
public void setModTime (long time)


Get this entry's file.

@return This entry's file.
public File getFile ()


Get this entry's file size.

@return This entry's file size.
public long getSize ()


Set this entry's file size.

@param size This entry's new file size.
public void setSize (long size)


Return whether or not this entry represents a directory.
return  True if this entry is a directory.
public boolean isDirectory ()


Fill in a TarHeader with information from a File.
param  hdr The TarHeader to fill in.
param  file The file from which to get the header information.
public void getFileTarHeader (TarHeader hdr, File file)


If this entry represents a file, and the file is a directory, return an
array of TarEntries for this entry's children.

@return An array of TarEntry's for this entry's children.
public TarEntry[] getDirectoryEntries ()


Compute the checksum of a tar entry header.
param  buf The tar entry's header buffer.
return  The computed checksum.
public long computeCheckSum (byte[] buf)


Write an entry's header information to a header buffer. This method can
throw an InvalidHeaderException
param  outbuf The tar entry header buffer to fill in.
throws  InvalidHeaderException If the name will not fit in the header.
public void writeEntryHeader (byte[] outbuf)


Parse an entry's TarHeader information from a header buffer.

Old unix-style code contributed by David Mehringer
.

@param hdr The TarHeader to fill in from the buffer information.
@param header The tar entry header buffer to get information from.
public void parseTarHeader (TarHeader hdr, byte[] headerBuf)


Fill in a TarHeader given only the entry's name.
param  hdr The TarHeader to fill in.
param  name The tar entry name.
public void nameTarHeader (TarHeader hdr, String name)

public String toString ()