public class FastPrintWriter extends PrintWriter
out
Constructor and Description |
---|
FastPrintWriter(OutputStream out)
Constructs a new
PrintWriter with out as its target
stream. |
FastPrintWriter(OutputStream out,
boolean autoFlush)
Constructs a new
PrintWriter with out as its target
stream. |
FastPrintWriter(OutputStream out,
boolean autoFlush,
int bufferLen)
Constructs a new
PrintWriter with out as its target
stream and a custom buffer size. |
FastPrintWriter(Printer pr)
Constructs a new
PrintWriter with pr as its target
printer and the default buffer size. |
FastPrintWriter(Printer pr,
int bufferLen)
Constructs a new
PrintWriter with pr as its target
printer and a custom buffer size. |
FastPrintWriter(Writer wr)
Constructs a new
PrintWriter with wr as its target
writer. |
FastPrintWriter(Writer wr,
boolean autoFlush)
Constructs a new
PrintWriter with wr as its target
writer. |
FastPrintWriter(Writer wr,
boolean autoFlush,
int bufferLen)
Constructs a new
PrintWriter with wr as its target
writer and a custom buffer size. |
Modifier and Type | Method and Description |
---|---|
PrintWriter |
append(CharSequence csq,
int start,
int end)
Appends a subsequence of the character sequence
csq to the
target. |
boolean |
checkError()
Flushes this writer and returns the value of the error flag.
|
protected void |
clearError()
Sets the error state of the stream to false.
|
void |
close()
Closes the stream and releases any system resources associated
with it.
|
void |
flush()
Ensures that all pending data is sent out to the target.
|
void |
print(char ch)
Prints the string representation of the specified character to the
target.
|
void |
print(char[] charArray)
Prints the string representation of the specified character array
to the target.
|
void |
print(int inum)
Prints an integer.
|
void |
print(long lnum)
Prints a long integer.
|
void |
print(String str)
Prints a string to the target.
|
void |
println()
Prints a newline.
|
void |
println(char c)
Prints the string representation of the char
c followed by a newline. |
void |
println(char[] chars)
Prints the string representation of the character array
chars followed by a newline. |
void |
println(int inum)
Prints an integer and then terminates the line.
|
void |
println(long lnum)
Prints a long integer and then terminates the line.
|
protected void |
setError()
Sets the error flag of this writer to true.
|
void |
write(char[] buf,
int offset,
int count)
Writes
count characters from buffer starting at offset to the target. |
void |
write(int oneChar)
Writes one character to the target.
|
void |
write(String str)
Writes the characters from the specified string to the target.
|
void |
write(String str,
int offset,
int count)
Writes
count characters from str starting at offset to the target. |
public FastPrintWriter(OutputStream out)
PrintWriter
with out
as its target
stream. By default, the new print writer does not automatically flush its
contents to the target stream when a newline is encountered.out
- the target output stream.NullPointerException
- if out
is null
.public FastPrintWriter(OutputStream out, boolean autoFlush)
PrintWriter
with out
as its target
stream. The parameter autoFlush
determines if the print writer
automatically flushes its contents to the target stream when a newline is
encountered.out
- the target output stream.autoFlush
- indicates whether contents are flushed upon encountering a
newline sequence.NullPointerException
- if out
is null
.public FastPrintWriter(OutputStream out, boolean autoFlush, int bufferLen)
PrintWriter
with out
as its target
stream and a custom buffer size. The parameter autoFlush
determines
if the print writer automatically flushes its contents to the target stream
when a newline is encountered.out
- the target output stream.autoFlush
- indicates whether contents are flushed upon encountering a
newline sequence.bufferLen
- specifies the size of the FastPrintWriter's internal buffer; the
default is 8192.NullPointerException
- if out
is null
.public FastPrintWriter(Writer wr)
PrintWriter
with wr
as its target
writer. By default, the new print writer does not automatically flush its
contents to the target writer when a newline is encountered.
NOTE: Unlike PrintWriter, this version will still do buffering inside of FastPrintWriter before sending data to the Writer. This means you must call flush() before retrieving any data from the Writer.
wr
- the target writer.NullPointerException
- if wr
is null
.public FastPrintWriter(Writer wr, boolean autoFlush)
PrintWriter
with wr
as its target
writer. The parameter autoFlush
determines if the print writer
automatically flushes its contents to the target writer when a newline is
encountered.wr
- the target writer.autoFlush
- indicates whether to flush contents upon encountering a
newline sequence.NullPointerException
- if out
is null
.public FastPrintWriter(Writer wr, boolean autoFlush, int bufferLen)
PrintWriter
with wr
as its target
writer and a custom buffer size. The parameter autoFlush
determines
if the print writer automatically flushes its contents to the target writer
when a newline is encountered.wr
- the target writer.autoFlush
- indicates whether to flush contents upon encountering a
newline sequence.bufferLen
- specifies the size of the FastPrintWriter's internal buffer; the
default is 8192.NullPointerException
- if wr
is null
.public FastPrintWriter(Printer pr)
PrintWriter
with pr
as its target
printer and the default buffer size. Because a Printer
is line-base,
autoflush is always enabled.pr
- the target writer.NullPointerException
- if pr
is null
.public FastPrintWriter(Printer pr, int bufferLen)
PrintWriter
with pr
as its target
printer and a custom buffer size. Because a Printer
is line-base,
autoflush is always enabled.pr
- the target writer.bufferLen
- specifies the size of the FastPrintWriter's internal buffer; the
default is 512.NullPointerException
- if pr
is null
.public boolean checkError()
checkError
in class PrintWriter
true
if either an IOException
has been thrown
previously or if setError()
has been called;
false
otherwise.setError()
protected void clearError()
clearError
in class PrintWriter
protected void setError()
setError
in class PrintWriter
public void flush()
true
.flush
in interface Flushable
flush
in class PrintWriter
PrintWriter.checkError()
public void close()
PrintWriter
close
in interface Closeable
close
in interface AutoCloseable
close
in class PrintWriter
PrintWriter.checkError()
public void print(char[] charArray)
print
in class PrintWriter
charArray
- the character array to print to the target.print(String)
public void print(char ch)
print
in class PrintWriter
ch
- the character to print to the target.print(String)
public void print(String str)
write(int)
.
If an I/O error occurs, this writer's error flag is set to true
.
print
in class PrintWriter
str
- the string to print to the target.write(int)
public void print(int inum)
PrintWriter
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 PrintWriter
inum
- The int
to be printedInteger.toString(int)
public void print(long lnum)
PrintWriter
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 PrintWriter
lnum
- The long
to be printedLong.toString(long)
public void println()
true
.println
in class PrintWriter
public void println(int inum)
PrintWriter
PrintWriter.print(int)
and then PrintWriter.println()
.println
in class PrintWriter
inum
- the int
value to be printedpublic void println(long lnum)
PrintWriter
PrintWriter.print(long)
and then
PrintWriter.println()
.println
in class PrintWriter
lnum
- the long
value to be printedpublic void println(char[] chars)
chars
followed by a newline.
Flushes this writer if the autoFlush flag is set to true
.println
in class PrintWriter
chars
- the array of char
values to be printedpublic void println(char c)
c
followed by a newline.
Flushes this writer if the autoFlush flag is set to true
.println
in class PrintWriter
c
- the char
value to be printedpublic void write(char[] buf, int offset, int count)
count
characters from buffer
starting at offset
to the target.
This writer's error flag is set to true
if this writer is closed
or an I/O error occurs.
write
in class PrintWriter
buf
- the buffer to write to the target.offset
- the index of the first character in buffer
to write.count
- the number of characters in buffer
to write.IndexOutOfBoundsException
- if offset < 0
or count < 0
, or if offset + count
is greater than the length of buf
.public void write(int oneChar)
oneChar
are written.
This writer's error flag is set to true
if this writer is closed
or an I/O error occurs.
write
in class PrintWriter
oneChar
- the character to write to the target.public void write(String str)
write
in class PrintWriter
str
- the non-null string containing the characters to write.public void write(String str, int offset, int count)
count
characters from str
starting at offset
to the target.write
in class PrintWriter
str
- the non-null string containing the characters to write.offset
- the index of the first character in str
to write.count
- the number of characters from str
to write.IndexOutOfBoundsException
- if offset < 0
or count < 0
, or if offset + count
is greater than the length of str
.public PrintWriter append(CharSequence csq, int start, int end)
csq
to the
target. This method works the same way as PrintWriter.print(csq.subsequence(start, end).toString())
. If csq
is null
, then the specified subsequence of the string "null"
will be written to the target.append
in interface Appendable
append
in class PrintWriter
csq
- the character sequence appended to the target.start
- the index of the first char in the character sequence appended
to the target.end
- the index of the character following the last character of the
subsequence appended to the target.StringIndexOutOfBoundsException
- if start > end
, start < 0
, end < 0
or
either start
or end
are greater or equal than
the length of csq
.