Build 1.0_r1(from source)

java.io
Class PrintStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by java.io.PrintStream
All Implemented Interfaces:
Closeable, Flushable, Appendable
Direct Known Subclasses:
String.ConsolePrintStream

public class PrintStream
extends FilterOutputStream
implements Appendable, Closeable

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 isfileName.
PrintStream(String fileName, String csn)
          Constructs a new PrintStream on the file the name of which isfileName.
 
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

PrintStream

public PrintStream(OutputStream out)
Constructs a new PrintStream on the OutputStream 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.

Parameters:
out - the OutputStream to provide convenience methods on.

PrintStream

public PrintStream(OutputStream out,
                   boolean autoflush)
Constructs a new PrintStream on the OutputStream out. All writes to the target can now take place through this PrintStream. The PrintStream is set to not autoflush if autoflush is true.

Parameters:
out - the OutputStream to provide convenience methods on.
autoflush - indicates whether or not to flush contents upon encountering a newline sequence.

PrintStream

public PrintStream(OutputStream out,
                   boolean autoflush,
                   String enc)
            throws UnsupportedEncodingException
Constructs a new PrintStream on the OutputStream out. All writes to the target can now take place through this PrintStream. The PrintStream is set to not autoflush if autoflush is true.

Parameters:
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.
Throws:
UnsupportedEncodingException - If the chosen encoding is not supported

PrintStream

public PrintStream(File file)
            throws FileNotFoundException
Constructs a new PrintStream on the file file. All writes to the target can now take place through this PrintStream. Its encoding character set is the default charset in the VM.

Parameters:
file - the file to provide convenience methods on.
Throws:
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.

PrintStream

public PrintStream(File file,
                   String csn)
            throws FileNotFoundException,
                   UnsupportedEncodingException
Constructs a new PrintStream on the file file. All writes to the target can now take place through this PrintStream. Its encoding character set name is csn.

Parameters:
file - the file to provide convenience methods on.
csn - the character set name
Throws:
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

PrintStream

public PrintStream(String fileName)
            throws FileNotFoundException
Constructs a new PrintStream on the file the name of which isfileName. All writes to the target can now take place through this PrintStream. Its encoding character set is the default charset in the VM.

Parameters:
fileName - the file to provide convenience methods on.
Throws:
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.

PrintStream

public PrintStream(String fileName,
                   String csn)
            throws FileNotFoundException,
                   UnsupportedEncodingException
Constructs a new PrintStream on the file the name of which isfileName. All writes to the target can now take place through this PrintStream. Its encoding character set name is csn.

Parameters:
fileName - the file to provide convenience methods on.
csn - the character set name
Throws:
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

checkError

public boolean checkError()
Returns a boolean indicating whether or not this PrintStream has encountered an error. If so, the receiver should probably be closed since further writes will not actually take place. A side effect of calling checkError is that the target OutputStream is flushed.

Returns:
true if an error occurred in this PrintStream, false otherwise.

close

public void close()
Close this PrintStream. This implementation flushes and then closes the target stream. If an error occurs, set an error in this PrintStream to true.

Specified by:
close in interface Closeable
Overrides:
close in class FilterOutputStream

flush

public void flush()
Flush this PrintStream to ensure all pending data is sent out to the target OutputStream. This implementation flushes the target OutputStream. If an error occurs, set an error in this PrintStream to true.

Specified by:
flush in interface Flushable
Overrides:
flush in class FilterOutputStream

format

public PrintStream format(String format,
                          Object... args)
Writes a string formatted by an intermediate 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.

Parameters:
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.
Returns:
This stream.
Throws:
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.

format

public 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.

Parameters:
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.
Returns:
This stream.
Throws:
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.

printf

public PrintStream printf(String format,
                          Object... args)
Prints a formatted string. The behavior of this method is the same as this stream's 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.

Parameters:
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.
Returns:
This stream.
Throws:
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.

printf

public PrintStream printf(Locale l,
                          String format,
                          Object... args)
Prints a formatted string. The behavior of this method is the same as this writer's format(Locale l, String format, Object... args) method.

Parameters:
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.
Returns:
This stream.
Throws:
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.

