Class CsvTableWriter
java.lang.Object
uk.ac.starlink.table.formats.DocumentedStreamStarTableWriter
uk.ac.starlink.table.formats.CsvTableWriter
- All Implemented Interfaces:
Documented, DocumentedIOHandler, StarTableWriter
A StarTableWriter which outputs to Comma-Separated Value format.
This format is readable by
CsvTableBuilder.- Since:
- 21 Sep 2004
- Author:
- Mark Taylor (Starlink)
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a default CSV table writer.CsvTableWriter(boolean writeHeader) Constructs a CSV table writer which optionally writes headers. -
Method Summary
Modifier and TypeMethodDescriptionbooleanIndicates whether the serialization of some (short) example table should be added to the user documentation for this handler.charReturns the delimiter character.Returns "CSV" or "CSV-noheader".intReturns the limit on the number of characters that will be written in a single field.Returns a string suitable for use as the value of a MIME Content-Type header.booleanIndicates whether an initial row containing column names will be written.Returns user-directed documentation in XML format.voidsetDelimiter(char delimiter) Sets the delimiter character.voidsetMaxFieldChars(int maxFieldChars) Sets a limit on the number of characters that will be written in a single field.voidsetWriteHeader(boolean writeHeader) Indicate whether an initial row containing column names should be written.voidwriteStarTable(StarTable table, OutputStream ostrm) Writes aStarTableobject to a given output stream.Methods inherited from class DocumentedStreamStarTableWriter
getExtensions, looksLikeFile, writeStarTableMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface DocumentedIOHandler
readText
-
Constructor Details
-
CsvTableWriter
public CsvTableWriter()Constructs a default CSV table writer. This doesn't write a header. -
CsvTableWriter
public CsvTableWriter(boolean writeHeader) Constructs a CSV table writer which optionally writes headers.- Parameters:
writeHeader- true iff you want the first output line to contain column names
-
-
Method Details
-
setWriteHeader
@ConfigMethod(property="header", doc="<p>If true, the first line of the CSV output will be a header containing the column names; if false, no header line is written and all lines represent data rows.</p>", sequence=1) public void setWriteHeader(boolean writeHeader) Indicate whether an initial row containing column names should be written.- Parameters:
writeHeader- true iff you want the first output line to contain column names
-
getWriteHeader
public boolean getWriteHeader()Indicates whether an initial row containing column names will be written.- Returns:
- whether the first output line will contain column names
-
setDelimiter
@ConfigMethod(property="delimiter", doc="<p>Field delimiter character, by default a comma. Permitted values are a single character like \"<code>|</code>\", a hexadecimal character code like \"<code>0x7C</code>\", or one of the names \"<code>comma</code>\", \"<code>space</code>\" or \"<code>tab</code>\". Some choices of delimiter, for instance whitespace characters, might not work well or might behave in surprising ways.</p>", example="|", sequence=2) public void setDelimiter(char delimiter) Sets the delimiter character. Non-comma delimiters are not guaranteed to work.- Parameters:
delimiter- delimiter character
-
getDelimiter
public char getDelimiter()Returns the delimiter character.- Returns:
- delimiter
-
setMaxFieldChars
@ConfigMethod(property="maxCell", doc="<p>Maximum width in characters of an output table cell. Cells longer than this will be truncated.</p>", example="160", sequence=3) public void setMaxFieldChars(int maxFieldChars) Sets a limit on the number of characters that will be written in a single field. Fields beyond this length will be truncated.- Parameters:
maxFieldChars- new limit
-
getMaxFieldChars
public int getMaxFieldChars()Returns the limit on the number of characters that will be written in a single field. Fields beyond this length will be truncated.- Returns:
- current limit
-
getFormatName
Returns "CSV" or "CSV-noheader".- Returns:
- a short string identifying the output format of this writer
-
getMimeType
Description copied from interface:StarTableWriterReturns a string suitable for use as the value of a MIME Content-Type header. If no suitable MIME type is available or known, one of "application/octet-stream" (for binary formats) or "text/plain" for ASCII ones) is recommended.- Returns:
- MIME content type
-
docIncludesExample
public boolean docIncludesExample()Description copied from interface:DocumentedIOHandlerIndicates whether the serialization of some (short) example table should be added to the user documentation for this handler. Binary formats, or instances for which theDocumented.getXmlDescription()method already includes some example output, should return false.- Returns:
- true if the user documentation would benefit from the addition of an example serialization
-
getXmlDescription
Description copied from interface:DocumentedReturns user-directed documentation in XML format.The output should be a sequence of one or more <P> elements, using XHTML-like XML. Since rendering may be done in a number of contexts however, use of the full range of XHTML elements is discouraged. Where possible, the content should stick to simple markup such as the elements P, A, UL, OL, LI, DL, DT, DD EM, STRONG, I, B, CODE, TT, PRE.
- Returns:
- XML description of this object
-
writeStarTable
Description copied from interface:StarTableWriterWrites aStarTableobject to a given output stream. The implementation can assume thatoutis suitable for direct writing (for instance it should not normally wrap it in aBufferedOutputStream), and should not close it at the end of the call.Not all table writers are capable of writing to a stream; an implementation may throw a
TableFormatExceptionto indicate that it cannot do so.- Parameters:
table- the table to writeostrm- the output stream to whichstartabshould be written- Throws:
IOException- if there is some I/O error
-