|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.io.OutputStream
java.io.FilterOutputStream
java.io.PrintStream
public class PrintStream
PrintStream is a class which takes an OutputStream and provides convenience methods for printing common data types in a human readable format on the stream. This is not to be confused with DataOutputStream which is used for encoding common data types so that they can be read back in. No IOExceptions are thrown by this class. Instead, callers should call checkError() to see if a problem has been encountered in this Stream.
| Field Summary |
|---|
| Fields inherited from class java.io.FilterOutputStream |
|---|
out |
| Constructor Summary | |
|---|---|
PrintStream(File file)
Constructs a new PrintStream on the file file. |
|
PrintStream(File file,
String csn)
Constructs a new PrintStream on the file file. |
|
PrintStream(OutputStream out)
Constructs a new PrintStream on the OutputStream out. |
|
PrintStream(OutputStream out,
boolean autoflush)
Constructs a new PrintStream on the OutputStream out. |
|
PrintStream(OutputStream out,
boolean autoflush,
String enc)
Constructs a new PrintStream on the OutputStream out. |
|
PrintStream(String fileName)
Constructs a new PrintStream on the file the name of which is fileName. |
|
PrintStream(String fileName,
String csn)
Constructs a new PrintStream on the file the name of which is fileName. |
|
| Method Summary | |
|---|---|
PrintStream |
append(char c)
Append a char c to the PrintStream. |
PrintStream |
append(CharSequence csq)
Append a CharSequence csq to the PrintStream. |
PrintStream |
append(CharSequence csq,
int start,
int end)
Append a subsequence of a CharSequence csq to the
PrintStream. |
boolean |
checkError()
Returns a boolean indicating whether or not this PrintStream has encountered an error. |
void |
close()
Close this PrintStream. |
void |
flush()
Flush this PrintStream to ensure all pending data is sent out to the target OutputStream. |
PrintStream |
format(Locale l,
String format,
Object... args)
Writes a string formatted by an intermediate Formatter to
this stream using the given format string and arguments. |
PrintStream |
format(String format,
Object... args)
Writes a string formatted by an intermediate Formatter to
this stream using the given format string and arguments. |
void |
print(boolean bool)
Prints the String representation of the boolean parameter
bool to the target OutputStream. |
void |
print(char ch)
Prints the String representation of the character parameter ch to the target OutputStream. |
void |
print(char[] charArray)
Prints the String representation of the character array parameter charArray to the target OutputStream. |
void |
print(double dnum)
Prints the String representation of the double parameter
dnum to the target OutputStream. |
void |
print(float fnum)
Prints the String representation of the float parameter
fnum to the target OutputStream. |
void |
print(int inum)
Obtains the int argument as a String and
prints it to the target OutputStream. |
void |
print(long lnum)
Prints the String representation of the long parameter
lnum to the target OutputStream. |
void |
print(Object obj)
Prints the String representation of the Object parameter obj
to the target OutputStream. |
void |
print(String str)
Prints the String representation of the String parameter
str to the target OutputStream. |
PrintStream |
printf(Locale l,
String format,
Object... args)
Prints a formatted string. |
PrintStream |
printf(String format,
Object... args)
Prints a formatted string. |
void |
println()
Prints the String representation of the System property "line.separator" to the target OutputStream. |
void |
println(boolean bool)
Prints the String representation of the boolean parameter
bool to the target OutputStream followed by the System
property "line.separator". |
void |
println(char ch)
Prints the String representation of the character parameter ch to the target OutputStream followed by the System
property "line.separator". |
void |
println(char[] charArray)
Prints the String representation of the character array parameter charArray to the target OutputStream followed by the
System property "line.separator". |
void |
println(double dnum)
Prints the String representation of the double parameter
dnum to the target OutputStream followed by the System
property "line.separator". |
void |
println(float fnum)
Prints the String representation of the float parameter
fnum to the target OutputStream followed by the System
property "line.separator". |
void |
println(int inum)
Obtains the int argument as a String and
prints it to the target OutputStream followed by the System
property "line.separator". |
void |
println(long lnum)
Prints the String representation of the long parameter
lnum to the target OutputStream followed by the System
property "line.separator". |
void |
println(Object obj)
Prints the String representation of the Object parameter
obj to the target OutputStream followed by the System
property "line.separator". |
void |
println(String str)
Prints the String representation of the String parameter
str to the target OutputStream followed by the System
property "line.separator". |
protected void |
setError()
|
void |
write(byte[] buffer,
int offset,
int count)
Writes count bytes from the byte array
buffer starting at offset to this
PrintStream. |
void |
write(int oneByte)
Writes the specified byte oneByte to this PrintStream. |
| Methods inherited from class java.io.FilterOutputStream |
|---|
write |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public PrintStream(OutputStream out)
out. All
writes to the target can now take place through this PrintStream. By
default, the PrintStream is set to not autoflush when a newline is
encountered.
out - the OutputStream to provide convenience methods on.
public PrintStream(OutputStream out,
boolean autoflush)
out. All
writes to the target can now take place through this PrintStream. The
PrintStream is set to not autoflush if autoflush is
true.
out - the OutputStream to provide convenience methods on.autoflush - indicates whether or not to flush contents upon encountering a
newline sequence.
public PrintStream(OutputStream out,
boolean autoflush,
String enc)
throws UnsupportedEncodingException
out. All
writes to the target can now take place through this PrintStream. The
PrintStream is set to not autoflush if autoflush is
true.
out - the OutputStream to provide convenience methods on.autoflush - indicates whether or not to flush contents upon encountering a
newline sequence.enc - the non-null String describing the desired character encoding.
UnsupportedEncodingException - If the chosen encoding is not supported
public PrintStream(File file)
throws FileNotFoundException
file. All writes
to the target can now take place through this PrintStream. Its encoding
character set is the default charset in the VM.
file - the file to provide convenience methods on.
FileNotFoundException - if the file does not exist or cannot be opened to write. Or
the file cannot be created or any problem when open the file
to write.
SecurityException - if the security manager exists and denies the write to the
file.
public PrintStream(File file,
String csn)
throws FileNotFoundException,
UnsupportedEncodingException
file. All writes
to the target can now take place through this PrintStream. Its encoding
character set name is csn.
file - the file to provide convenience methods on.csn - the character set name
FileNotFoundException - if the file does not exist or cannot be opened to write. Or
the file cannot be created or any problem when open the file
to write.
SecurityException - if the security manager exists and denies the write to the
file.
UnsupportedEncodingException - if the chosen character set is not supported
public PrintStream(String fileName)
throws FileNotFoundException
fileName.
All writes to the target can now take place through this PrintStream. Its
encoding character set is the default charset in the VM.
fileName - the file to provide convenience methods on.
FileNotFoundException - if the file does not exist or cannot be opened to write. Or
the file cannot be created or any problem when open the file
to write.
SecurityException - if the security manager exists and denies the write to the
file.
public PrintStream(String fileName,
String csn)
throws FileNotFoundException,
UnsupportedEncodingException
fileName.
All writes to the target can now take place through this PrintStream. Its
encoding character set name is csn.
fileName - the file to provide convenience methods on.csn - the character set name
FileNotFoundException - if the file does not exist or cannot be opened to write. Or
the file cannot be created or any problem when open the file
to write.
SecurityException - if the security manager exists and denies the write to the
file.
UnsupportedEncodingException - if the chosen character set is not supported| Method Detail |
|---|
public boolean checkError()
true if an error occurred in this PrintStream,
false otherwise.public void close()
true.
close in interface Closeableclose in class FilterOutputStreampublic void flush()
true.
flush in interface Flushableflush in class FilterOutputStream
public PrintStream format(String format,
Object... args)
Formatter to
this stream using the given format string and arguments.
The method uses the default for the current JVM instance locale, as if it
is specified by the Locale.getDefault() call.
format - A format string.args - The arguments list. If there are more arguments than those
specified by the format string, then the additional arguments
are ignored.
IllegalFormatException - If the format string is illegal or incompatible with the
arguments or the arguments are less than those required by
the format string or any other illegal situation.
NullPointerException - If the given format is null.
public PrintStream format(Locale l,
String format,
Object... args)
Formatter to
this stream using the given format string and arguments.
l - The locale used in the method. If locale is null, then no
localization will be applied.format - A format string.args - The arguments list. If there are more arguments than those
specified by the format string, then the additional arguments
are ignored.
IllegalFormatException - If the format string is illegal or incompatible with the
arguments or the arguments are less than those required by
the format string or any other illegal situation.
NullPointerException - If the given format is null.
public PrintStream printf(String format,
Object... args)
format(String format, Object... args)
method.
The method uses the default for the current JVM instance locale, as if it
is specified by the Locale.getDefault() call.
format - A format string.args - The arguments list. If there are more arguments than those
specified by the format string, then the additional arguments
are ignored.
IllegalFormatException - If the format string is illegal or incompatible with the
arguments or the arguments are less than those required by
the format string or any other illegal situation.
NullPointerException - If the given format is null.
public PrintStream printf(Locale l,
String format,
Object... args)
format(Locale l, String format, Object... args) method.
l - The locale used in the method. If locale is null, then no
localization will be applied.format - A format string.args - The arguments list. If there are more arguments than those
specified by the format string, then the additional arguments
are ignored.
IllegalFormatException - If the format string is illegal or incompatible with the
arguments or the arguments are less than those required by
the format string or any other illegal situation.
NullPointerException - If the given format is null.public void print(char[] charArray)
charArray to the target OutputStream.
charArray - the character array to print on this PrintStream.public void print(char ch)
ch to the target OutputStream.
ch - the character to print on this PrintStream.public void print(double dnum)
double parameter
dnum to the target OutputStream.
dnum - the double to print on this PrintStream.public void print(float fnum)
float parameter
fnum to the target OutputStream.
fnum - the float to print on this PrintStream.public void print(int inum)
int argument as a String and
prints it to the target OutputStream.
inum - the int to print on this PrintStream.public void print(long lnum)
long parameter
lnum to the target OutputStream.
lnum - the long to print on this PrintStream.public void print(Object obj)
obj
to the target OutputStream.
obj - the Object to print on this PrintStream.public void print(String str)
String parameter
str to the target OutputStream.
str - the String to print on this PrintStream.public void print(boolean bool)
boolean parameter
bool to the target OutputStream.
bool - the boolean to print on this PrintStream.public void println()
"line.separator" to the target OutputStream.
public void println(char[] charArray)
charArray to the target OutputStream followed by the
System property "line.separator".
charArray - the character array to print on this PrintStream.public void println(char ch)
ch to the target OutputStream followed by the System
property "line.separator".
ch - the character to print on this PrintStream.public void println(double dnum)
double parameter
dnum to the target OutputStream followed by the System
property "line.separator".
dnum - the double to print on this PrintStream.public void println(float fnum)
float parameter
fnum to the target OutputStream followed by the System
property "line.separator".
fnum - the float to print on this PrintStream.public void println(int inum)
int argument as a String and
prints it to the target OutputStream followed by the System
property "line.separator".
inum - the int to print on this PrintStream.public void println(long lnum)
long parameter
lnum to the target OutputStream followed by the System
property "line.separator".
lnum - the long to print on this PrintStream.public void println(Object obj)
Object parameter
obj to the target OutputStream followed by the System
property "line.separator".
obj - the Object to print on this PrintStream.public void println(String str)
String parameter
str to the target OutputStream followed by the System
property "line.separator".
str - the String to print on this PrintStream.public void println(boolean bool)
boolean parameter
bool to the target OutputStream followed by the System
property "line.separator".
bool - the boolean to print on this PrintStream.protected void setError()
public void write(byte[] buffer,
int offset,
int count)
count bytes from the byte array
buffer starting at offset to this
PrintStream. This implementation writes the buffer to the
target OutputStream and if this PrintStream is set to autoflush, flushes
it. If an error occurs, set an error in this PrintStream to
true.
write in class FilterOutputStreambuffer - the buffer to be writtenoffset - offset in buffer to get bytescount - number of bytes in buffer to write
IndexOutOfBoundsException - If offset or count are outside of bounds.public void write(int oneByte)
oneByte to this PrintStream.
Only the low order byte of oneByte is written. This
implementation writes oneByte to the target OutputStream.
If oneByte is equal to the character '\n'
and this PrintSteam is set to autoflush, the target OutputStream is
flushed.
write in class FilterOutputStreamoneByte - the byte to be writtenpublic PrintStream append(char c)
c to the PrintStream. The
PrintStream.append(c) works the same way as
PrintStream.print(c).
append in interface Appendablec - The character appended to the PrintStream.
public PrintStream append(CharSequence csq)
csq to the PrintStream. The
PrintStream.append(csq) works the same way as
PrintStream.print(csq.toString()). If csq
is null, then a CharSequence just contains then "null" will be
substituted for csq.
append in interface Appendablecsq - The CharSequence appended to the PrintStream.
public PrintStream append(CharSequence csq,
int start,
int end)
csq to the
PrintStream. The first char and the last char of the subsequnce is
specified by the parameter start and end.
The PrintStream.append(csq) works the same way as
PrintStream.print (csqcsq.subSequence(start,
end).toString). If csq is null, then
"null" will be substituted for csq.
append in interface Appendablecsq - The CharSequence appended to the PrintStream.start - The index of the first char in the CharSequence appended to
the PrintStream.end - The index of the char after the last one in the CharSequence
appended to the PrintStream.
IndexOutOfBoundsException - If start is less than end, end is greater than the length of
the CharSequence, or start or end is negative.
|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||