print

public void print(char[] charArray)
Prints the String representation of the character array parameter charArray to the target OutputStream.

Parameters:
charArray - the character array to print on this PrintStream.

print

public void print(char ch)
Prints the String representation of the character parameter ch to the target OutputStream.

Parameters:
ch - the character to print on this PrintStream.

print

public void print(double dnum)
Prints the String representation of the double parameter dnum to the target OutputStream.

Parameters:
dnum - the double to print on this PrintStream.

print

public void print(float fnum)
Prints the String representation of the float parameter fnum to the target OutputStream.

Parameters:
fnum - the float to print on this PrintStream.

print

public void print(int inum)
Obtains the int argument as a String and prints it to the target OutputStream.

Parameters:
inum - the int to print on this PrintStream.

print

public void print(long lnum)
Prints the String representation of the long parameter lnum to the target OutputStream.

Parameters:
lnum - the long to print on this PrintStream.

print

public void print(Object obj)
Prints the String representation of the Object parameter obj to the target OutputStream.

Parameters:
obj - the Object to print on this PrintStream.

print

public void print(String str)
Prints the String representation of the String parameter str to the target OutputStream.

Parameters:
str - the String to print on this PrintStream.

print

public void print(boolean bool)
Prints the String representation of the boolean parameter bool to the target OutputStream.

Parameters:
bool - the boolean to print on this PrintStream.

println

public void println()
Prints the String representation of the System property "line.separator" to the target OutputStream.


println

public 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".

Parameters:
charArray - the character array to print on this PrintStream.

println

public void println(char ch)
Prints the String representation of the character parameter ch to the target OutputStream followed by the System property "line.separator".

Parameters:
ch - the character to print on this PrintStream.

println

public void println(double dnum)
Prints the String representation of the double parameter dnum to the target OutputStream followed by the System property "line.separator".

Parameters:
dnum - the double to print on this PrintStream.

println

public void println(float fnum)
Prints the String representation of the float parameter fnum to the target OutputStream followed by the System property "line.separator".

Parameters:
fnum - the float to print on this PrintStream.

println

public 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".

Parameters:
inum - the int to print on this PrintStream.

println

public void println(long lnum)
Prints the String representation of the long parameter lnum to the target OutputStream followed by the System property "line.separator".

Parameters:
lnum - the long to print on this PrintStream.

println

public void println(Object obj)
Prints the String representation of the Object parameter obj to the target OutputStream followed by the System property "line.separator".

Parameters:
obj - the Object to print on this PrintStream.

println

public void println(String str)
Prints the String representation of the String parameter str to the target OutputStream followed by the System property "line.separator".

Parameters:
str - the String to print on this PrintStream.

println

public void println(boolean bool)
Prints the String representation of the boolean parameter bool to the target OutputStream followed by the System property "line.separator".

Parameters:
bool - the boolean to print on this PrintStream.

setError

protected void setError()

write

public void write(byte[] buffer,
                  int offset,
                  int count)
Writes 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.

Overrides:
write in class FilterOutputStream
Parameters:
buffer - the buffer to be written
offset - offset in buffer to get bytes
count - number of bytes in buffer to write
Throws:
IndexOutOfBoundsException - If offset or count are outside of bounds.

write

public void write(int oneByte)
Writes the specified byte 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.

Overrides:
write in class FilterOutputStream
Parameters:
oneByte - the byte to be written

append

public PrintStream append(char c)
Append a char c to the PrintStream. The PrintStream.append(c) works the same way as PrintStream.print(c).

Specified by:
append in interface Appendable
Parameters:
c - The character appended to the PrintStream.
Returns:
The PrintStream.

append

public PrintStream append(CharSequence csq)
Append a CharSequence 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.

Specified by:
append in interface Appendable
Parameters:
csq - The CharSequence appended to the PrintStream.
Returns:
The PrintStream.

append

public PrintStream append(CharSequence csq,
                          int start,
                          int end)
Append a subsequence of a CharSequence 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.

Specified by:
append in interface Appendable
Parameters:
csq - 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.
Returns:
The PrintStream.
Throws:
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)

Please submit a feedback, bug or feature