com.reuters.msgtest.load.output.csv
Class ExcelCSVPrinter

java.lang.Object
  extended bycom.reuters.msgtest.load.output.csv.ExcelCSVPrinter
All Implemented Interfaces:
CSVPrint

public class ExcelCSVPrinter
extends java.lang.Object
implements CSVPrint

Print values as a comma separated list that can be read by the Excel spreadsheet. More information about this class is available from ostermiller.org.

Since:
ostermillerutils 1.00.00
Author:
Stephen Ostermiller http://ostermiller.org/contact.pl?regarding=Java+Utilities, Pierre Dittgen

Field Summary
protected  boolean alwaysQuote
          If auto flushing is enabled.
protected  boolean autoFlush
          If auto flushing is enabled.
protected  char delimiterChar
          Delimiter character written.
protected  boolean error
          true iff an error has occurred.
protected  boolean newLine
          True iff we just began a new line.
protected  java.io.Writer out
          The place that the values get written.
protected  char quoteChar
          Quoting character written.
 
Constructor Summary
ExcelCSVPrinter(java.io.OutputStream out)
          Create a printer that will print values to the given stream.
ExcelCSVPrinter(java.io.Writer out)
          Create a printer that will print values to the given stream.
ExcelCSVPrinter(java.io.Writer out, boolean alwaysQuote, boolean autoFlush)
          Create a printer that will print values to the given stream.
ExcelCSVPrinter(java.io.Writer out, char quote, char delimiter)
          Create a printer that will print values to the given stream.
ExcelCSVPrinter(java.io.Writer out, char quote, char delimiter, boolean alwaysQuote, boolean autoFlush)
          Create a printer that will print values to the given stream.
 
Method Summary
 void changeDelimiter(char newDelimiter)
          Change this printer so that it uses a new delimiter.
 void changeQuote(char newQuote)
          Change this printer so that it uses a new character for quoting.
 boolean checkError()
          Flush the stream if it's not closed and check its error state.
 void close()
          Close any underlying streams.
 void flush()
          Flush any data written out to underlying streams.
 void print(java.lang.String value)
          Print the string as the next value on the line.
 void print(java.lang.String[] values)
          Print a single line of comma separated values.
 void println()
          Output a blank line.
 void println(java.lang.String value)
          Print the string as the last value on the line.
 void println(java.lang.String[] values)
          Print a single line of comma separated values.
 void println(java.lang.String[][] values)
          Print several lines of comma separated values.
 void printlnComment(java.lang.String comment)
          Since ExcelCSV format does not support comments, this method will ignore the comment and start a new row.
 void setAlwaysQuote(boolean alwaysQuote)
          Set whether values printers should always be quoted, or whether the printer may, at its discretion, omit quotes around the value.
 void setAutoFlush(boolean autoFlush)
          Set flushing behavior.
 void write(java.lang.String value)
          Print the string as the next value on the line.
 void write(java.lang.String[] values)
          Print a single line of comma separated values.
 void writeln()
          Output a blank line.
 void writeln(java.lang.String value)
          Print the string as the last value on the line.
 void writeln(java.lang.String[] values)
          Print a single line of comma separated values.
 void writeln(java.lang.String[][] values)
          Print several lines of comma separated values.
 void writelnComment(java.lang.String comment)
          Since ExcelCSV format does not support comments, this method will ignore the comment and start a new row.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

autoFlush

protected boolean autoFlush
If auto flushing is enabled.

Since:
ostermillerutils 1.02.26

alwaysQuote

protected boolean alwaysQuote
If auto flushing is enabled.

Since:
ostermillerutils 1.02.26

error

protected boolean error
true iff an error has occurred.

Since:
ostermillerutils 1.02.26

delimiterChar

protected char delimiterChar
Delimiter character written.

Since:
ostermillerutils 1.02.18

quoteChar

protected char quoteChar
Quoting character written.

Since:
ostermillerutils 1.02.18

out

protected java.io.Writer out
The place that the values get written.

Since:
ostermillerutils 1.00.00

newLine

protected boolean newLine
True iff we just began a new line.

Since:
ostermillerutils 1.00.00
Constructor Detail

ExcelCSVPrinter

public ExcelCSVPrinter(java.io.OutputStream out)
Create a printer that will print values to the given stream. Character to byte conversion is done using the default character encoding. The delimiter will be the comma, the quote character will be double quotes, quotes will be used when needed, and auto flushing will be enabled.

Parameters:
out - stream to which to print.
Since:
ostermillerutils 1.00.00

ExcelCSVPrinter

public ExcelCSVPrinter(java.io.Writer out)
Create a printer that will print values to the given stream. The delimiter will be the comma, the quote character will be double quotes, quotes will be used when needed, and auto flushing will be enabled.

