Format a TarEntry the same way that UNIX tar does
sb = new StringBuffer();
switch(e.type) {
case TarEntry.LF_OLDNORMAL:
case TarEntry.LF_NORMAL:
case TarEntry.LF_CONTIG:
case TarEntry.LF_LINK: // hard link: same as file
sb.append('-"); // 'f' would be sensible
break;
case TarEntry.LF_DIR:
sb.append('d");
break;
case TarEntry.LF_SYMLINK:
sb.append('l");
break;
case TarEntry.LF_CHR: // UNIX device file
sb.append('c");
break;
case TarEntry.LF_BLK: // UNIX device file
sb.append('b");
break;
case TarEntry.LF_FIFO: // UNIX named pipe
sb.append('p");
break;
default: // Can't happen?
sb.append('?");
break;
}
// Convert e.g., 754 to rwxrw-r--
int mode = e.getMode();
for (int i=0; i<3; i++) {
sb.append(rwx[mode >> shft[i] & 007]);
}
sb.append(' ");
// owner and group
sb.append(e.getUname()).append('/").append(e.getGname()).append(' ");
// size
// DecimalFormat can't do "%-9d", so we do part of it ourselves
sb.append(' ");
String t = sizeForm.format(e.getSize());
boolean digit = false;
char c;
for (int i=0; i<8; i++) {
c = t.charAt(i);
if (!digit && i<(8-1) && c == '0")
sb.append(' "); // leading space
else {
digit = true;
sb.append(c);
}
}
sb.append(' ");
// mtime
// copy file's mtime into Data object (after scaling
// from "sec since 1970" to "msec since 1970"), and format it.
date.setTime(1000*e.getTime());
sb.append(dateForm.format(date)).append(' ");
sb.append(e.getName());
if (e.isLink())
sb.append(" link to " ).append(e.getLinkName());
if (e.isSymLink())
sb.append(" -> " ).append(e.getLinkName());
return sb.toString();