FileDocCategorySizeDatePackage
DropReceivedLines.javaAPI DocExample2024Tue Mar 13 15:32:30 GMT 2001None

DropReceivedLines

public class DropReceivedLines extends Object
Read a file and print, using LineReader and System.out

Fields Summary
protected static File
tempFile
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] av)

        DropReceivedLines d = new DropReceivedLines();
		// For stdin, act as a filter. For named files,
		// update each file in place (safely, by creating a new file).
		try {
			if (av.length == 0) 
				d.process(new BufferedReader(
						new InputStreamReader(System.in)), 
						new PrintWriter(System.out));
			else for (int i=0; i<av.length; i++)
				d.process(av[i]);
		} catch (FileNotFoundException e) {
			System.err.println(e.getMessage());
		} catch (IOException e) {
			System.err.println("I/O error " + e);
		}
    
public voidprocess(java.lang.String fileName)
Process one file given only its name


	        
	      
		File old = new File(fileName);
		String newFileName = fileName + ".TMP";
		File newf = new File(newFileName);
		BufferedReader is =
				new BufferedReader(new FileReader(fileName));
		PrintWriter p = new PrintWriter(new FileWriter(newFileName));
		process(is, p);		// call other process(), below
		p.close();
		old.renameTo(tempFile);
		newf.renameTo(old);
		tempFile.delete();
	
public voidprocess(java.io.BufferedReader is, java.io.PrintWriter out)
process one file, given an open LineReader

        try {
            String lin;

			// If line begins with "Received:", ditch it, and its continuations
            while ((lin = is.readLine()) != null) {
				Debug.println("read", "Read line " + lin);
				if (lin.startsWith("Received:")) {
					do {
						lin = is.readLine();
						Debug.println("read", "\tContin read line " + lin);
					} while (lin.length() > 0 &&
						Character.isWhitespace(lin.charAt(0)));
				}
				out.println(lin);
            }
            is.close();
			out.close();
        } catch (IOException e) {
            System.out.println("IOException: " + e);
        }