public class SerializerWriter extends Writer
Writer
with additional methods.
Modeled after the Java ProcessBuilder class so that you can chain commands to reduce the need for string concatenation for performance reasons.
writer.append(
Modifier and Type | Field and Description |
---|---|
protected int |
maxIndent
Max indentation levels.
|
protected Writer |
out
The underlying writer.
|
protected char |
quoteChar
The quote character being used by this writer.
|
protected boolean |
trimStrings
Trim strings flag.
|
protected UriResolver |
uriResolver
The URI resolver of the request.
|
protected boolean |
useWhitespace
Use-whitespace flag.
|
Constructor and Description |
---|
SerializerWriter(Writer out,
boolean useWhitespace,
int maxIndent,
boolean trimStrings,
char quoteChar,
UriResolver uriResolver) |
Modifier and Type | Method and Description |
---|---|
SerializerWriter |
append(char c) |
SerializerWriter |
append(char[] characters)
Appends the specified characters to this writer.
|
SerializerWriter |
append(int indent,
char c)
Writes an indent (if the
useWhitespace setting is enabled), followed by text. |
SerializerWriter |
append(int indent,
String text)
Writes an indent (if the
useWhitespace setting is enabled), followed by text. |
SerializerWriter |
append(Object text)
Writes the specified text to the writer.
|
SerializerWriter |
append(String text)
Writes the specified text to the writer.
|
SerializerWriter |
appendIf(boolean b,
char c)
Writes the specified text to the writer if b is true.
|
SerializerWriter |
appendIf(boolean b,
String text)
Writes the specified text to the writer if b is true.
|
SerializerWriter |
appendln(int indent,
String text)
Writes an indent (if the
useWhitespace setting is enabled), followed by text, followed by a newline
(if the useWhitespace setting is enabled). |
SerializerWriter |
appendln(String text)
Writes the specified text followed by a newline (if the
useWhitespace setting is enabled). |
SerializerWriter |
appendUri(Object uri)
Appends the specified object as a URI.
|
void |
close() |
SerializerWriter |
cr(int depth)
Performs a carriage return.
|
SerializerWriter |
cre(int depth)
Performs a carriage return at the end of a line.
|
void |
flush() |
SerializerWriter |
i(int indent)
Writes an indent to the writer if the
useWhitespace setting is enabled. |
SerializerWriter |
ie(int indent)
Writes an end-of-line indent to the writer if the
useWhitespace setting is enabled. |
SerializerWriter |
nl(int indent)
Writes a newline to the writer if the
useWhitespace setting is enabled. |
SerializerWriter |
nlIf(boolean b,
int indent)
Writes a newline to the writer if the
useWhitespace setting is enabled and the boolean flag is true. |
SerializerWriter |
q()
Adds the quote character specified by the
quoteChar setting to the output. |
SerializerWriter |
s()
Adds a whitespace character to the output if the
useWhitespace setting is enabled. |
SerializerWriter |
sIf(boolean b)
Writes a space if the boolean expression is
useWhitespace is false. |
void |
write(char[] cbuf,
int off,
int len) |
protected final boolean useWhitespace
protected final int maxIndent
protected final boolean trimStrings
protected final char quoteChar
protected final UriResolver uriResolver
public SerializerWriter(Writer out, boolean useWhitespace, int maxIndent, boolean trimStrings, char quoteChar, UriResolver uriResolver)
out
- The writer being wrapped.useWhitespace
- If cr(int)
will create an indentation and calling s()
will write a
space character.maxIndent
- The maximum indentation level.trimStrings
- If quoteChar
- The character to write when q()
is called.uriResolver
- The URI resolver for resolving URIs to absolute or root-relative form.public SerializerWriter cr(int depth) throws IOException
Adds a newline and the specified number of tabs (if the useWhitespace
setting is enabled) to the output.
depth
- The indentation.IOException
- If a problem occurred trying to write to the writer.public SerializerWriter cre(int depth) throws IOException
Adds a newline and the specified number of tabs (if the useWhitespace
setting is enabled) to the output.
depth
- The indentation.IOException
- If a problem occurred trying to write to the writer.public SerializerWriter appendln(int indent, String text) throws IOException
useWhitespace
setting is enabled), followed by text, followed by a newline
(if the useWhitespace
setting is enabled).indent
- The number of tabs to indent.text
- The text to write.IOException
- If a problem occurred trying to write to the writer.public SerializerWriter appendln(String text) throws IOException
useWhitespace
setting is enabled).text
- The text to write.IOException
- If a problem occurred trying to write to the writer.public SerializerWriter append(int indent, String text) throws IOException
useWhitespace
setting is enabled), followed by text.indent
- The number of tabs to indent.text
- The text to write.IOException
- If a problem occurred trying to write to the writer.public SerializerWriter append(int indent, char c) throws IOException
useWhitespace
setting is enabled), followed by text.indent
- The number of tabs to indent.c
- The character to write.IOException
- If a problem occurred trying to write to the writer.public SerializerWriter appendUri(Object uri) throws IOException
Object is converted to a String
using toString()
, so this will work on URL
or
URI
objects, or any other type that returns a URI via it's toString()
method.
The URI is resolved based on the Serializer.SERIALIZER_uriRelativity
and
Serializer.SERIALIZER_uriResolution
settings and the UriContext
that's part of the
session.
uri
- The URI to serialize.IOException
- If a problem occurred trying to write to the writer.public SerializerWriter append(char[] characters) throws IOException
characters
- The characters to append to this writer.IOException
public SerializerWriter s() throws IOException
useWhitespace
setting is enabled.IOException
- If a problem occurred trying to write to the writer.public SerializerWriter q() throws IOException
quoteChar
setting to the output.IOException
- If a problem occurred trying to write to the writer.public SerializerWriter i(int indent) throws IOException
useWhitespace
setting is enabled.indent
- The number of tabs to indent.IOException
- If a problem occurred trying to write to the writer.public SerializerWriter ie(int indent) throws IOException
useWhitespace
setting is enabled.indent
- The number of tabs to indent.IOException
- If a problem occurred trying to write to the writer.public SerializerWriter nl(int indent) throws IOException
useWhitespace
setting is enabled.indent
- The current indentation level.IOException
- If a problem occurred trying to write to the writer.public SerializerWriter sIf(boolean b) throws IOException
useWhitespace
is false.
Intended for cases in XML where text should be separated by either a space or newline. This ensures the text is separated by a space if whitespace is disabled.
b
- The boolean flag.IOException
- If a problem occurred trying to write to the writer.public SerializerWriter nlIf(boolean b, int indent) throws IOException
useWhitespace
setting is enabled and the boolean flag is true.b
- The boolean flag.indent
- The current indentation level.IOException
- If a problem occurred trying to write to the writer.public SerializerWriter append(Object text) throws IOException
text
- The text to write.IOException
- If a problem occurred trying to write to the writer.public SerializerWriter append(String text) throws IOException
text
- The text to write.IOException
- If a problem occurred trying to write to the writer.public SerializerWriter appendIf(boolean b, String text) throws IOException
b
- Boolean flag.text
- The text to write.IOException
- If a problem occurred trying to write to the writer.public SerializerWriter appendIf(boolean b, char c) throws IOException
b
- Boolean flag.c
- The text to write.IOException
- If a problem occurred trying to write to the writer.public SerializerWriter append(char c) throws IOException
append
in interface Appendable
append
in class Writer
IOException
public void write(char[] cbuf, int off, int len) throws IOException
write
in class Writer
IOException
public void flush() throws IOException
flush
in interface Flushable
flush
in class Writer
IOException
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
close
in class Writer
IOException
Copyright © 2018 Apache. All rights reserved.