FileDocCategorySizeDatePackage
Pager.javaAPI DocGlassfish v2 API3956Fri May 04 22:25:22 BST 2007com.sun.enterprise.cli.framework

Pager

public class Pager extends Object
Pager.java
author
Toby H Ferguson
version
$Revision: 1.4 $

Fields Summary
private BufferedReader
in
private BufferedWriter
out
private int
pageLength
private String
line
Constructors Summary
Pager(int lines, Reader in, Writer out)
Construct an object which will copy one pages worth of lines at a time from the input to the the output. No attempt is made under any circumstances to close the input or output.

param
lines the number of lines in a page. A number less than 0 means copy all the input to the output.
param
in the source of the copy operation
param
out the destination of the copy operation
throws
IOException if there's a problem reading from, or writing to, the source or destination

        this.in = new BufferedReader(in);
        this.out = new BufferedWriter(out);
        pageLength = lines;
        nextLine();
    
Methods Summary
booleanhasNext()
Indicate if there are lines left to be copied

return
true iff there is at least one line left to be copied

        return line != null;
    
private voidnextLine()
Get the next line and copy it inot the internal buffer so's we can answer the hasNext() question

        line = in.readLine();
    
voidnextPage()
Copy the next page worth of lines from input to output

        for (int i = 0; (pageLength < 0 || i < pageLength) && hasNext(); i++){
            out.write(line);
            out.newLine();
            nextLine();
        }
        out.flush();