public class CountingPrintWriter
extends java.io.PrintWriter
Methods in this class never throw I/O exceptions. The client may inquire as to whether any
errors have occurred by invoking PrintWriter.checkError()
.
Constructor and Description |
---|
CountingPrintWriter(java.io.OutputStream out)
Create a new PrintWriter, without automatic line flushing, from an existing OutputStream.
|
CountingPrintWriter(java.io.OutputStream out,
boolean autoFlush)
Create a new PrintWriter from an existing OutputStream.
|
CountingPrintWriter(java.io.Writer out)
Create a new PrintWriter, without automatic line flushing.
|
CountingPrintWriter(java.io.Writer out,
boolean autoFlush)
Create a new PrintWriter, without automatic line flushing.
|
Modifier and Type | Method and Description |
---|---|
int |
countBytes(char c)
Returns the number of bytes used to represent a character.
|
int |
countBytes(java.lang.String s)
Returns the number of bytes contained in a string.
|
int |
getNumberOfPrintedBytes()
Returns the total number of bytes printed using any of the 'print' or 'println' methods of this
CountingPrintBuffer.
|
int |
getNumberOfPrintedChars()
Returns the total number of characters printed using any of the 'print' or 'println' methods of
this CountingPrintBuffer.
|
int |
getNumberOfWrittenBytes()
Returns the total number of bytes printed using any of the 'write' methods of this
CountingPrintBuffer.
|
void |
print(boolean b)
Print a boolean value.
|
void |
print(char c)
Print a character.
|
void |
print(char[] s)
Print an array of characters.
|
void |
print(double d)
Print a double-precision floating-point number.
|
void |
print(float f)
Print a floating-point number.
|
void |
print(int i)
Print an integer.
|
void |
print(long l)
Print a long integer.
|
void |
print(java.lang.Object obj)
Print an object.
|
void |
print(java.lang.String s)
Print a string.
|
void |
println()
Terminate the current line by writing the line separator string.
|
void |
println(java.lang.String s)
Print a String and then terminate the line.
|
void |
resetAll()
Resets all the byte and char counters.
|
void |
resetPrintedByteCounter()
Resets printedByte counter.
|
void |
resetPrintedCharCounter()
Resets printedChar counter.
|
void |
resetWrittenByteCounter()
Resets writtenByte counter.
|
void |
resetWrittenCharCounter()
Resets writtenChar counter.
|
void |
write(char[] buf)
Write an array of characters.
|
void |
write(char[] buf,
int off,
int len)
Write a portion of a character array.
|
void |
write(java.lang.String s)
Write a string.
|
void |
write(java.lang.String s,
int off,
int len)
Write a portion of a string.
|
public CountingPrintWriter(java.io.OutputStream out)
out
- an output streampublic CountingPrintWriter(java.io.OutputStream out, boolean autoFlush)
out
- an output streamautoFlush
- if true, the println() methods will flush the output bufferpublic CountingPrintWriter(java.io.Writer out)
out
- a Writerpublic CountingPrintWriter(java.io.Writer out, boolean autoFlush)
out
- a writerautoFlush
- if true, the println() methods will flush the output bufferpublic int countBytes(java.lang.String s)
s
- the String for which to count bytespublic int countBytes(char c)
c
- a characterpublic int getNumberOfPrintedBytes()
public int getNumberOfWrittenBytes()
public int getNumberOfPrintedChars()
public void print(java.lang.String s)
PrintWriter.write(int)
method.print
in class java.io.PrintWriter
s
- the string to be printed, or nullpublic void print(boolean b)
String.valueOf(boolean)
is translated
into bytes according to the platform's default character encoding, and these bytes are written
in exactly the manner of the PrintWriter.write(int)
method.print
in class java.io.PrintWriter
b
- the boolean to be printedpublic void print(char c)
PrintWriter.write(int)
method.print
in class java.io.PrintWriter
c
- the char to be printedpublic void print(char[] s)
PrintWriter.write(int)
method.print
in class java.io.PrintWriter
s
- the char[] to be printedpublic void print(double d)
String.valueOf(double)
is translated into bytes according to the platform's default character
encoding, and these bytes are written in exactly the manner of the PrintWriter.write(int)
method.print
in class java.io.PrintWriter
d
- the double to be printedpublic void print(float f)
String.valueOf(float)
is
translated into bytes according to the platform's default character encoding, and these bytes
are written in exactly the manner of the PrintWriter.write(int)
method.print
in class java.io.PrintWriter
f
- the float to be printedpublic void print(int i)
String.valueOf(int)
is translated into bytes
according to the platform's default character encoding, and these bytes are written in exactly
the manner of the PrintWriter.write(int)
method.print
in class java.io.PrintWriter
i
- the int to be printedpublic void resetAll()
public void resetPrintedByteCounter()
public void resetPrintedCharCounter()
public void resetWrittenByteCounter()
public void resetWrittenCharCounter()
public void print(long l)
String.valueOf(long)
is translated into
bytes according to the platform's default character encoding, and these bytes are written in
exactly the manner of the PrintWriter.write(int)
method.print
in class java.io.PrintWriter
l
- the long to be printedpublic void print(java.lang.Object obj)
String.valueOf(Object)
method is translated
into bytes according to the platform's default character encoding, and these bytes are written
in exactly the manner of the PrintWriter.write(int)
method.print
in class java.io.PrintWriter
obj
- the object to be printedpublic void println()
When incrementing the byte count of PrintWriter, also accounts for the bytes needed to represent the line separator string.
println
in class java.io.PrintWriter
public void println(java.lang.String s)
println
in class java.io.PrintWriter
s
- the string to be printedpublic void write(char[] buf)
write
in class java.io.PrintWriter
buf
- the char[] to be printedpublic void write(char[] buf, int off, int len)
write
in class java.io.PrintWriter
buf
- character arrayoff
- offset from which to start writing characterslen
- number of characters to writepublic void write(java.lang.String s)
write
in class java.io.PrintWriter
s
- the string to be printedpublic void write(java.lang.String s, int off, int len)
write
in class java.io.PrintWriter
s
- string to be printedoff
- offset from which to start writing characterslen
- number of characters to write