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
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.
|
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) throws IOException
n
- Value of byte to be written.IOException
- if io errorsPrintStream.write(int)
,
PrintWriter.write(int)
public void println(String value) throws IOException
value
- String to be printedIOException
- if io errorsPrintStream.println(String)
,
PrintWriter.println(String)
public void print(String value) throws IOException
value
- String to be printedIOException
- if io errorsPrintStream.print(String)
,
PrintWriter.print(String)
public void print(char c) throws IOException
c
- Character to be printedIOException
- if io errorsPrintStream.print(char)
,
PrintWriter.print(char)
public void println(char c) throws IOException
c
- Character to be printedIOException
- if io errorsPrintStream.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) throws IOException
c
- Character to be printedIOException
- if io errorsPrintStream.println(char[])
,
PrintWriter.println(char[])
public void println() throws IOException
IOException
- if io errorsPrintStream.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
- if start and end values out of boundsPrintStream.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) throws IOException
value
- integer value to be printedIOException
- if io errorsInteger.toString(int)
,
PrintStream.print(int)
,
PrintWriter.print(int)
public void println(int value) throws IOException
value
- integer value to be printedIOException
- if io errorsInteger.toString(int)
,
PrintStream.println(int)
,
PrintWriter.println(int)
public void print(long value) throws IOException
value
- long integer value to be printedIOException
- if io errorsLong.toString(long)
,
PrintStream.println(long)
,
PrintWriter.println(long)
public void println(long value) throws IOException
value
- long integer value to be printedIOException
- if io errorsLong.toString(long)
,
PrintStream.println(long)
,
PrintWriter.println(long)
public void print(boolean value) throws IOException
value
- boolean value to be printedIOException
- if io errorsBoolean.toString(boolean)
,
PrintStream.print(boolean)
,
PrintWriter.print(boolean)
public void println(boolean value) throws IOException
value
- Boolean value to be printedIOException
- if io errorsBoolean.toString(boolean)
,
PrintStream.println(boolean)
,
PrintWriter.println(boolean)
public void print(double value) throws IOException
value
- Double-precision floating-point number to be printedIOException
- if io errorsPrintStream.print(double)
,
PrintWriter.print(double)
public void println(double value) throws IOException
value
- Double-precision floating-point number to be printedIOException
- if io errorsPrintStream.println(double)
,
PrintWriter.println(double)
public void print(float value) throws IOException
value
- Floating-point number to be printedIOException
- if io errorsPrintStream.println(float)
,
PrintWriter.println(float)
public void println(float value) throws IOException
value
- Floating-point number to be printedIOException
- if io errors occurPrintStream.println(float)
,
PrintWriter.println(float)
Copyright © 2017. All rights reserved.