Class SerializerWriter
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
- Direct Known Subclasses:
CsvWriter
,JsonWriter
,UonWriter
,XmlWriter
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.
Example:
See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprotected final int
Max indentation levels.protected final Writer
The underlying writer.protected final char
The quote character being used by this writer.protected final boolean
Trim strings flag.protected final UriResolver
The URI resolver of the request.protected final boolean
Use-whitespace flag. -
Constructor Summary
ConstructorDescriptionSerializerWriter
(Writer out, boolean useWhitespace, int maxIndent, boolean trimStrings, char quoteChar, UriResolver uriResolver) -
Method Summary
Modifier and TypeMethodDescriptionappend
(char c) append
(char[] value) Appends the specified characters to this writer.append
(int indent, char value) Writes an indent (if theuseWhitespace
setting is enabled), followed by text.Writes an indent (if theuseWhitespace
setting is enabled), followed by text.Writes the specified text to the writer if it isn'tnull .Writes the specified text to the writer if it isn'tnull .appendIf
(boolean flag, char value) Writes the specified text to the writer if b is true.Writes the specified text to the writer if b is true.Writes an indent (if theuseWhitespace
setting is enabled), followed by text, followed by a newline (if theuseWhitespace
setting is enabled).Writes the specified text followed by a newline (if theuseWhitespace
setting is enabled).Appends the specified object as a URI.void
close()
cr
(int depth) Performs a carriage return.cre
(int depth) Performs a carriage return at the end of a line.void
flush()
i
(int indent) Writes an indent to the writer if theuseWhitespace
setting is enabled.ie
(int indent) Writes an end-of-line indent to the writer if theuseWhitespace
setting is enabled.nl
(int indent) Writes a newline to the writer if theuseWhitespace
setting is enabled.nlIf
(boolean flag, int indent) Writes a newline to the writer if theuseWhitespace
setting is enabled and the boolean flag is true.q()
Adds the quote character specified by thequoteChar
setting to the output.s()
Adds a whitespace character to the output if theuseWhitespace
setting is enabled.sIf
(boolean flag) Writes a space if the boolean expression istrue anduseWhitespace
is false.w
(char value) Writes the specified character to the writer.Writes the specified string to the writer.void
write
(char[] cbuf, int off, int len)
-
Field Details
-
out
The underlying writer. -
useWhitespace
Use-whitespace flag. -
maxIndent
Max indentation levels. -
trimStrings
Trim strings flag. -
quoteChar
The quote character being used by this writer. -
uriResolver
The URI resolver of the request.
-
-
Constructor Details
-
SerializerWriter
public SerializerWriter(Writer out, boolean useWhitespace, int maxIndent, boolean trimStrings, char quoteChar, UriResolver uriResolver) - Parameters:
out
- The writer being wrapped.useWhitespace
- Iftrue , callingcr(int)
will create an indentation and callings()
will write a space character.maxIndent
- The maximum indentation level.trimStrings
- Iftrue , strings should be trimmed before they're serialized.quoteChar
- The character to write whenq()
is called.uriResolver
- The URI resolver for resolving URIs to absolute or root-relative form.
-
-
Method Details
-
cr
Performs a carriage return.Adds a newline and the specified number of tabs (if the
useWhitespace
setting is enabled) to the output.- Parameters:
depth
- The indentation.- Returns:
- This object.
-
cre
Performs a carriage return at the end of a line.Adds a newline and the specified number of tabs (if the
useWhitespace
setting is enabled) to the output.- Parameters:
depth
- The indentation.- Returns:
- This object.
-
appendln
Writes an indent (if theuseWhitespace
setting is enabled), followed by text, followed by a newline (if theuseWhitespace
setting is enabled).- Parameters:
indent
- The number of tabs to indent.value
- The text to write.- Returns:
- This object.
-
appendln
Writes the specified text followed by a newline (if theuseWhitespace
setting is enabled).- Parameters:
value
- The text to write.- Returns:
- This object.
-
append
Writes an indent (if theuseWhitespace
setting is enabled), followed by text.- Parameters:
indent
- The number of tabs to indent.value
- The text to write.- Returns:
- This object.
-
append
Writes an indent (if theuseWhitespace
setting is enabled), followed by text.- Parameters:
indent
- The number of tabs to indent.value
- The character to write.- Returns:
- This object.
-
appendUri
Appends the specified object as a URI.Object is converted to a
String usingtoString() , so this will work onURL
orURI
objects, or any other type that returns a URI via it'stoString() method.The URI is resolved based on the
Serializer.Builder.uriRelativity(UriRelativity)
andSerializer.Builder.uriResolution(UriResolution)
settings and theUriContext
that's part of the session.- Parameters:
value
- The URI to serialize.- Returns:
- This object.
-
append
Appends the specified characters to this writer.- Parameters:
value
- The characters to append to this writer.- Returns:
- This object.
-
s
Adds a whitespace character to the output if theuseWhitespace
setting is enabled.- Returns:
- This object.
-
q
Adds the quote character specified by thequoteChar
setting to the output.- Returns:
- This object.
-
i
Writes an indent to the writer if theuseWhitespace
setting is enabled.- Parameters:
indent
- The number of tabs to indent.- Returns:
- This object.
-
ie
Writes an end-of-line indent to the writer if theuseWhitespace
setting is enabled.- Parameters:
indent
- The number of tabs to indent.- Returns:
- This object.
-
nl
Writes a newline to the writer if theuseWhitespace
setting is enabled.- Parameters:
indent
- The current indentation level.- Returns:
- This object.
-
sIf
Writes a space if the boolean expression istrue anduseWhitespace
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.
- Parameters:
flag
- The boolean flag.- Returns:
- This object.
-
nlIf
Writes a newline to the writer if theuseWhitespace
setting is enabled and the boolean flag is true.- Parameters:
flag
- The boolean flag.indent
- The current indentation level.- Returns:
- This object.
-
append
Writes the specified text to the writer if it isn'tnull .- Parameters:
value
- The text to write.- Returns:
- This object.
-
append
Writes the specified text to the writer if it isn'tnull .- Parameters:
value
- The text to write.- Returns:
- This object.
-
appendIf
Writes the specified text to the writer if b is true.- Parameters:
flag
- Boolean flag.value
- The text to write.- Returns:
- This object.
-
appendIf
Writes the specified text to the writer if b is true.- Parameters:
flag
- Boolean flag.value
- The text to write.- Returns:
- This object.
-
w
Writes the specified character to the writer.- Parameters:
value
- The character to write.- Returns:
- This object.
-
w
Writes the specified string to the writer.- Parameters:
value
- The string to write.- Returns:
- This object.
-
append
- Specified by:
append
in interfaceAppendable
- Overrides:
append
in classWriter
-
write
-
flush
- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in classWriter
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classWriter
- Throws:
IOException
-