Parameters:
out - stream to which to print.
Since:
ostermillerutils 1.00.00

ExcelCSVPrinter

public ExcelCSVPrinter(java.io.Writer out,
                       boolean alwaysQuote,
                       boolean autoFlush)
Create a printer that will print values to the given stream. The delimiter will be the comma, and the quote character will be double quotes.

Parameters:
out - stream to which to print.
alwaysQuote - true if quotes should be used even when not strictly needed.
autoFlush - should auto flushing be enabled.
Since:
ostermillerutils 1.02.26

ExcelCSVPrinter

public ExcelCSVPrinter(java.io.Writer out,
                       char quote,
                       char delimiter)
                throws BadDelimeterException,
                       BadQuoteException
Create a printer that will print values to the given stream. Quotes will be used when needed, and auto flushing will be enabled.

Parameters:
out - stream to which to print.
delimiter - The new delimiter character to use.
quote - The new character to use for quoting.
Throws:
BadQuoteException - if the character cannot be used as a quote.
BadDelimiterException - if the character cannot be used as a delimiter.
BadDelimeterException
Since:
ostermillerutils 1.02.26

ExcelCSVPrinter

public ExcelCSVPrinter(java.io.Writer out,
                       char quote,
                       char delimiter,
                       boolean alwaysQuote,
                       boolean autoFlush)
                throws BadDelimeterException,
                       BadQuoteException
Create a printer that will print values to the given stream.

Parameters:
out - stream to which to print.
delimiter - The new delimiter character to use.
quote - The new character to use for quoting.
alwaysQuote - true if quotes should be used even when not strictly needed.
autoFlush - should auto flushing be enabled.
Throws:
BadQuoteException - if the character cannot be used as a quote.
BadDelimiterException - if the character cannot be used as a delimiter.
BadDelimeterException
Since:
ostermillerutils 1.02.26
Method Detail

changeDelimiter

public void changeDelimiter(char newDelimiter)
                     throws BadDelimeterException
Change this printer so that it uses a new delimiter.

Specified by:
changeDelimiter in interface CSVPrint
Parameters:
newDelimiter - The new delimiter character to use.
Throws:
BadDelimiterException - if the character cannot be used as a delimiter.
BadDelimeterException
Since:
ostermillerutils 1.02.18

changeQuote

public void changeQuote(char newQuote)
                 throws BadQuoteException
Change this printer so that it uses a new character for quoting.

Specified by:
changeQuote in interface CSVPrint
Parameters:
newQuote - The new character to use for quoting.
Throws:
BadQuoteException - if the character cannot be used as a quote.
Since:
ostermillerutils 1.02.18

println

public void println(java.lang.String value)
Print the string as the last value on the line. The value will be quoted if needed.

This method never throws an I/O exception. The client may inquire as to whether any errors have occurred by invoking checkError(). If an I/O Exception is desired, the client should use the corresponding writeln method.

Specified by:
println in interface CSVPrint
Parameters:
value - value to be outputted.
Since:
ostermillerutils 1.00.00

writeln

public void writeln(java.lang.String value)
             throws java.io.IOException
Print the string as the last value on the line. The value will be quoted if needed.

Specified by:
writeln in interface CSVPrint
Parameters:
value - value to be outputted.
Throws:
java.io.IOException - if an error occurs while writing.
Since:
ostermillerutils 1.02.26

println

public void println()
Output a blank line.

This method never throws an I/O exception. The client may inquire as to whether any errors have occurred by invoking checkError(). If an I/O Exception is desired, the client should use the corresponding writeln method.

Specified by:
println in interface CSVPrint
Since:
ostermillerutils 1.00.00

writeln

public void writeln()
             throws java.io.IOException
Output a blank line.

Specified by:
writeln in interface CSVPrint
Throws:
java.io.IOException - if an error occurs while writing.
Since:
ostermillerutils 1.02.26

println

public void println(java.lang.String[] values)
Print a single line of comma separated values. The values will be quoted if needed. Quotes and and other characters that need it will be escaped.

This method never throws an I/O exception. The client may inquire as to whether any errors have occurred by invoking checkError(). If an I/O Exception is desired, the client should use the corresponding writeln method.

Specified by:
println in interface CSVPrint
Parameters:
values - values to be outputted.
Since:
ostermillerutils 1.00.00

writeln

public void writeln(java.lang.String[] values)
             throws java.io.IOException
Print a single line of comma separated values. The values will be quoted if needed. Quotes and and other characters that need it will be escaped.

Specified by:
writeln in interface CSVPrint
Parameters:
values - values to be outputted.
Throws:
java.io.IOException - if an error occurs while writing.
Since:
ostermillerutils 1.02.26

print

