Package org.stringtemplate.v4
Interface STWriter
- All Known Implementing Classes:
AutoIndentWriter
,NoIndentWriter
public interface STWriter
Generic StringTemplate output writer filter.
Literals and the elements of expressions are emitted via write(String)
.
Separators are emitted via writeSeparator(String)
because they must be
handled specially when wrapping lines (we don't want to wrap
in between an element and it's separator).
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionint
index()
Return the absolute char index into the output of the char we're about to write.void
void
void
pushIndentation
(String indent) void
setLineWidth
(int lineWidth) int
Write the string and return how many actual characters were written.int
Same as write, but wrap lines using the indicated string as the wrap character (such as"\n"
).int
writeSeparator
(String str) Write a separator.int
Because we evaluate ST instance by invokingInterpreter.exec(STWriter, InstanceScope)
again, we can't pass options in.
-
Field Details
-
NO_WRAP
static final int NO_WRAP- See Also:
-
-
Method Details
-
pushIndentation
-
popIndentation
String popIndentation() -
pushAnchorPoint
void pushAnchorPoint() -
popAnchorPoint
void popAnchorPoint() -
setLineWidth
void setLineWidth(int lineWidth) -
write
Write the string and return how many actual characters were written. With auto-indentation and wrapping, more chars thanstr.length()
can be emitted. No wrapping is done.- Throws:
IOException
-
write
Same as write, but wrap lines using the indicated string as the wrap character (such as"\n"
).- Throws:
IOException
-
writeWrap
Because we evaluate ST instance by invokingInterpreter.exec(STWriter, InstanceScope)
again, we can't pass options in. So theBytecode.INSTR_WRITE
instruction of an applied template (such as when we wrap in between template applications like<data:{v|[<v>]}; wrap>
) we need to write thewrap
string before callingInterpreter.exec(org.stringtemplate.v4.STWriter, org.stringtemplate.v4.InstanceScope)
. We expose just like for the separator. SeeInterpreter.writeObject(org.stringtemplate.v4.STWriter, org.stringtemplate.v4.InstanceScope, java.lang.Object, java.lang.String[])
where it checks for ST instance. If POJO,Interpreter.writePOJO(org.stringtemplate.v4.STWriter, org.stringtemplate.v4.InstanceScope, java.lang.Object, java.lang.String[])
passeswrap
towrite(String str, String wrap)
. Can't pass toInterpreter.exec(org.stringtemplate.v4.STWriter, org.stringtemplate.v4.InstanceScope)
.- Throws:
IOException
-
writeSeparator
Write a separator. Same aswrite(String)
except that a"\n"
cannot be inserted before emitting a separator.- Throws:
IOException
-
index
int index()Return the absolute char index into the output of the char we're about to write. Returns 0 if no char written yet.
-