public class GenericPrinter extends Object implements Appendable, Closeable, Flushable
PrintStream and PrintWriter implement Closeable, Flushable, and Appendable. The method names and parameter types used by these methods are the same as those in the PrintStream and PrintWriter classes.
StringWriter is first encapsulated in a PrintWriter to enable it to be used as an output device.
PrintStream
,
PrintWriter
,
StringWriter
Modifier and Type | Field and Description |
---|---|
(package private) PrintStream |
stream
PrintStream object.
|
(package private) Object |
underlying
PrintStream, PrintWriter, or StringWriter
object that was used in the constructor.
|
(package private) PrintWriter |
writer
PrintWriter object.
|
Constructor and Description |
---|
GenericPrinter(PrintStream value)
Create printer for PrintStream object.
|
GenericPrinter(PrintWriter value)
Create printer for PrintWriter object
|
GenericPrinter(StringWriter value)
Create printer for StringWriter object.
|
Modifier and Type | Method and Description |
---|---|
Appendable |
append(char c)
Append a character.
|
Appendable |
append(CharSequence csq)
Append a character sequence to the output stream.
|
Appendable |
append(CharSequence csq,
int start,
int end)
Append a subsequence of the specified character sequence to the output stream.
|
boolean |
checkError()
Checks if an error has occurred on the output stream.
|
void |
close()
Close the output stream.
|
void |
flush()
Flush the output stream.
|
Object |
getUnderlyingObject()
Return the underlying StringWriter, PrintStream or PrintWriter object
for the GenericPrinter object.
|
static void |
main(String[] args)
Test driver.
|
void |
print(boolean value)
Print a boolean value.
|
void |
print(char c)
Print a character.
|
void |
print(char[] c)
Print an array of characters.
|
void |
print(double value)
Print a double-precision floating-point number.
|
void |
print(float value)
Print a floating-point number.
|
void |
print(int value)
Print an integer value.
|
void |
print(long value)
Print a long integer value.
|
void |
print(String value)
Print string.
|
void |
println()
Terminate the line.
|
void |
println(boolean value)
Print a boolean value and then terminate the line.
|
void |
println(char c)
Print a character and terminate the line.
|
void |
println(char[] c)
Print an array of characters and then terminate the line.
|
void |
println(double value)
Print a double-precision floating-point number and
then terminate the line.
|
void |
println(float value)
Print a floating-point number and
then terminate the line.
|
void |
println(int value)
Print an integer value and then terminate the line.
|
void |
println(long value)
Print a long integer value and then terminate the line.
|
void |
println(String value)
Print string and then terminate the line.
|
void |
write(int n)
Place a byte containing the specified value to the stream.
|
PrintWriter writer
PrintWriter
PrintStream stream
PrintStream
Object underlying
public GenericPrinter(PrintWriter value)
value
- PrintWriter objectPrintWriter
public GenericPrinter(PrintStream value)
value
- PrintStream objectpublic GenericPrinter(StringWriter value)
value
- StringWriter object.public Object getUnderlyingObject()
public boolean checkError()
PrintStream.checkError()
,
PrintWriter.checkError()
public void write(int n)
n
- Value of byte to be written.PrintStream.write(int)
,
PrintWriter.write(int)
public void println(String value)
value
- String to be printedPrintStream.println(String)
,
PrintWriter.println(String)
public void print(String value)
value
- String to be printedPrintStream.print(String)
,
PrintWriter.print(String)
public void print(char c)
c
- Character to be printedPrintStream.print(char)
,
PrintWriter.print(char)
public void println(char c)
c
- Character to be printedPrintStream.println(String)
,
PrintWriter.println(String)
public void print(char[] c)
c
- Character to be printedPrintStream.print(char[])
,
PrintWriter.print(char[])
public void println(char[] c)
c
- Character to be printedPrintStream.println(char[])
,
PrintWriter.println(char[])
public void println()
PrintStream.println()
,
PrintWriter.println()
public Appendable append(char c)
append
in interface Appendable
PrintStream.append(char)
,
PrintWriter.append(char)
public Appendable append(CharSequence csq)
append
in interface Appendable
csq
- The character sequence to be be appended.PrintStream.append(CharSequence)
,
PrintWriter.append(CharSequence)
public Appendable append(CharSequence csq, int start, int end) throws IndexOutOfBoundsException
append
in interface Appendable
csq
- The character sequence from which a subsequence will be appended. If csq is null,
then characters will be appended as if csq contained the four characters "null".start
- The index of the first character in the subsequenceend
- The index of the character following the last character in the subsequenceIndexOutOfBoundsException
PrintStream.append(CharSequence,int,int)
,
PrintWriter.append(CharSequence, int, int)
public void close()
close
in interface Closeable
close
in interface AutoCloseable
PrintStream.close()
,
PrintWriter.close()
public void flush()
flush
in interface Flushable
PrintStream.flush()
,
PrintWriter.flush()
public void print(int value)
value
- integer value to be printedInteger.toString(int)
,
PrintStream.print(int)
,
PrintWriter.print(int)
public void println(int value)
value
- integer value to be printedInteger.toString(int)
,
PrintStream.println(int)
,
PrintWriter.println(int)
public void print(long value)
value
- long integer value to be printedLong.toString(long)
,
PrintStream.println(long)
,
PrintWriter.println(long)
public void println(long value)
value
- long integer value to be printedLong.toString(long)
,
PrintStream.println(long)
,
PrintWriter.println(long)
public void print(boolean value)
value
- boolean value to be printedBoolean.toString(boolean)
,
PrintStream.print(boolean)
,
PrintWriter.print(boolean)
public void println(boolean value)
value
- Boolean value to be printedBoolean.toString(boolean)
,
PrintStream.println(boolean)
,
PrintWriter.println(boolean)
public void print(double value)
value
- Double-precision floating-point number to be printedPrintStream.print(double)
,
PrintWriter.print(double)
public void println(double value)
value
- Double-precision floating-point number to be printedPrintStream.println(double)
,
PrintWriter.println(double)
public void print(float value)
value
- Floating-point number to be printedPrintStream.println(float)
,
PrintWriter.println(float)
public void println(float value)
value
- Floating-point number to be printedPrintStream.println(float)
,
PrintWriter.println(float)