FileDocCategorySizeDatePackage
TarEntry.javaAPI DocExample6027Sat Mar 06 15:16:20 GMT 2004None

TarEntry

public class TarEntry extends Object
One entry in an archive file.
author
Ian Darwin
version
$Id: TarEntry.java,v 1.7 2004/03/06 21:16:19 ian Exp $
note
Tar format info taken from John Gilmore's public domain tar program,
(#)tar.h
1.21 87/05/01 Public Domain, which said: "Created 25 August 1985 by John Gilmore, ihnp4!hoptoad!gnu." John is now gnu@toad.com, and by another path tar.h is GPL'd in GNU Tar.

Fields Summary
public long
fileOffset
Where in the tar archive this entry's HEADER is found.
public static final int
NAMSIZ
The maximum size of a name
public static final int
TUNMLEN
public static final int
TGNMLEN
byte[]
name
File name
byte[]
mode
permissions, e.g., rwxr-xr-x?
byte[]
uid
byte[]
gid
byte[]
size
byte[]
mtime
byte[]
chksum
byte
type
byte[]
linkName
byte[]
magic
byte[]
uname
byte[]
gname
byte[]
devmajor
byte[]
devminor
public static final byte[]
TMAGIC
public static final int
LF_OLDNORMAL
public static final int
LF_NORMAL
public static final int
LF_LINK
public static final int
LF_SYMLINK
public static final int
LF_CHR
public static final int
LF_BLK
public static final int
LF_DIR
public static final int
LF_FIFO
public static final int
LF_CONTIG
Constructors Summary
public TarEntry(RandomAccessFile is)


	/* Constructor that reads the entry's header. */
	      

		fileOffset = is.getFilePointer();

		// read() returns -1 at EOF
		if (is.read(name) < 0)
			throw new EOFException();
		// Tar pads to block boundary with nulls.
		if (name[0] == '\0")
			throw new EOFException();
		// OK, read remaining fields.
		is.read(mode);
		is.read(uid);
		is.read(gid);
		is.read(size);
		is.read(mtime);
		is.read(chksum);
		type = is.readByte();
		is.read(linkName);
		is.read(magic);
		is.read(uname);
		is.read(gname);
		is.read(devmajor);
		is.read(devminor);

		// Since the tar header is < 512, we need to skip it.
		is.skipBytes((int)(TarFile.RECORDSIZE -
			(is.getFilePointer() % TarFile.RECORDSIZE)));

		// TODO if checksum() fails,
		//	throw new TarException("Failed to find next header");

	
Methods Summary
public java.lang.StringgetGname()
Returns the string name of the group id

		return new String(gname).trim();
	
public java.lang.StringgetLinkName()
Returns the name of the file this entry is a link to, or null if this entry is not a link.

		// if (isLink())
		// 	return null;
		return new String(linkName).trim();
	
public intgetMode()
Returns the UNIX-specific "mode" (type+permissions) of the entry

		try {
			return Integer.parseInt(new String(mode).trim(), 8) & 0777;
		} catch (IllegalArgumentException e) {
			return 0;
		}
	
public java.lang.StringgetName()
Returns the name of the file this entry represents.

		return new String(name).trim();
	
public intgetSize()
Returns the size of the entry

		try {
			return Integer.parseInt(new String(size).trim(), 8);
		} catch (IllegalArgumentException e) {
			return 0;
		}
	
public longgetTime()
Returns the modification time of the entry

		try {
			return Long.parseLong(new String(mtime).trim(), 8);
		} catch (IllegalArgumentException e) {
			return 0;
		}
	
public java.lang.StringgetTypeName()

		switch(type) {
		case LF_OLDNORMAL:
		case LF_NORMAL:
			return "file";
		case LF_LINK:
			return "link w/in archive";
		case LF_SYMLINK:
			return "symlink";
		case LF_CHR:
		case LF_BLK:
		case LF_FIFO:
			return "special file";
		case LF_DIR:
			return "directory";
		case LF_CONTIG:
			return "contig";
		default:
			throw new IllegalStateException("TarEntry.getTypeName: type " + type + " invalid");
		}
	
public java.lang.StringgetUname()
Returns the string name of the userid

		return new String(uname).trim();
	
public intgetgid()
Returns the numeric gid of the entry

		try {
			return Integer.parseInt(new String(gid).trim());
		} catch (IllegalArgumentException e) {
			return -1;
		}
	
public intgetuid()
Returns the numeric userid of the entry

		try {
			return Integer.parseInt(new String(uid).trim());
		} catch (IllegalArgumentException e) {
			return -1;
		}
	
booleanisDirectory()
Returns true if this entry represents a directory

		return type == LF_DIR;
	
booleanisFile()
Returns true if this entry represents a file

		return type == LF_NORMAL || type == LF_OLDNORMAL;
	
booleanisLink()
Returns true if this a hard link (to a file in the archive)

		return type == LF_LINK;
	
booleanisSpecial()
Returns true if this entry represents some type of UNIX special file

		return type == LF_CHR || type == LF_BLK || type == LF_FIFO;
	
booleanisSymLink()
Returns true if this a symbolic link

		return type == LF_SYMLINK;
	
public java.lang.StringtoString()

		return "TarEntry[" + getName() + ']";