FileDocCategorySizeDatePackage
Fmt.javaAPI DocExample1538Sat Nov 25 12:56:14 GMT 2000None

Fmt

public class Fmt extends Object
Fmt - format text (like Berkeley UNIX fmt).

Fields Summary
public static final int
COLWIDTH
The maximum column width
BufferedReader
in
The file that we read and format
Constructors Summary
public Fmt(String fname)
Construct a Formatter given a filename

		in = new BufferedReader(new FileReader(fname));
	
public Fmt(InputStream file)
Construct a Formatter given an open Stream

		in = new BufferedReader(new InputStreamReader(file));
	
Methods Summary
public voidformat()
Format the File contained in a constructed Fmt object

		String w, f;
		int col = 0;
		while ((w = in.readLine()) != null) {
			if (w.length() == 0) {	// null line
				System.out.print("\n");		// end current line
				if (col>0) {
					System.out.print("\n");	// output blank line
					col = 0;
				}
				continue;
			}

			// otherwise it's text, so format it.
			StringTokenizer st = new StringTokenizer(w);
			while (st.hasMoreTokens()) {
				f = st.nextToken();

				if (col + f.length() > COLWIDTH) {
					System.out.print("\n");
					col = 0;
				}
				System.out.print(f + " ");
				col += f.length() + 1;
			}
		}
		if (col>0) System.out.print("\n");
		in.close();
	
public static voidmain(java.lang.String[] av)
If files present, format each, else format the standard input.


	           
	       
		if (av.length == 0)
			new Fmt(System.in).format();
		else for (int i=0; i<av.length; i++)
			new Fmt(av[i]).format();