Constructors Summary |
---|
public PrintWriter(OutputStream out)Constructs a new {@code PrintWriter} with {@code 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. //$NON-NLS-1$
this(new OutputStreamWriter(out), false);
|
public PrintWriter(OutputStream out, boolean autoflush)Constructs a new {@code PrintWriter} with {@code out} as its target
stream. The parameter {@code autoflush} determines if the print writer
automatically flushes its contents to the target stream when a newline is
encountered.
this(new OutputStreamWriter(out), autoflush);
|
public PrintWriter(Writer wr)Constructs a new {@code PrintWriter} with {@code 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.
this(wr, false);
|
public PrintWriter(Writer wr, boolean autoflush)Constructs a new {@code PrintWriter} with {@code out} as its target
writer. The parameter {@code autoflush} determines if the print writer
automatically flushes its contents to the target writer when a newline is
encountered.
super(wr);
this.autoflush = autoflush;
out = wr;
|
public PrintWriter(File file)Constructs a new {@code PrintWriter} with {@code file} as its target. The
virtual machine's default character set is used for character encoding.
The print writer does not automatically flush its contents to the target
file when a newline is encountered. The output to the file is buffered.
// BEGIN android-modified
this(new OutputStreamWriter(
new BufferedOutputStream(
new FileOutputStream(file), 8192)),
false);
// END android-modified
|
public PrintWriter(File file, String csn)Constructs a new {@code PrintWriter} with {@code file} as its target. The
character set named {@code csn} is used for character encoding.
The print writer does not automatically flush its contents to the target
file when a newline is encountered. The output to the file is buffered.
// BEGIN android-modified
this(new OutputStreamWriter(
new BufferedOutputStream(
new FileOutputStream(file), 8192), csn),
false);
// END android-modified
|
public PrintWriter(String fileName)Constructs a new {@code PrintWriter} with the file identified by {@code
fileName} as its target. The virtual machine's default character set is
used for character encoding. The print writer does not automatically
flush its contents to the target file when a newline is encountered. The
output to the file is buffered.
// BEGIN android-modified
this(new OutputStreamWriter(
new BufferedOutputStream(
new FileOutputStream(fileName), 8192)),
false);
// END android-modified
|
public PrintWriter(String fileName, String csn)Constructs a new {@code PrintWriter} with the file identified by {@code
fileName} as its target. The character set named {@code csn} is used for
character encoding. The print writer does not automatically flush its
contents to the target file when a newline is encountered. The output to
the file is buffered.
// BEGIN android-modified
this(new OutputStreamWriter(
new BufferedOutputStream(
new FileOutputStream(fileName), 8192), csn),
false);
// END android-modified
|
Methods Summary |
---|
public java.io.PrintWriter | append(char c)Appends the character {@code c} to the target.
write(c);
return this;
|
public java.io.PrintWriter | append(java.lang.CharSequence csq)Appends the character sequence {@code csq} to the target. This
method works the same way as {@code PrintWriter.print(csq.toString())}.
If {@code csq} is {@code null}, then the string "null" is written
to the target.
if (null == csq) {
append(TOKEN_NULL, 0, TOKEN_NULL.length());
} else {
append(csq, 0, csq.length());
}
return this;
|
public java.io.PrintWriter | append(java.lang.CharSequence csq, int start, int end)Appends a subsequence of the character sequence {@code csq} to the
target. This method works the same way as {@code
PrintWriter.print(csq.subsequence(start, end).toString())}. If {@code
csq} is {@code null}, then the specified subsequence of the string "null"
will be written to the target.
if (null == csq) {
csq = TOKEN_NULL;
}
String output = csq.subSequence(start, end).toString();
write(output, 0, output.length());
return this;
|
public boolean | checkError()Flushes this writer and returns the value of the error flag.
if (out != null) {
flush();
}
return ioError;
|
public void | close()Closes this print writer. Flushes this writer and then closes the target.
If an I/O error occurs, this writer's error flag is set to {@code true}.
synchronized (lock) {
if (out != null) {
try {
out.close();
} catch (IOException e) {
setError();
}
out = null;
}
}
|
private final void | doWrite(char[] buf, int offset, int count)
// BEGIN android-note
// changed array notation to be consistent with the rest of harmony
// END android-note
synchronized (lock) {
if (out != null) {
try {
out.write(buf, offset, count);
} catch (IOException e) {
setError();
}
} else {
setError();
}
}
|
public void | flush()Ensures that all pending data is sent out to the target. It also
flushes the target. If an I/O error occurs, this writer's error
state is set to {@code true}.
synchronized (lock) {
if (out != null) {
try {
out.flush();
} catch (IOException e) {
setError();
}
} else {
setError();
}
}
|
public java.io.PrintWriter | format(java.lang.String format, java.lang.Object args)Writes a string formatted by an intermediate {@code Formatter} to the
target using the specified format string and arguments. For the locale,
the default value of the current virtual machine instance is used. If
automatic flushing is enabled then the buffer is flushed as well.
return format(Locale.getDefault(), format, args);
|
public java.io.PrintWriter | format(java.util.Locale l, java.lang.String format, java.lang.Object args)Writes a string formatted by an intermediate {@code Formatter} to the
target using the specified locale, format string and arguments. If
automatic flushing is enabled then this writer is flushed.
if (format == null) {
throw new NullPointerException(Msg.getString("K0351")); //$NON-NLS-1$
}
new Formatter(this, l).format(format, args);
if (autoflush) {
flush();
}
return this;
|
private void | newline()Print a new line String onto the writer, flushing if autoflush enabled.
print(lineSeparator);
if (autoflush) {
flush();
}
|
public void | print(char[] charArray)Prints the string representation of the specified character array
to the target.
print(new String(charArray, 0, charArray.length));
|
public void | print(char ch)Prints the string representation of the specified character to the
target.
print(String.valueOf(ch));
|
public void | print(double dnum)Prints the string representation of the specified double to the target.
print(String.valueOf(dnum));
|
public void | print(float fnum)Prints the string representation of the specified float to the target.
print(String.valueOf(fnum));
|
public void | print(int inum)Prints the string representation of the specified integer to the target.
print(String.valueOf(inum));
|
public void | print(long lnum)Prints the string representation of the specified long to the target.
print(String.valueOf(lnum));
|
public void | print(java.lang.Object obj)Prints the string representation of the specified object to the target.
print(String.valueOf(obj));
|
public void | print(java.lang.String str)Prints a string to the target. The string is converted to an array of
bytes using the encoding chosen during the construction of this writer.
The bytes are then written to the target with {@code write(int)}.
If an I/O error occurs, this writer's error flag is set to {@code true}.
write(str != null ? str : String.valueOf((Object) null));
|
public void | print(boolean bool)Prints the string representation of the specified boolean to the target.
print(String.valueOf(bool));
|
public java.io.PrintWriter | printf(java.lang.String format, java.lang.Object args)Prints a formatted string. The behavior of this method is the same as
this writer's {@code #format(String, Object...)} method. For the locale,
the default value of the current virtual machine instance is used.
return format(format, args);
|
public java.io.PrintWriter | printf(java.util.Locale l, java.lang.String format, java.lang.Object args)Prints a formatted string. The behavior of this method is the same as
this writer's {@code #format(Locale, String, Object...)} method.
return format(l, format, args);
|
public void | println()Prints the string representation of the system property {@code
"line.separator"} to the target. Flushes this writer if the autoflush
flag is set to {@code true}.
synchronized (lock) {
newline();
}
|
public void | println(char[] charArray)Prints the string representation of the specified character array
followed by the system property {@code "line.separator"} to the target.
Flushes this writer if the autoflush flag is set to {@code true}.
println(new String(charArray, 0, charArray.length));
|
public void | println(char ch)Prints the string representation of the specified character followed by
the system property {@code "line.separator"} to the target. Flushes this
writer if the autoflush flag is set to {@code true}.
println(String.valueOf(ch));
|
public void | println(double dnum)Prints the string representation of the specified double followed by the
system property {@code "line.separator"} to the target. Flushes this
writer if the autoflush flag is set to {@code true}.
println(String.valueOf(dnum));
|
public void | println(float fnum)Prints the string representation of the specified float followed by the
system property {@code "line.separator"} to the target. Flushes this
writer if the autoflush flag is set to {@code true}.
println(String.valueOf(fnum));
|
public void | println(int inum)Prints the string representation of the specified integer followed by the
system property {@code "line.separator"} to the target. Flushes this
writer if the autoflush flag is set to {@code true}.
println(String.valueOf(inum));
|
public void | println(long lnum)Prints the string representation of the specified long followed by the
system property {@code "line.separator"} to the target. Flushes this
writer if the autoflush flag is set to {@code true}.
println(String.valueOf(lnum));
|
public void | println(java.lang.Object obj)Prints the string representation of the specified object followed by the
system property {@code "line.separator"} to the target. Flushes this
writer if the autoflush flag is set to {@code true}.
println(String.valueOf(obj));
|
public void | println(java.lang.String str)Prints a string followed by the system property {@code "line.separator"}
to the target. The string is converted to an array of bytes using the
encoding chosen during the construction of this writer. The bytes are
then written to the target with {@code write(int)}. Finally, this writer
is flushed if the autoflush flag is set to {@code true}.
If an I/O error occurs, this writer's error flag is set to {@code true}.
synchronized (lock) {
print(str);
newline();
}
|
public void | println(boolean bool)Prints the string representation of the specified boolean followed by the
system property {@code "line.separator"} to the target. Flushes this
writer if the autoflush flag is set to {@code true}.
println(String.valueOf(bool));
|
protected void | setError()Sets the error flag of this writer to {@code true}.
synchronized (lock) {
ioError = true;
}
|
public void | write(char[] buf)Writes the character buffer {@code buf} to the target.
// BEGIN android-note
// changed array notation to be consistent with the rest of harmony
// END android-note
write(buf, 0, buf.length);
|
public void | write(char[] buf, int offset, int count)Writes {@code count} characters from {@code buffer} starting at {@code
offset} to the target.
This writer's error flag is set to {@code true} if this writer is closed
or an I/O error occurs.
// BEGIN android-note
// changed array notation to be consistent with the rest of harmony
// END android-note
doWrite(buf, offset, count);
|
public void | write(int oneChar)Writes one character to the target. Only the two least significant bytes
of the integer {@code oneChar} are written.
This writer's error flag is set to {@code true} if this writer is closed
or an I/O error occurs.
doWrite(new char[] { (char) oneChar }, 0, 1);
|
public void | write(java.lang.String str)Writes the characters from the specified string to the target.
write(str.toCharArray());
|
public void | write(java.lang.String str, int offset, int count)Writes {@code count} characters from {@code str} starting at {@code
offset} to the target.
write(str.substring(offset, offset + count).toCharArray());
|