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
ConstructorsModifierConstructorDescriptionprotectedIndentingWriter(Appendable delegate, Indentation indentation) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidflush()protected Indentationindent()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 IndentingWriterwrap(Appendable delegate, Indentation indentation) Returns an indenting writer around the givendelegate.
If thedelegatewriter is already an indenting writer, it will simply be returnedwith the specified indentation.
If thedelegatewriter is not yet an indending writer, a new indenting writer class will be created to wrap the delegate using the specifiedindentation.voidwrite(char[] cbuf, int off, int len)
-
Constructor Details
-
IndentingWriter
-
-
Method Details
-
wrap
Returns an indenting writer around the givendelegate.
If thedelegatewriter is already an indenting writer, it will simply be returnedwith the specified indentation.
If thedelegatewriter 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, specifynullto use the default indentation).- Returns:
- The indenting delegate writer.
- See Also:
-
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:
writein classWriter- Throws:
IOException
-
flush
- Specified by:
flushin interfaceFlushable- Specified by:
flushin classWriter- Throws:
IOException
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException
-
toString
-