Class IndentingWriter
java.lang.Object
java.io.Writer
nl.talsmasoftware.umldoclet.rendering.indent.IndentingWriter
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
Writer implementation that will indent each new line with a specified number of whitespace
characters (four by default).
The writing itself can be delegated to any other
Writer
implementation.- Author:
- Sjoerd Talsma
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
IndentingWriter(Appendable delegate, Indentation indentation)
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
flush()
protected Indentation
indent()
toString()
unindent()
Makes sure there is at least one whitespace character between the last charater and the next.withIndentation(Indentation newIndentation)
Returns an indenting writer with the new indentation.static IndentingWriter
wrap(Appendable delegate, Indentation indentation)
Returns an indenting writer around the givendelegate
.
If thedelegate
writer is already an indenting writer, it will simply be returnedwith the specified indentation
.
If thedelegate
writer is not yet an indending writer, a new indenting writer class will be created to wrap the delegate using the specifiedindentation
.void
write(char[] cbuf, int off, int len)
-
Constructor Details
-
IndentingWriter
-
-
Method Details
-
wrap
Returns an indenting writer around the givendelegate
.
If thedelegate
writer is already an indenting writer, it will simply be returnedwith the specified indentation
.
If thedelegate
writer is not yet an indending writer, a new indenting writer class will be created to wrap the delegate using the specifiedindentation
.- Parameters:
delegate
- The delegate to turn into an indenting writer.indentation
- The indentation to use for the indenting writer (optional, specifynull
to use the default indentation).- Returns:
- The indenting delegate writer.
- See Also:
Indentation.DEFAULT
-
withIndentation
Returns an indenting writer with the new indentation.Please note: Already written lines will not be modified to accomodate the new indentation.
- Parameters:
newIndentation
- The new indentation to apply to this writer (optional).- Returns:
- Either this writer if the indentation is already correct, or a new IndentingWriter with the adapted indentation.
-
getIndentation
-
indent
-
unindent
-
whitespace
Makes sure there is at least one whitespace character between the last charater and the next.This method attempts to avoid appending a whitespace character if it knows the last character was in fact a whitespace character. The whitespace character will also not be written until there are other characters that need to be written.
- Returns:
- Reference to this writer for chaining purposes.
-
write
- Specified by:
write
in classWriter
- Throws:
IOException
-
flush
- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in classWriter
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classWriter
- Throws:
IOException
-
toString
-