FileDocCategorySizeDatePackage
DumpFile.javaAPI DocExample1308Tue Mar 13 15:32:32 GMT 2001None

DumpFile

public class DumpFile extends Object
Read a file and decode, using DataInputStream and System.out

Fields Summary
public static final int
PERLINE
The numberof items per line
protected StringBuffer
num
protected StringBuffer
txt
Constructors Summary
Methods Summary
protected voiddump()


	   
		System.out.print(num);
		System.out.print(' ");
		System.out.print(txt);
		num.setLength(0);
		txt.setLength(0);
	
public static voidmain(java.lang.String[] av)

		DumpFile c = new DumpFile();
		switch(av.length) {
		case 0: c.process(System.in);
			break;
		default:
			for (int i=0; i<av.length; i++)
				try {
					c.process(new FileInputStream(av[i]));
				} catch (FileNotFoundException e) {
					System.err.println(e);
				}
		}
	
public voidprocess(java.io.InputStream ois)
print one file, given an open InputStream

		BufferedInputStream is = new BufferedInputStream(ois);
		num.setLength(0);
		txt.setLength(0);
		
		try {
			int b = 0;
			int column = 0;

			while ((b=is.read()) != -1) {
				num.append(b);
				num.append(' ");
				txt.append(Character.isLetterOrDigit((char)b) ? (char)b : '.");

				if (++column%PERLINE == 0) {
					dump();
				}
			}
			System.out.print("\n");
			is.close();
		} catch (IOException e) {
			System.out.println("IOException: " + e);
		}