public class PrintStreamWithHistory extends PrintStream
PrintStream
that provides for a history
recall function and some other features making I/O testing a bit
easier to perform. See the documentation for PrintStream
for
more thorough details on what methods are provided.out
Constructor and Description |
---|
PrintStreamWithHistory(File file)
Creates a new print stream, without automatic line flushing, with the
specified file.
|
PrintStreamWithHistory(File file,
String csn)
Creates a new print stream, without automatic line flushing, with the
specified file and charset.
|
PrintStreamWithHistory(OutputStream out)
Create a new print stream.
|
PrintStreamWithHistory(OutputStream out,
boolean autoFlush)
Create a new print stream.
|
PrintStreamWithHistory(OutputStream out,
boolean autoFlush,
String encoding)
Create a new print stream.
|
PrintStreamWithHistory(String fileName)
Creates a new print stream, without automatic line flushing, with the
specified file name.
|
PrintStreamWithHistory(String fileName,
String csn)
Creates a new print stream, without automatic line flushing, with the
specified file name and charset.
|
Modifier and Type | Method and Description |
---|---|
void |
clearHistory()
Reset this object's history to be empty, just as when the object was
first created.
|
String |
getHistory()
Retrieve the text history of what has been sent to this PrintStream.
|
boolean |
getNormalizeLineEndings()
Returns whether this object's history has normalized unix-style
line endings, or the raw line endings generated by printing.
|
void |
setNormalizeLineEndings(boolean value)
Set whether this object's history will have normalized unix-style
line endings, or the raw line endings generated by printing.
|
void |
write(byte[] buf,
int off,
int len)
Write
len bytes from the specified byte array starting at
offset off to this stream. |
void |
write(int b)
Write the specified byte to this stream.
|
append, append, append, checkError, clearError, close, flush, format, format, print, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, println, setError
write
public PrintStreamWithHistory(OutputStream out)
out
- The output stream to which values and objects will be
printedPrintWriter.PrintWriter(java.io.OutputStream)
public PrintStreamWithHistory(OutputStream out, boolean autoFlush)
out
- The output stream to which values and objects will be
printedautoFlush
- A boolean; if true, the output buffer will be flushed
whenever a byte array is written, one of the
println
methods is invoked, or a newline
character or byte ('\n'
) is writtenPrintWriter.PrintWriter(java.io.OutputStream, boolean)
public PrintStreamWithHistory(OutputStream out, boolean autoFlush, String encoding) throws UnsupportedEncodingException
out
- The output stream to which values and objects will be
printedautoFlush
- A boolean; if true, the output buffer will be flushed
whenever a byte array is written, one of the
println
methods is invoked, or a newline
character or byte ('\n'
) is writtenencoding
- The name of a supported
character encodingUnsupportedEncodingException
- If the named encoding is not supportedpublic PrintStreamWithHistory(String fileName) throws FileNotFoundException
OutputStreamWriter
, which will encode characters using the
default charset
for this instance of the Java virtual machine.fileName
- The name of the file to use as the destination of this print
stream. If the file exists, then it will be truncated to
zero size; otherwise, a new file will be created. The output
will be written to the file and is buffered.FileNotFoundException
- If the given file object does not denote an existing, writable
regular file and a new regular file of that name cannot be
created, or if some other error occurs while opening or
creating the fileSecurityException
- If a security manager is present and checkWrite(fileName)
denies write
access to the filepublic PrintStreamWithHistory(String fileName, String csn) throws FileNotFoundException, UnsupportedEncodingException
OutputStreamWriter
, which will encode characters using the provided
charset.fileName
- The name of the file to use as the destination of this print
stream. If the file exists, then it will be truncated to
zero size; otherwise, a new file will be created. The output
will be written to the file and is buffered.csn
- The name of a supported charsetFileNotFoundException
- If the given file object does not denote an existing, writable
regular file and a new regular file of that name cannot be
created, or if some other error occurs while opening or
creating the fileSecurityException
- If a security manager is present and checkWrite(fileName)
denies write
access to the fileUnsupportedEncodingException
- If the named charset is not supportedpublic PrintStreamWithHistory(File file) throws FileNotFoundException
OutputStreamWriter
,
which will encode characters using the default charset for this
instance of the Java virtual machine.file
- The file to use as the destination of this print stream. If the
file exists, then it will be truncated to zero size; otherwise,
a new file will be created. The output will be written to the
file and is buffered.FileNotFoundException
- If the given file object does not denote an existing, writable
regular file and a new regular file of that name cannot be
created, or if some other error occurs while opening or
creating the fileSecurityException
- If a security manager is present and checkWrite(file.getPath())
denies write access to the filepublic PrintStreamWithHistory(File file, String csn) throws FileNotFoundException, UnsupportedEncodingException
OutputStreamWriter
, which will encode characters using the provided
charset.file
- The file to use as the destination of this print stream. If the
file exists, then it will be truncated to zero size; otherwise,
a new file will be created. The output will be written to the
file and is buffered.csn
- The name of a supported charsetFileNotFoundException
- If the given file object does not denote an existing, writable
regular file and a new regular file of that name cannot be
created, or if some other error occurs while opening or
creating the fileSecurityException
- If a security manager is presentand checkWrite(file.getPath())
denies write access to the fileUnsupportedEncodingException
- If the named charset is not supportedpublic String getHistory()
clearHistory()
method resets the history to be empty, just
as when the object was first created. Note that newline characters
in the history are always represented by '\n', regardless of what
value the system line.separator
property has.public void clearHistory()
getHistory()
.public void setNormalizeLineEndings(boolean value)
value
- If true, the retrieved history will have all line
endings automatically standardized to unix-style
("\n") line endings; if fase, the retrieved history
will be presented without any modifications, using
whatever (platform-specific) line endings were printed
to this object.public boolean getNormalizeLineEndings()
public void write(int b)
flush
method will be
invoked.
Note that the byte is written as given; to write a character that
will be translated according to the platform's default character
encoding, use the print(char)
or println(char)
methods.
write
in class PrintStream
b
- The byte to be writtenPrintStream.print(char)
,
PrintStream.println(char)
public void write(byte[] buf, int off, int len)
len
bytes from the specified byte array starting at
offset off
to this stream. If automatic flushing is
enabled then the flush
method will be invoked.
Note that the bytes will be written as given; to write characters
that will be translated according to the platform's default character
encoding, use the print(char)
or println(char)
methods.
write
in class PrintStream
buf
- A byte arrayoff
- Offset from which to start taking byteslen
- Number of bytes to write