public static class OutTextPreparer.WriteDst
extends java.lang.Object
implements java.lang.Appendable
Appendable
, as the output,
then the field sb
is also set. It is only a second link, not immediately used for OutText preparation.
It allows more possibilities to deal with the generated text, for example insert a text on a definite position,
which is generated afterwards (for example local variable definition generated on usage of the variable,
but necessary as definition before. But this is outside of OutText preparation.
The operation #add(WriteDst)
allows adding a generated text to the current output,
the source to add needs the StringBuilder output.
append(CharSequence)
operations looks for '\n' inside the output text.
Any found new line character increments the lineCt()
.
The lineCt()
can be used to output the line number.
#OutTextPreparer(Appendable, int, int)
is used, an extra StringBuilder is created.
then all append(CharSequence)
operations appends only to wr
,
buf if finishAppend()
is called, it writes out the content to wrDst
,
but prevents the content in the sb
. So it can be visited both in the file (after flush)
and also in the sb
.
And then the next any append(CharSequence)
cleans first the sb
for further operation.
The flag bSbClean
controls the behavior.
Modifier and Type | Field and Description |
---|---|
private boolean |
bSbClean
If true, then the next any
append(char) cleans first the wr as StringBuilder
and sets this flag to false. |
private int |
lineCt
Counts the '\n' inside appended texts.
|
private int |
lineStart |
java.lang.StringBuilder |
sb
This is set if the Appendable on construction, the last used output, is a
StringBuilder . |
private java.lang.Appendable |
wr
This is always the destination for all
append(char) , append(CharSequence) , append(int) ,
append(CharSequence, int, int) and #add(WriteDst) . |
private java.lang.Appendable |
wrDst
The primary output if
#OutTextPreparer(Appendable, int, int) is called, else null. |
Constructor and Description |
---|
WriteDst(java.lang.Appendable wr,
int lineStart)
Constructs a new output destination to write the generated text.
|
WriteDst(java.lang.Appendable wrDst,
int lineStart,
int sizeStringBuilder)
Constructs a new output destination to write the generated text using a temporary used StringBuilder
for any
OutTextPreparer.exec(Appendable, DataTextPreparer) . |
Modifier and Type | Method and Description |
---|---|
void |
add(OutTextPreparer.WriteDst other)
This operation can be used if a part of the output text is generated meanwhile with another WriteDst instance
and should be added now.
|
OutTextPreparer.WriteDst |
append(char c)
Standard append operation see
Appendable.append(char) |
OutTextPreparer.WriteDst |
append(java.lang.CharSequence csq)
Standard append operation see
Appendable.append(CharSequence) |
OutTextPreparer.WriteDst |
append(java.lang.CharSequence csq,
int start,
int end)
Standard append operation see
Appendable.append(CharSequence, int, int) |
OutTextPreparer.WriteDst |
append(int val)
Append operation similar as in
StringBuilder.append(int) |
void |
close()
|
void |
finishAppend()
Finishes one append phase.
|
int |
lineCt() |
void |
setLineCt(int lineCt) |
java.lang.String |
toString()
This should be used only for debug view.
|
private final java.lang.Appendable wrDst
#OutTextPreparer(Appendable, int, int)
is called, else null.
It can be a StringBuilder, then also sb
is set with the same instance reference.
Or it can be any other Appendable
, especially Writer
for file output.private final java.lang.Appendable wr
append(char)
, append(CharSequence)
, append(int)
,
append(CharSequence, int, int)
and #add(WriteDst)
.
It is either a StringBuilder if #OutTextPreparer(Appendable, int, int)
is called,
or it is any other Appendable.public final java.lang.StringBuilder sb
StringBuilder
.
It allows more access possibilities for the user to change the generated text.
If the output Appendable is not a StringBulder this field remains null.
The user can use it immediately if the calling environment of the ctor delivers a StringBuilder
as Appendable
.
But note that changing content of this field does not effect the lineCt()
.
If the StringBuilder sb is changed, it is similar as the generated output text is changed afterwards,
independent of the functionality of the OutTextPreparer
and in full responsibility to the user.private int lineCt
private final int lineStart
private boolean bSbClean
append(char)
cleans first the wr
as StringBuilder
and sets this flag to false.
This flag is set to true after finishAppend()
, after the content is written to wrDst
.
close()
also call finishAppend()
to write out content.
If this flag is true, the wr
contains the last written contentpublic WriteDst(java.lang.Appendable wr, int lineStart)
wr
- may be also an instance of StringBuilder
, then sb
is set also.lineStart
- number of this first line. It is important for immediately instances.
The lineCt starts from 1 for the first line.public WriteDst(java.lang.Appendable wrDst, int lineStart, int sizeStringBuilder)
OutTextPreparer.exec(Appendable, DataTextPreparer)
.wrDst
- may be also an instance of StringBuilder
, then sb
is set also.lineStart
- number of this first line. It is important for immediately instances.
The lineCt starts from 1 for the first line.public void setLineCt(int lineCt)
public int lineCt()
public void finishAppend() throws java.io.IOException
#OutTextPreparer(Appendable, int, int)
and hence wr
is a StringBuilder: Writes out the content of wr
to wrDst
but prevent the content in wr
(it is a StringBuilder) for debug view, else do nothing.
Sets bSbClean
which forces clean sb
on the next any append(char)
.
This operation is also called on close()
.java.io.IOException
public void add(OutTextPreparer.WriteDst other) throws java.io.IOException
lineCt()
is also incremented by the 'other.lineCt'.other
- The sb
must be set, else assertion and exception.
It means 'other' should be created (ctor) using a StringBuilder as Appendable.java.io.IOException
public OutTextPreparer.WriteDst append(int val) throws java.io.IOException
StringBuilder.append(int)
val
- java.io.IOException
public OutTextPreparer.WriteDst append(java.lang.CharSequence csq) throws java.io.IOException
Appendable.append(CharSequence)
append
in interface java.lang.Appendable
java.io.IOException
public OutTextPreparer.WriteDst append(java.lang.CharSequence csq, int start, int end) throws java.io.IOException
Appendable.append(CharSequence, int, int)
append
in interface java.lang.Appendable
java.io.IOException
public OutTextPreparer.WriteDst append(char c) throws java.io.IOException
Appendable.append(char)
append
in interface java.lang.Appendable
java.io.IOException
public void close() throws java.io.IOException
java.io.IOException