Package org.glassfish.rmic
Class IndentingWriter
- java.lang.Object
-
- java.io.Writer
-
- java.io.BufferedWriter
-
- org.glassfish.rmic.IndentingWriter
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.Appendable,java.lang.AutoCloseable
public class IndentingWriter extends java.io.BufferedWriterIndentingWriter 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. WARNING: The contents of this source file are not part of any supported API. Code that depends on them does so at its own risk: they are subject to change or removal without notice.
-
-
Field Summary
Fields Modifier and Type Field Description private booleanbeginningOfLinetrue if the next character written is the first on a lineprivate intcurrentIndentcurrent number of spaces to prepend to linesprivate intindentStepnumber of spaces to change indent when indenting in or outprivate inttabSizenumber of spaces to convert into tabs.
-
Constructor Summary
Constructors Constructor Description IndentingWriter(java.io.Writer out)Create a new IndentingWriter that writes indented text to the given Writer.IndentingWriter(java.io.Writer out, int step)Create a new IndentingWriter that writes indented text to the given Writer and uses the supplied indent step.IndentingWriter(java.io.Writer out, int step, int tabSize)Create a new IndentingWriter that writes indented text to the given Writer and uses the supplied indent step and tab size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckWrite()Check if an indent needs to be written before writing the next character.protected voidindentIn()Increase the current indent by the indent step.protected voidindentOut()Decrease the current indent by the indent step.voidnewLine()Write a line separator.voidp(java.lang.Object o)Write Object.voidp(java.lang.String s)Write string.voidpI()Indent in.voidpln()End current line.voidpln(java.lang.Object o)Write Object; end current line.voidpln(java.lang.String s)Write string; end current line.voidplnI(java.lang.Object o)Write Object; end current line; indent in.voidplnI(java.lang.String s)Write string; end current line; indent in.voidpO()Indent out.voidpO(java.lang.Object o)Indent out; write Object.voidpO(java.lang.String s)Indent out; write string.voidpOln(java.lang.Object o)Indent out; write Object; end current line.voidpOln(java.lang.String s)Indent out; write string; end current line.voidpOlnI(java.lang.Object o)Indent out; write Object; end current line; indent in.voidpOlnI(java.lang.String s)Indent out; write string; end current line; indent in.voidwrite(char[] cbuf, int off, int len)Write a portion of an array of characters.voidwrite(int c)Write a single character.voidwrite(java.lang.String s, int off, int len)Write a portion of a String.
-
-
-
Field Detail
-
beginningOfLine
private boolean beginningOfLine
true if the next character written is the first on a line
-
currentIndent
private int currentIndent
current number of spaces to prepend to lines
-
indentStep
private int indentStep
number of spaces to change indent when indenting in or out
-
tabSize
private int tabSize
number of spaces to convert into tabs. Use MAX_VALUE to disable
-
-
Constructor Detail
-
IndentingWriter
public IndentingWriter(java.io.Writer out)
Create a new IndentingWriter that writes indented text to the given Writer. Use the default indent step of four spaces.
-
IndentingWriter
public IndentingWriter(java.io.Writer out, int step)Create a new IndentingWriter that writes indented text to the given Writer and uses the supplied indent step.
-
IndentingWriter
public IndentingWriter(java.io.Writer out, int step, int tabSize)Create a new IndentingWriter that writes indented text to the given Writer and uses the supplied indent step and tab size.
-
-
Method Detail
-
write
public void write(int c) throws java.io.IOExceptionWrite a single character.- Overrides:
writein classjava.io.BufferedWriter- Throws:
java.io.IOException
-
write
public void write(char[] cbuf, int off, int len) throws java.io.IOExceptionWrite a portion of an array of characters.- Overrides:
writein classjava.io.BufferedWriter- Throws:
java.io.IOException
-
write
public void write(java.lang.String s, int off, int len) throws java.io.IOExceptionWrite a portion of a String.- Overrides:
writein classjava.io.BufferedWriter- Throws:
java.io.IOException
-
newLine
public void newLine() throws java.io.IOExceptionWrite a line separator. The next character written will be preceded by an indent.- Overrides:
newLinein classjava.io.BufferedWriter- Throws:
java.io.IOException
-
checkWrite
protected void checkWrite() throws java.io.IOExceptionCheck 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:
java.io.IOException
-
indentIn
protected void indentIn()
Increase the current indent by the indent step.
-
indentOut
protected void indentOut()
Decrease the current indent by the indent step.
-
pI
public void pI()
Indent in.
-
pO
public void pO()
Indent out.
-
p
public void p(java.lang.String s) throws java.io.IOExceptionWrite string.- Throws:
java.io.IOException
-
pln
public void pln() throws java.io.IOExceptionEnd current line.- Throws:
java.io.IOException
-
pln
public void pln(java.lang.String s) throws java.io.IOExceptionWrite string; end current line.- Throws:
java.io.IOException
-
plnI
public void plnI(java.lang.String s) throws java.io.IOExceptionWrite string; end current line; indent in.- Throws:
java.io.IOException
-
pO
public void pO(java.lang.String s) throws java.io.IOExceptionIndent out; write string.- Throws:
java.io.IOException
-
pOln
public void pOln(java.lang.String s) throws java.io.IOExceptionIndent out; write string; end current line.- Throws:
java.io.IOException
-
pOlnI
public void pOlnI(java.lang.String s) throws java.io.IOExceptionIndent 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 {".- Throws:
java.io.IOException
-
p
public void p(java.lang.Object o) throws java.io.IOExceptionWrite Object.- Throws:
java.io.IOException
-
pln
public void pln(java.lang.Object o) throws java.io.IOExceptionWrite Object; end current line.- Throws:
java.io.IOException
-
plnI
public void plnI(java.lang.Object o) throws java.io.IOExceptionWrite Object; end current line; indent in.- Throws:
java.io.IOException
-
pO
public void pO(java.lang.Object o) throws java.io.IOExceptionIndent out; write Object.- Throws:
java.io.IOException
-
pOln
public void pOln(java.lang.Object o) throws java.io.IOExceptionIndent out; write Object; end current line.- Throws:
java.io.IOException
-
pOlnI
public void pOlnI(java.lang.Object o) throws java.io.IOExceptionIndent out; write Object; end current line; indent in. This method is useful for generating lines of code that both end and begin nested blocks, like "} else {".- Throws:
java.io.IOException
-
-