Package org.glassfish.rmic
Class IndentingWriter
java.lang.Object
java.io.Writer
java.io.BufferedWriter
org.glassfish.rmic.IndentingWriter
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
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.
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
FieldsModifier and TypeFieldDescriptionprivate boolean
true if the next character written is the first on a lineprivate int
current number of spaces to prepend to linesprivate int
number of spaces to change indent when indenting in or outprivate int
number of spaces to convert into tabs. -
Constructor Summary
ConstructorsConstructorDescriptionIndentingWriter
(Writer out) Create a new IndentingWriter that writes indented text to the given Writer.IndentingWriter
(Writer out, int step) Create a new IndentingWriter that writes indented text to the given Writer and uses the supplied indent step.IndentingWriter
(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
Modifier and TypeMethodDescriptionprotected void
Check if an indent needs to be written before writing the next character.protected void
indentIn()
Increase the current indent by the indent step.protected void
Decrease the current indent by the indent step.void
newLine()
Write a line separator.void
Write Object.void
Write string.void
pI()
Indent in.void
pln()
End current line.void
Write Object; end current line.void
Write string; end current line.void
Write Object; end current line; indent in.void
Write string; end current line; indent in.void
pO()
Indent out.void
Indent out; write Object.void
Indent out; write string.void
Indent out; write Object; end current line.void
Indent out; write string; end current line.void
Indent out; write Object; end current line; indent in.void
Indent out; write string; end current line; indent in.void
write
(char[] cbuf, int off, int len) Write a portion of an array of characters.void
write
(int c) Write a single character.void
Write a portion of a String.Methods inherited from class java.io.BufferedWriter
close, flush
-
Field Details
-
beginningOfLine
private boolean beginningOfLinetrue if the next character written is the first on a line -
currentIndent
private int currentIndentcurrent number of spaces to prepend to lines -
indentStep
private int indentStepnumber of spaces to change indent when indenting in or out -
tabSize
private int tabSizenumber of spaces to convert into tabs. Use MAX_VALUE to disable
-
-
Constructor Details
-
IndentingWriter
Create a new IndentingWriter that writes indented text to the given Writer. Use the default indent step of four spaces. -
IndentingWriter
Create a new IndentingWriter that writes indented text to the given Writer and uses the supplied indent step. -
IndentingWriter
Create a new IndentingWriter that writes indented text to the given Writer and uses the supplied indent step and tab size.
-
-
Method Details
-
write
Write a single character.- Overrides:
write
in classBufferedWriter
- Throws:
IOException
-
write
Write a portion of an array of characters.- Overrides:
write
in classBufferedWriter
- Throws:
IOException
-
write
Write a portion of a String.- Overrides:
write
in classBufferedWriter
- Throws:
IOException
-
newLine
Write a line separator. The next character written will be preceded by an indent.- Overrides:
newLine
in classBufferedWriter
- Throws:
IOException
-
checkWrite
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
-
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
Write string.- Throws:
IOException
-
pln
End current line.- Throws:
IOException
-
pln
Write string; end current line.- Throws:
IOException
-
plnI
Write string; end current line; indent in.- Throws:
IOException
-
pO
Indent out; write string.- Throws:
IOException
-
pOln
Indent out; write string; end current line.- Throws:
IOException
-
pOlnI
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 {".- Throws:
IOException
-
p
Write Object.- Throws:
IOException
-
pln
Write Object; end current line.- Throws:
IOException
-
plnI
Write Object; end current line; indent in.- Throws:
IOException
-
pO
Indent out; write Object.- Throws:
IOException
-
pOln
Indent out; write Object; end current line.- Throws:
IOException
-
pOlnI
Indent 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:
IOException
-