Top Description Fields Methods
org.stringtemplate.v4

public Interface STWriter

Known Direct Implementers
org.stringtemplate.v4.AutoIndentWriter
Imports
org.stringtemplate.v4.compiler.Bytecode, java.io.IOException

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

Modifier and TypeField and Description
public static final int

Method Summary

Modifier and TypeMethod and Description
public int
index()

Return the absolute char index into the output of the char we're about to write.

public void
public String
public void
public void
public void
setLineWidth(int lineWidth)

public int
write(String str)

Write the string and return how many actual characters were written.

public int
write(String str, String wrap)

Same as write, but wrap lines using the indicated string as the wrap character (such as "\n").

public int
writeSeparator(String str)

Write a separator.

public int
writeWrap(String wrap)

Because we evaluate ST instance by invoking Interpreter#exec(STWriter, InstanceScope) again, we can't pass options in. So the Bytecode#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 the wrap string before calling Interpreter#exec.

Field Detail

NO_WRAPback to summary
public static final int NO_WRAP

Method Detail

indexback to summary
public 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.

popAnchorPointback to summary
public void popAnchorPoint()
popIndentationback to summary
public String popIndentation()
pushAnchorPointback to summary
public void pushAnchorPoint()
pushIndentationback to summary
public void pushIndentation(String indent)
setLineWidthback to summary
public void setLineWidth(int lineWidth)
writeback to summary
public int write(String str) throws IOException

Write the string and return how many actual characters were written. With auto-indentation and wrapping, more chars than str.length() can be emitted. No wrapping is done.

writeback to summary
public int write(String str, String wrap) throws IOException

Same as write, but wrap lines using the indicated string as the wrap character (such as "\n").

writeSeparatorback to summary
public int writeSeparator(String str) throws IOException

Write a separator. Same as write(String) except that a "\n" cannot be inserted before emitting a separator.

writeWrapback to summary
public int writeWrap(String wrap) throws IOException

Because we evaluate ST instance by invoking Interpreter#exec(STWriter, InstanceScope) again, we can't pass options in. So the Bytecode#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 the wrap string before calling Interpreter#exec. We expose just like for the separator. See Interpreter#writeObject where it checks for ST instance. If POJO, Interpreter#writePOJO passes wrap to STWriter#write(String str, String wrap). Can't pass to Interpreter#exec.