Class AutoIndentWriter
java.lang.Object
java.io.Writer
java.io.FilterWriter
org.codehaus.janino.util.AutoIndentWriter
- All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable
A
FilterWriter that indents lines by processing some control characters in the character stream.
INDENT or UNINDENT may precede lines and indicate that the line and all following lines should
be (un)indented by one position.
TABULATORs may appear anywhere in lines and dictate that portions of all following lines should be
vertically aligned (see resolveTabs(List)).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final charSpecial character at the beginning of a line that flushes a tabular layout.static final charSpecial character at the beginning of a line that indents the following text by one position.private intprivate final StringBuilderBuffer for the "current line", including the trailing line break (CR, LF or CRLF).static final charSpecial character indicating a tabular layout of all following lines untilUNINDENT.private List<StringBuilder> Iff non-null, then we are in "tab mode".private intTheindentationwhen tab mode started.static final charSpecial character at the beginning of a line that unindents the following text by one position.Fields inherited from class FilterWriter
out -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidflush()private voidprivate voidprivate static voidresolveTabs(List<StringBuilder> lineGroup) Expands allTABULATORs in the givenListofStringBuilders with spaces, so that the characters immediately following theTABULATORs are vertically aligned, like this:private static Stringspaces(int n) voidwrite(char[] cbuf, int off, int len) voidwrite(int c) void
-
Field Details
-
TABULATOR
public static final char TABULATORSpecial character indicating a tabular layout of all following lines untilUNINDENT.- See Also:
-
CLEAR_TABULATORS
public static final char CLEAR_TABULATORSSpecial character at the beginning of a line that flushes a tabular layout.- See Also:
-
INDENT
public static final char INDENTSpecial character at the beginning of a line that indents the following text by one position.- See Also:
-
UNINDENT
public static final char UNINDENTSpecial character at the beginning of a line that unindents the following text by one position.- See Also:
-
lineBuffer
Buffer for the "current line", including the trailing line break (CR, LF or CRLF). -
indentation
-
tabulatorBuffer
Iff non-null, then we are in "tab mode". While in tab mode, lines are not printed immediately, but stored in this buffer. Tab mode starts when a line contains aTABULATOR. Tab mode ends when output is unindented beyond the level when tab mode started, or when this writer is closed.When tab mode ends, all buffered lines are vertically aligned at the
TABULATORs and printed. -
tabulatorIndentation
private int tabulatorIndentationTheindentationwhen tab mode started.
-
-
Constructor Details
-
AutoIndentWriter
-
-
Method Details
-
write
- Overrides:
writein classFilterWriter- Throws:
IOException
-
write
- Overrides:
writein classFilterWriter- Throws:
IOException
-
write
- Overrides:
writein classFilterWriter- Throws:
IOException
-
line
- Throws:
IOException
-
flushTabulatorBuffer
- Throws:
IOException
-
resolveTabs
Expands allTABULATORs in the givenListofStringBuilders with spaces, so that the characters immediately following theTABULATORs are vertically aligned, like this:Input:
a @b @c\r\n aa @bb @cc\r\n aaa @bbb @ccc\r\n
Output:
a b c\r\n aa bb cc\r\n aaa bbb ccc\r\n
-
spaces
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classFilterWriter- Throws:
IOException
-
flush
- Specified by:
flushin interfaceFlushable- Overrides:
flushin classFilterWriter- Throws:
IOException
-