FileDocCategorySizeDatePackage
x_tar.javaAPI DocExample1206Fri Jul 11 00:58:42 BST 1997exploringjava.contenthandlers.application

x_tar

public class x_tar extends ContentHandler

Fields Summary
static int
RECORDLEN
static int
NAMEOFF
static int
NAMELEN
static int
SIZEOFF
static int
SIZELEN
static int
MTIMEOFF
static int
MTIMELEN
Constructors Summary
Methods Summary
public java.lang.ObjectgetContent(java.net.URLConnection uc)


	      
		InputStream is = uc.getInputStream();
		StringBuffer output = new StringBuffer( "Tape Archive Listing:\n\n" );
		byte [] header = new byte[RECORDLEN];
		int count = 0;

		while ( (is.read(header) == RECORDLEN) && (header[NAMEOFF] != 0) ) {

			String name = new String(header, NAMEOFF, NAMELEN, "8859_1").trim();
			String s = new String(header, SIZEOFF, SIZELEN, "8859_1").trim();
			int size = Integer.parseInt(s, 8);
			s = new String(header, MTIMEOFF, MTIMELEN, "8859_1").trim();
			long l = Integer.parseInt(s, 8);
			Date mtime = new Date( l*1000 );

			output.append( size + " " + mtime + " " + name + "\n" );

			count += is.skip( size ) + RECORDLEN;
			if ( count % RECORDLEN != 0 )
				count += is.skip ( RECORDLEN - count % RECORDLEN);
		}

		if ( count == 0 )
			output.append("Not a valid TAR file\n");

		return( output.toString() );