FileDocCategorySizeDatePackage
IndentingWriter.javaAPI DocphoneME MR2 API (J2ME)6504Wed May 02 18:00:40 BST 2007com.sun.satsa.jcrmic.utils

IndentingWriter

public class IndentingWriter extends BufferedWriter
IndentingWriter is a BufferedWriter subclass that supports automatic indentation of lines of text written to the underlying Writer. Methods are provided for compact, convenient indenting, writing text, and writing lines in various combinations.

Fields Summary
private boolean
beginningOfLine
true if the next character written is the first on a line
private int
currentIndent
current number of spaces to prepend to lines
private int
indentStep
number of spaces to change indent when indenting in or out
Constructors Summary
public IndentingWriter(Writer out)
Create a new IndentingWriter that writes indented text to the given Writer. Use the default indent step of four spaces.

param
out output stream


                                  
       
        super(out);
    
public IndentingWriter(Writer out, int step)
Create a new IndentingWriter that writes indented text to the given Writer and uses the supplied indent step.

param
out output stream
param
step indent step

        this(out);

        if (indentStep < 0)
            throw new IllegalArgumentException("negative indent step");

        indentStep = step;
    
Methods Summary
protected voidcheckWrite()
Check if an indent needs to be written before writing the next character. The indent generation is optimized (and made consistent with certain coding conventions) by condensing groups of eight spaces into tab characters.

throws
IOException if I/O exception occurs

        if (beginningOfLine) {
            beginningOfLine = false;
            int i = currentIndent;
            while (i >= 8) {
                super.write('\t");
                i -= 8;
            }
            while (i > 0) {
                super.write(' ");
                --i;
            }
        }
    
protected voidindentIn()
Increase the current indent by the indent step.

        currentIndent += indentStep;
    
protected voidindentOut()
Decrease the current indent by the indent step.

        currentIndent -= indentStep;
        if (currentIndent < 0)
            currentIndent = 0;
    
public voidnewLine()
Write a line separator. The next character written will be preceded by an indent.

throws
IOException if I/O exception occurs

        super.newLine();
        beginningOfLine = true;
    
public voidp(java.lang.String s)
Write string.

param
s the string
throws
IOException if I/O exception occurs

        write(s);
    
public voidpI()
Indent in.

        indentIn();
    
public voidpO()
Indent out.

        indentOut();
    
public voidpO(java.lang.String s)
Indent out; write string.

param
s the string
throws
IOException if I/O exception occurs

        pO();
        p(s);
    
public voidpOln(java.lang.String s)
Indent out; write string; end current line.

param
s the string
throws
IOException if I/O exception occurs

        pO(s);
        pln();
    
public voidpOlnI(java.lang.String s)
Indent out; write string; end current line; indent in. This method is useful for generating lines of code that both end and begin nested blocks, like "} else {".

param
s the string
throws
IOException if I/O exception occurs

        pO(s);
        pln();
        pI();
    
public voidpln()
End current line.

throws
IOException if I/O exception occurs

        newLine();
    
public voidpln(java.lang.String s)
Write string; end current line.

param
s the string
throws
IOException if I/O exception occurs

        p(s);
        pln();
    
public voidplnI(java.lang.String s)
Write string; end current line; indent in.

param
s the string
throws
IOException if I/O exception occurs

        p(s);
        pln();
        pI();
    
public voidwrite(int c)
Write a single character.

param
c the character
throws
IOException if I/O exception occurs

        checkWrite();
        super.write(c);
    
public voidwrite(char[] cbuf, int off, int len)
Write a portion of an array of characters.

param
cbuf buffer
param
off offset
param
len length
throws
IOException if I/O exception occurs

        if (len > 0) {
            checkWrite();
        }
        super.write(cbuf, off, len);
    
public voidwrite(java.lang.String s, int off, int len)
Write a portion of a String.

param
s the string
param
off offset
param
len length
throws
IOException if I/O exception occurs

        if (len > 0) {
            checkWrite();
        }
        super.write(s, off, len);