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
FieldsModifier and TypeFieldDescriptionprotected final intMax indentation levels.protected final WriterThe underlying writer.protected final charThe quote character being used by this writer.protected final booleanTrim strings flag.protected final UriResolverThe URI resolver of the request.protected final booleanUse-whitespace flag. -
Constructor Summary
ConstructorsConstructorDescriptionSerializerWriter(Writer out, boolean useWhitespace, int maxIndent, boolean trimStrings, char quoteChar, UriResolver uriResolver) Copy Constructor -
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 theuseWhitespacesetting is enabled), followed by text.Writes an indent (if theuseWhitespacesetting 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 theuseWhitespacesetting is enabled), followed by text, followed by a newline (if theuseWhitespacesetting is enabled).Writes the specified text followed by a newline (if theuseWhitespacesetting is enabled).Appends the specified object as a URI.voidclose()cr(int depth) Performs a carriage return.cre(int depth) Performs a carriage return at the end of a line.voidflush()i(int indent) Writes an indent to the writer if theuseWhitespacesetting is enabled.ie(int indent) Writes an end-of-line indent to the writer if theuseWhitespacesetting is enabled.nl(int indent) Writes a newline to the writer if theuseWhitespacesetting is enabled.nlIf(boolean flag, int indent) Writes a newline to the writer if theuseWhitespacesetting is enabled and the boolean flag is true.q()Adds the quote character specified by thequoteCharsetting to the output.s()Adds a whitespace character to the output if theuseWhitespacesetting is enabled.sIf(boolean flag) Writes a space if the boolean expression istrue anduseWhitespaceis false.w(char value) Writes the specified character to the writer.Writes the specified string to the writer.voidwrite(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
Copy Constructor- Parameters:
w- Writer being copied.
-
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
-
append
- Specified by:
appendin interfaceAppendable- Overrides:
appendin classWriter
-
append
Appends the specified characters to this writer.- Parameters:
value- The characters to append to this writer.- Returns:
- This object.
-
append
Writes an indent (if theuseWhitespacesetting is enabled), followed by text.- Parameters:
indent- The number of tabs to indent.value- The character to write.- Returns:
- This object.
-
append
Writes an indent (if theuseWhitespacesetting is enabled), followed by text.- Parameters:
indent- The number of tabs to indent.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.
-
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.
-
appendln
Writes an indent (if theuseWhitespacesetting is enabled), followed by text, followed by a newline (if theuseWhitespacesetting 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 theuseWhitespacesetting is enabled).- Parameters:
value- The text to write.- Returns:
- This object.
-
appendUri
Appends the specified object as a URI.Object is converted to a
String usingtoString() , so this will work onURLorURIobjects, 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 theUriContextthat's part of the session.- Parameters:
value- The URI to serialize.- Returns:
- This object.
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException
-
cr
Performs a carriage return.Adds a newline and the specified number of tabs (if the
useWhitespacesetting 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
useWhitespacesetting is enabled) to the output.- Parameters:
depth- The indentation.- Returns:
- This object.
-
flush
- Specified by:
flushin interfaceFlushable- Specified by:
flushin classWriter- Throws:
IOException
-
i
Writes an indent to the writer if theuseWhitespacesetting is enabled.- Parameters:
indent- The number of tabs to indent.- Returns:
- This object.
-
ie
Writes an end-of-line indent to the writer if theuseWhitespacesetting is enabled.- Parameters:
indent- The number of tabs to indent.- Returns:
- This object.
-
nl
Writes a newline to the writer if theuseWhitespacesetting is enabled.- Parameters:
indent- The current indentation level.- Returns:
- This object.
-
nlIf
Writes a newline to the writer if theuseWhitespacesetting is enabled and the boolean flag is true.- Parameters:
flag- The boolean flag.indent- The current indentation level.- Returns:
- This object.
-
q
Adds the quote character specified by thequoteCharsetting to the output.- Returns:
- This object.
-
s
Adds a whitespace character to the output if theuseWhitespacesetting is enabled.- Returns:
- This object.
-
sIf
Writes a space if the boolean expression istrue anduseWhitespaceis 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.
-
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.
-
write
-