- All Implemented Interfaces:
Closeable
,Appendable
,AutoCloseable
PrintWriter
and returns the ChainWriter
instance on most methods. This gives the ability to call code like
out.print("Hi ").print(name).print('!');
- Author:
- AO Industries, Inc.
-
Constructor Summary
ConstructorDescriptionChainWriter
(EncodingContext encodingContext, OutputStream out) Create a new PrintWriter, without automatic line flushing, from an existing OutputStream.ChainWriter
(EncodingContext encodingContext, OutputStream out, boolean autoFlush) Create a new PrintWriter from an existing OutputStream.ChainWriter
(EncodingContext encodingContext, PrintWriter out) ChainWriter
(EncodingContext encodingContext, Writer out) Create a new PrintWriter, if needed, without automatic line flushing.ChainWriter
(EncodingContext encodingContext, Writer out, boolean autoFlush) Create a new PrintWriter, if needed.ChainWriter
(OutputStream out) Deprecated.ChainWriter
(OutputStream out, boolean autoFlush) Deprecated.ChainWriter
(PrintWriter out) Deprecated.ChainWriter
(Writer out) Deprecated.ChainWriter
(Writer out, boolean autoFlush) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionappend
(char c) append
(CharSequence csq) append
(CharSequence csq, int start, int end) void
close()
Closes the stream.encodeHtml
(Object value, boolean isXhtml) Deprecated.the effects of makeBr and makeNbsp should be handled by CSS white-space property.encodeHtml
(Object value, boolean makeBr, boolean makeNbsp, boolean isXhtml) Deprecated.the effects of makeBr and makeNbsp should be handled by CSS white-space property.flush()
Flushes the stream.print
(boolean b) Print a boolean value.print
(char c) Print a character.print
(char[] s) Print an array of characters.print
(double d) Print a double-precision floating-point number.print
(float f) Print a floating-point number.print
(int i) Print an integer.print
(long l) Print a long integer.Print an object.Print a string.println()
Terminate the current line by writing the line separator string.println
(boolean x) Print a boolean value and then terminate the line.println
(char x) Print a character and then terminate the line.println
(char[] x) Print an array of characters and then terminate the line.println
(double x) Print a double-precision floating-point number and then terminate the line.println
(float x) Print a floating-point number and then terminate the line.println
(int x) Print an integer and then terminate the line.println
(long x) Print a long integer and then terminate the line.Print an Object and then terminate the line.Print a String and then terminate the line.textInJavascript
(Object value) Encodes a javascript string.textInJavascriptInXhtml
(Object value) Encodes a javascript string for use in an XML body CDATA context.Encodes a javascript string for use in an XML attribute context.textInMysql
(Object value) Encodes a MySQL string.textInPsql
(Object value) Encodes a psql string.Encodes a sh string.textInXhtml
(Object value) textInXmlAttribute
(Object value) write
(char[] buf) Write an array of characters.write
(char[] buf, int off, int len) Write a portion of an array of characters.write
(int c) Write a single character.Write a string.Write a portion of a string.writeHtmlColor
(int color) Prints a color in HTML format #xxxxxx, where xxxxxx is the hex code.static void
writeHtmlColor
(int color, Appendable out) Prints a color in HTML format #xxxxxx, where xxxxxx is the hex code.
-
Constructor Details
-
ChainWriter
Create a new PrintWriter, without automatic line flushing, from an existing OutputStream. This convenience constructor creates the necessary intermediate OutputStreamWriter, which will convert characters into bytes using the default character encoding.- Parameters:
out
- An output stream
-
ChainWriter
Deprecated.- See Also:
-
ChainWriter
Create a new PrintWriter from an existing OutputStream. This convenience constructor creates the necessary intermediate OutputStreamWriter, which will convert characters into bytes using the default character encoding.- Parameters:
out
- An output streamautoFlush
- A boolean; if true, the println() methods will flush the output buffer
-
ChainWriter
Deprecated.- See Also:
-
ChainWriter
-
ChainWriter
Deprecated.- See Also:
-
ChainWriter
Create a new PrintWriter, if needed, without automatic line flushing.When
out
is already aPrintWriter
, it is used directly, regardless ofautoFlush
settings.- Parameters:
out
- A character-output stream
-
ChainWriter
Deprecated.- See Also:
-
ChainWriter
Create a new PrintWriter, if needed.When
out
is already aPrintWriter
, it is used directly, regardless ofautoFlush
settings.- Parameters:
out
- A character-output streamautoFlush
- A boolean; if true, the println() methods will flush the output buffer
-
ChainWriter
Deprecated.- See Also:
-
-
Method Details
-
getEncodingContext
-
getPrintWriter
-
flush
Flushes the stream.Unlike
, exceptions are thrown immediately, as requiring the caller to remember to invokePrintWriter.flush()
too easily leads to swallowed exceptions and hard-to-diagnose runtime problems.PrintWriter.checkError()
- Throws:
IOException
-
close
Closes the stream.Unlike
, exceptions are thrown immediately, as requiring the caller to remember to invokePrintWriter.close()
too easily leads to swallowed exceptions and hard-to-diagnose runtime problems.PrintWriter.checkError()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
write
Write a single character. -
write
Write a portion of an array of characters. -
write
Write an array of characters. This method cannot be inherited from the Writer class because it must suppress I/O exceptions. -
write
Write a portion of a string. -
write
Write a string. This method cannot be inherited from the Writer class because it must suppress I/O exceptions. -
print
Print a boolean value. The string produced by
is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of theString.valueOf(boolean)
method.write(int)
- Parameters:
b
- Theboolean
to be printed
-
print
Print a character. The character is translated into one or more bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the
method.write(int)
- Parameters:
c
- Thechar
to be printed
-
print
Print an integer. The string produced by
is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of theString.valueOf(int)
method.write(int)
- Parameters:
i
- Theint
to be printed- See Also:
-
print
Print a long integer. The string produced by
is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of theString.valueOf(long)
method.write(int)
- Parameters:
l
- Thelong
to be printed
-
print
Print a floating-point number. The string produced by
is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of theString.valueOf(float)
method.write(int)
- Parameters:
f
- Thefloat
to be printed- See Also:
-
print
Print a double-precision floating-point number. The string produced by
is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of theString.valueOf(double)
method.write(int)
- Parameters:
d
- Thedouble
to be printed
-
print
Print an array of characters. The characters are converted into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the
method.write(int)
- Parameters:
s
- The array of chars to be printed- Throws:
NullPointerException
- Ifs
isnull
-
print
Print a string. If the argument isnull
then the string"null"
is printed. Otherwise, the string's characters are converted into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of the
method.write(int)
- Parameters:
s
- TheString
to be printed
-
print
Print an object. The string produced by the
method is translated into bytes according to the platform's default character encoding, and these bytes are written in exactly the manner of theString.valueOf(Object)
method.write(int)
- Parameters:
obj
- TheObject
to be printed- See Also:
-
println
Terminate the current line by writing the line separator string. The line separator string is defined by the system propertyline.separator
, and is not necessarily a single newline character ('\n'
). -
println
Print a boolean value and then terminate the line. This method behaves as though it invokes
and thenprint(boolean)
.println()
-
println
Print a character and then terminate the line. This method behaves as though it invokes
and thenprint(char)
.println()
-
println
Print an integer and then terminate the line. This method behaves as though it invokes
and thenprint(int)
.println()
-
println
Print a long integer and then terminate the line. This method behaves as though it invokes
and thenprint(long)
.println()
-
println
Print a floating-point number and then terminate the line. This method behaves as though it invokes
and thenprint(float)
.println()
-
println
Print a double-precision floating-point number and then terminate the line. This method behaves as though it invokes
and thenprint(double)
.println()
-
println
Print an array of characters and then terminate the line. This method behaves as though it invokes
and thenprint(char[])
.println()
-
println
Print a String and then terminate the line. This method behaves as though it invokes
and thenprint(String)
.println()
-
println
Print an Object and then terminate the line. This method behaves as though it invokes
and thenprint(Object)
.println()
-
printf
-
printf
-
format
-
format
-
append
- Specified by:
append
in interfaceAppendable
-
append
- Specified by:
append
in interfaceAppendable
-
append
- Specified by:
append
in interfaceAppendable
-
textInXmlAttribute
- Parameters:
value
- the value to be encoded- Throws:
IOException
- See Also:
-
textInXhtml
- Parameters:
value
- the value to be encoded- Throws:
IOException
- See Also:
-
encodeHtml
Deprecated.the effects of makeBr and makeNbsp should be handled by CSS white-space property.Escapes HTML for displaying in browsers and writes to the internal
. Has makeBr and makeNbsp enabled.PrintWriter
- Parameters:
value
- the string to be escaped.- Throws:
IOException
- See Also:
-
encodeHtml
@Deprecated public ChainWriter encodeHtml(Object value, boolean makeBr, boolean makeNbsp, boolean isXhtml) throws IOException Deprecated.the effects of makeBr and makeNbsp should be handled by CSS white-space property.Escapes HTML for displaying in browsers and writes to the internal
.PrintWriter
- Parameters:
value
- the string to be escaped.makeBr
- will write <br /> tags for every newline charactermakeNbsp
- will write   for a space when another space follows- Throws:
IOException
- See Also:
-
textInJavascript
Encodes a javascript string. Quotes ("…"
) are added around the string. Also, if the string is translated, comments will be added giving the translation lookup id to aid in translation of server-translated values.- Parameters:
value
- the value to be encoded- Throws:
IOException
- See Also:
-
textInJavascriptInXmlAttribute
Encodes a javascript string for use in an XML attribute context. Quotes ("…"
) are added around the string. Also, if the string is translated, comments will be added giving the translation lookup id to aid in translation of server-translated values.- Parameters:
value
- the value to be encoded- Throws:
IOException
- See Also:
-
textInJavascriptInXhtml
Encodes a javascript string for use in an XML body CDATA context. Quotes ("…"
) are added around the string. Also, if the string is translated, comments will be added giving the translation lookup id to aid in translation of server-translated values.- Parameters:
value
- the value to be encoded- Throws:
IOException
- See Also:
-
textInMysql
Encodes a MySQL string.E'…'
quotes are added around the string. Also, if the string is translated, comments will be added giving the translation lookup id to aid in translation of server-translated values.- Parameters:
value
- the value to be encoded- Throws:
IOException
- See Also:
-
textInPsql
Encodes a psql string.E'…'
quotes are added around the string. Also, if the string is translated, comments will be added giving the translation lookup id to aid in translation of server-translated values.- Parameters:
value
- the value to be encoded- Throws:
IOException
- See Also:
-
textInSh
Encodes a sh string.$'…'
quotes are added around the string. Also, if the string is translated, comments will be added giving the translation lookup id to aid in translation of server-translated values.- Parameters:
value
- the value to be encoded- Throws:
IOException
- See Also:
-
writeHtmlColor
Prints a color in HTML format #xxxxxx, where xxxxxx is the hex code.- Throws:
IOException
-
writeHtmlColor
Prints a color in HTML format #xxxxxx, where xxxxxx is the hex code.- Throws:
IOException
-
ChainWriter(com.aoapps.encoding.EncodingContext, java.io.OutputStream)