Package uk.ac.starlink.table.formats
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 TypeMethodDescriptionboolean
Indicates whether the serialization of some (short) example table should be added to the user documentation for this handler.Returns "CSV" or "CSV-noheader".int
Returns 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.boolean
Indicates whether an initial row containing column names will be written.Returns user-directed documentation in XML format.void
setMaxFieldChars
(int maxFieldChars) Sets a limit on the number of characters that will be written in a single field.void
setWriteHeader
(boolean writeHeader) Indicate whether an initial row containing column names should be written.void
writeStarTable
(StarTable table, OutputStream ostrm) Writes aStarTable
object to a given output stream.Methods inherited from class uk.ac.starlink.table.formats.DocumentedStreamStarTableWriter
getExtensions, looksLikeFile, writeStarTable
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface uk.ac.starlink.table.formats.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
-
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=2) 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:StarTableWriter
Returns 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:DocumentedIOHandler
Indicates 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:Documented
Returns 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:StarTableWriter
Writes aStarTable
object to a given output stream. The implementation can assume thatout
is 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
TableFormatException
to indicate that it cannot do so.- Parameters:
table
- the table to writeostrm
- the output stream to whichstartab
should be written- Throws:
IOException
- if there is some I/O error
-