Constructors Summary |
---|
public PrintStream(OutputStream out)Constructs a new {@code PrintStream} with {@code out} as its target
stream. By default, the new print stream does not automatically flush its
contents to the target stream when a newline is encountered. //$NON-NLS-1$
// private Formatter formatter;
super(out);
if (out == null) {
throw new NullPointerException();
}
|
public PrintStream(OutputStream out, boolean autoflush)Constructs a new {@code PrintStream} with {@code out} as its target
stream. The parameter {@code autoflush} determines if the print stream
automatically flushes its contents to the target stream when a newline is
encountered.
super(out);
if (out == null) {
throw new NullPointerException();
}
this.autoflush = autoflush;
|
public PrintStream(OutputStream out, boolean autoflush, String enc)Constructs a new {@code PrintStream} with {@code out} as its target
stream and using the character encoding {@code enc} while writing. The
parameter {@code autoflush} determines if the print stream automatically
flushes its contents to the target stream when a newline is encountered.
super(out);
if (out == null || enc == null) {
throw new NullPointerException();
}
this.autoflush = autoflush;
if (!Charset.isSupported(enc)) {
throw new UnsupportedEncodingException(enc);
}
encoding = enc;
|
public PrintStream(File file)Constructs a new {@code PrintStream} with {@code file} as its target. The
virtual machine's default character set is used for character encoding.
super(new FileOutputStream(file));
|
public PrintStream(File file, String csn)Constructs a new {@code PrintStream} with {@code file} as its target. The
character set named {@code csn} is used for character encoding.
super(new FileOutputStream(file));
if (csn == null) {
throw new NullPointerException();
}
if (!Charset.isSupported(csn)) {
throw new UnsupportedEncodingException();
}
encoding = csn;
|
public PrintStream(String fileName)Constructs a new {@code PrintStream} with the file identified by
{@code fileName} as its target. The virtual machine's default character
set is used for character encoding.
this(new File(fileName));
|
public PrintStream(String fileName, String csn)Constructs a new {@code PrintStream} with the file identified by
{@code fileName} as its target. The character set named {@code csn} is
used for character encoding.
this(new File(fileName), csn);
|
Methods Summary |
---|
public java.io.PrintStream | append(char c)Appends the character {@code c} to the target stream. This method works
the same way as {@link #print(char)}.
print(c);
return this;
|
public java.io.PrintStream | append(java.lang.CharSequence csq)Appends the character sequence {@code csq} to the target stream. This
method works the same way as {@code PrintStream.print(csq.toString())}.
If {@code csq} is {@code null}, then the string "null" is written to the
target stream.
if (null == csq) {
print(TOKEN_NULL);
} else {
print(csq.toString());
}
return this;
|
public java.io.PrintStream | append(java.lang.CharSequence csq, int start, int end)Appends a subsequence of the character sequence {@code csq} to the target
stream. This method works the same way as {@code
PrintStream.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 stream.
if (null == csq) {
print(TOKEN_NULL.substring(start, end));
} else {
print(csq.subSequence(start, end).toString());
}
return this;
|
public boolean | checkError()Flushes this stream and returns the value of the error flag.
if (out != null) {
flush();
}
return ioError;
|
public synchronized void | close()Closes this print stream. Flushes this stream and then closes the target
stream. If an I/O error occurs, this stream's error state is set to
{@code true}.
flush();
if (out != null) {
try {
out.close();
out = null;
} catch (IOException e) {
setError();
}
}
|
public synchronized void | flush()Ensures that all pending data is sent out to the target stream. It also
flushes the target stream. If an I/O error occurs, this stream's error
state is set to {@code true}.
if (out != null) {
try {
out.flush();
return;
} catch (IOException e) {
// Ignored, fall through to setError
}
}
setError();
|
public java.io.PrintStream | format(java.lang.String format, java.lang.Object args)Writes a string formatted by an intermediate {@code Formatter} to the
target stream using the specified format string and arguments. For the
locale, the default value of the current virtual machine instance is
used.
return format(Locale.getDefault(), format, args);
|
public java.io.PrintStream | format(java.util.Locale l, java.lang.String format, java.lang.Object args)Writes a string formatted by an intermediate {@link Formatter} to this
stream using the specified locale, format string and arguments.
if (format == null) {
throw new NullPointerException(Msg.getString("K0351")); //$NON-NLS-1$
}
new Formatter(this, l).format(format, args);
return this;
|
private void | newline()Put the line separator String onto the print stream.
print(lineSeparator);
|
public void | print(char[] charArray)Prints the string representation of the specified character array
to the target stream.
print(new String(charArray, 0, charArray.length));
|
public void | print(char ch)Prints the string representation of the specified character to the target
stream.
print(String.valueOf(ch));
|
public void | print(double dnum)Prints the string representation of the specified double to the target
stream.
print(String.valueOf(dnum));
|
public void | print(float fnum)Prints the string representation of the specified float to the target
stream.
print(String.valueOf(fnum));
|
public void | print(int inum)Prints the string representation of the specified integer to the target
stream.
print(String.valueOf(inum));
|
public void | print(long lnum)Prints the string representation of the specified long to the target
stream.
print(String.valueOf(lnum));
|
public void | print(java.lang.Object obj)Prints the string representation of the specified object to the target
stream.
print(String.valueOf(obj));
|
public synchronized void | print(java.lang.String str)Prints a string to the target stream. The string is converted to an array
of bytes using the encoding chosen during the construction of this
stream. The bytes are then written to the target stream with
{@code write(int)}.
If an I/O error occurs, this stream's error state is set to {@code true}.
if (out == null) {
setError();
return;
}
if (str == null) {
print("null"); //$NON-NLS-1$
return;
}
try {
if (encoding == null) {
write(str.getBytes());
} else {
write(str.getBytes(encoding));
}
} catch (IOException e) {
setError();
}
|
public void | print(boolean bool)Prints the string representation of the specified boolean to the target
stream.
print(String.valueOf(bool));
|
public java.io.PrintStream | printf(java.lang.String format, java.lang.Object args)Prints a formatted string. The behavior of this method is the same as
this stream'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.PrintStream | 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 stream'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 stream.
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
stream.
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 stream.
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 stream.
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 stream.
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 stream.
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 stream.
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 stream.
println(String.valueOf(obj));
|
public synchronized void | println(java.lang.String str)Prints a string followed by the system property {@code "line.separator"}
to the target stream. The string is converted to an array of bytes using
the encoding chosen during the construction of this stream. The bytes are
then written to the target stream with {@code write(int)}.
If an I/O error occurs, this stream's error state is set to {@code true}.
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 stream.
println(String.valueOf(bool));
|
protected void | setError()Sets the error flag of this print stream to {@code true}.
ioError = true;
|
public void | write(byte[] buffer, int offset, int count)Writes {@code count} bytes from {@code buffer} starting at {@code offset}
to the target stream. If autoflush is set, this stream gets flushed after
writing the buffer.
This stream's error flag is set to {@code true} if this stream is closed
or an I/O error occurs.
// BEGIN android-changed
if (buffer == null) {
throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
}
// avoid int overflow
// Exception priorities (in case of multiple errors) differ from
// RI, but are spec-compliant.
// removed redundant check, used (offset | count) < 0
// instead of (offset < 0) || (count < 0) to safe one operation
if ((offset | count) < 0 || count > buffer.length - offset) {
throw new ArrayIndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
}
// END android-changed
synchronized (this) {
if (out == null) {
setError();
return;
}
try {
out.write(buffer, offset, count);
if (autoflush) {
flush();
}
} catch (IOException e) {
setError();
}
}
|
public synchronized void | write(int oneByte)Writes one byte to the target stream. Only the least significant byte of
the integer {@code oneByte} is written. This stream is flushed if
{@code oneByte} is equal to the character {@code '\n'} and this stream is
set to autoflush.
This stream's error flag is set to {@code true} if it is closed or an I/O
error occurs.
if (out == null) {
setError();
return;
}
try {
out.write(oneByte);
if (autoflush && (oneByte & 0xFF) == '\n") {
flush();
}
} catch (IOException e) {
setError();
}
|