public void print(java.lang.String[] values)
Print a single line of comma separated values. The values will be quoted if needed. Quotes and and other characters that need it will be escaped.

This method never throws an I/O exception. The client may inquire as to whether any errors have occurred by invoking checkError(). If an I/O Exception is desired, the client should use the corresponding writeln method.

Specified by:
print in interface CSVPrint
Parameters:
values - values to be outputted.
Since:
ostermillerutils 1.00.00

write

public void write(java.lang.String[] values)
           throws java.io.IOException
Print a single line of comma separated values. The values will be quoted if needed. Quotes and and other characters that need it will be escaped.

Specified by:
write in interface CSVPrint
Parameters:
values - values to be outputted.
Throws:
java.io.IOException - if an error occurs while writing.
Since:
ostermillerutils 1.02.26

println

public void println(java.lang.String[][] values)
Print several lines of comma separated values. The values will be quoted if needed. Quotes and newLine characters will be escaped.

This method never throws an I/O exception. The client may inquire as to whether any errors have occurred by invoking checkError(). If an I/O Exception is desired, the client should use the corresponding writeln method.

Specified by:
println in interface CSVPrint
Parameters:
values - values to be outputted.
Since:
ostermillerutils 1.00.00

writeln

public void writeln(java.lang.String[][] values)
             throws java.io.IOException
Print several lines of comma separated values. The values will be quoted if needed. Quotes and newLine characters will be escaped.

Specified by:
writeln in interface CSVPrint
Parameters:
values - values to be outputted.
Throws:
java.io.IOException - if an error occurs while writing.
Since:
ostermillerutils 1.02.26

printlnComment

public void printlnComment(java.lang.String comment)
Since ExcelCSV format does not support comments, this method will ignore the comment and start a new row.

This method never throws an I/O exception. The client may inquire as to whether any errors have occurred by invoking checkError(). If an I/O Exception is desired, the client should use the corresponding writelnComment method.

Specified by:
printlnComment in interface CSVPrint
Parameters:
comment - the comment to output (ignored).
Since:
ostermillerutils 1.00.00

writelnComment

public void writelnComment(java.lang.String comment)
                    throws java.io.IOException
Since ExcelCSV format does not support comments, this method will ignore the comment and start a new row.

Specified by:
writelnComment in interface CSVPrint
Parameters:
comment - the comment to output (ignored).
Throws:
java.io.IOException - if an error occurs while writing.
Since:
ostermillerutils 1.02.26

print

public void print(java.lang.String value)
Print the string as the next value on the line. The value will be quoted if needed. If value is null, an empty value is printed.

This method never throws an I/O exception. The client may inquire as to whether any errors have occurred by invoking checkError(). If an I/O Exception is desired, the client should use the corresponding println method.

Specified by:
print in interface CSVPrint
Parameters:
value - value to be outputted.
Since:
ostermillerutils 1.00.00

write

public void write(java.lang.String value)
           throws java.io.IOException
Print the string as the next value on the line. The value will be quoted if needed. If value is null, an empty value is printed.

Specified by:
write in interface CSVPrint
Parameters:
value - value to be outputted.
Throws:
java.io.IOException - if an error occurs while writing.
Since:
ostermillerutils 1.02.26

flush

public void flush()
           throws java.io.IOException
Flush any data written out to underlying streams.

Specified by:
flush in interface CSVPrint
Throws:
java.io.IOException
Since:
ostermillerutils 1.02.26

close

public void close()
           throws java.io.IOException
Close any underlying streams.

Specified by:
close in interface CSVPrint
Throws:
java.io.IOException
Since:
ostermillerutils 1.02.26

checkError

public boolean checkError()
Flush the stream if it's not closed and check its error state. Errors are cumulative; once the stream encounters an error, this routine will return true on all successive calls.

Specified by:
checkError in interface CSVPrint
Returns:
True if the print stream has encountered an error, either on the underlying output stream or during a format conversion.
Since:
ostermillerutils 1.02.26

setAlwaysQuote

public void setAlwaysQuote(boolean alwaysQuote)
Set whether values printers should always be quoted, or whether the printer may, at its discretion, omit quotes around the value.

Specified by:
setAlwaysQuote in interface CSVPrint
Parameters:
alwaysQuote - true if quotes should be used even when not strictly needed.
Since:
ostermillerutils 1.02.26

setAutoFlush

public void setAutoFlush(boolean autoFlush)
Set flushing behavior. Iff set, a flush command will be issued to any underlying stream after each print or write command.

Specified by:
setAutoFlush in interface CSVPrint
Parameters:
autoFlush - should auto flushing be enabled.
Since:
ostermillerutils 1.02.26


Copyright © 2002-2004 The RVTest Team. All Rights Reserved.