Package uk.ac.starlink.table.formats
Class TextTableWriter
java.lang.Object
uk.ac.starlink.table.formats.DocumentedStreamStarTableWriter
uk.ac.starlink.table.formats.AbstractTextTableWriter
uk.ac.starlink.table.formats.TextTableWriter
- All Implemented Interfaces:
Documented,DocumentedIOHandler,MultiStarTableWriter,StarTableWriter
A StarTableWriter which outputs text to a human-readable text file.
Table parameters (per-table metadata) can optionally be output
as well as the table data themselves.
- Author:
- Mark Taylor (Starlink)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanIndicates whether the serialization of some (short) example table should be added to the user documentation for this handler.protected StringformatValue(Object val, ValueInfo vinfo, int width) Formats a data value for output.Returns "text";Returns a string suitable for use as the value of a MIME Content-Type header.Returns user-directed documentation in XML format.booleanlooksLikeFile(String location) Returns true if the location argument is equal to "-", indicating standard output.protected voidprintColumnHeads(OutputStream strm, int[] colwidths, ColumnInfo[] cinfos) Outputs headings for the table columns.protected voidprintLine(OutputStream strm, int[] colwidths, String[] data) Outputs a line of table data.protected voidprintParam(OutputStream strm, String name, String value, Class<?> clazz) Outputs a parameter and its value.protected voidprintSeparator(OutputStream strm, int[] colwidths) Outputs a decorative separator line, of the sort you might find between the column headings and the table data.voidwriteStarTables(TableSequence tableSeq, OutputStream out) Writes an array of StarTable objects to a given output stream.voidwriteStarTables(TableSequence tableSeq, String location, StarTableOutput sto) Writes an array of StarTable objects to a given location.Methods inherited from class uk.ac.starlink.table.formats.AbstractTextTableWriter
getBytes, getMaximumParameterLength, getMaxWidth, getMinNameWidth, getSampledRows, getWriteParameters, setMaximumParameterLength, setMaxWidth, setSampledRows, setWriteParameters, writeStarTableMethods inherited from class uk.ac.starlink.table.formats.DocumentedStreamStarTableWriter
getExtensions, writeStarTableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface uk.ac.starlink.table.formats.DocumentedIOHandler
readTextMethods inherited from interface uk.ac.starlink.table.StarTableWriter
writeStarTable, writeStarTable
-
Constructor Details
-
TextTableWriter
public TextTableWriter()
-
-
Method Details
-
getFormatName
Returns "text";- Specified by:
getFormatNamein interfaceStarTableWriter- Overrides:
getFormatNamein classAbstractTextTableWriter- Returns:
- "text"
-
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.- Specified by:
getMimeTypein interfaceStarTableWriter- Overrides:
getMimeTypein classAbstractTextTableWriter- 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.- Specified by:
docIncludesExamplein interfaceDocumentedIOHandler- 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.
- Specified by:
getXmlDescriptionin interfaceDocumented- Returns:
- XML description of this object
-
looksLikeFile
Returns true if the location argument is equal to "-", indicating standard output.- Specified by:
looksLikeFilein interfaceStarTableWriter- Overrides:
looksLikeFilein classDocumentedStreamStarTableWriter- Parameters:
location- the location name (probably filename)- Returns:
- true iff it looks like a file this writer would normally write
-
writeStarTables
Description copied from interface:MultiStarTableWriterWrites an array of StarTable objects to a given output stream. The implementation can assume that the stream 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.- Specified by:
writeStarTablesin interfaceMultiStarTableWriter- Parameters:
tableSeq- sequence of tables to writeout- destination stream- Throws:
IOException
-
writeStarTables
public void writeStarTables(TableSequence tableSeq, String location, StarTableOutput sto) throws IOException Description copied from interface:MultiStarTableWriterWrites an array of StarTable objects to a given location. Implementations are free to interpret the location argument in any way appropriate for them. Typically however the location will simply be used to get an output stream (for instance interpreting it as a filename). In this case the sto argument should normally be used to turn location into a stream.- Specified by:
writeStarTablesin interfaceMultiStarTableWriter- Parameters:
tableSeq- sequence of tables to writelocation- destination for tablessto- StarTableOutput instance- Throws:
IOException
-
formatValue
Description copied from class:AbstractTextTableWriterFormats a data value for output.- Specified by:
formatValuein classAbstractTextTableWriter- Parameters:
val- the valuevinfo- the metadata object describing val's typewidth- maximum preferred width into which the value should be formatted- Returns:
- formatted string meaning value, preferably no longer than width characters
-
printSeparator
Description copied from class:AbstractTextTableWriterOutputs a decorative separator line, of the sort you might find between the column headings and the table data.- Specified by:
printSeparatorin classAbstractTextTableWriter- Parameters:
strm- stream to write intocolwidths- column widths in characters- Throws:
IOException
-
printColumnHeads
protected void printColumnHeads(OutputStream strm, int[] colwidths, ColumnInfo[] cinfos) throws IOException Description copied from class:AbstractTextTableWriterOutputs headings for the table columns.- Specified by:
printColumnHeadsin classAbstractTextTableWriter- Parameters:
strm- stream to write intocolwidths- column widths in characterscinfos- array of column headings- Throws:
IOException
-
printLine
Description copied from class:AbstractTextTableWriterOutputs a line of table data.- Specified by:
printLinein classAbstractTextTableWriter- Parameters:
strm- stream to write intocolwidths- column widths in charactersdata- array of strings to be output, one per column- Throws:
IOException
-
printParam
protected void printParam(OutputStream strm, String name, String value, Class<?> clazz) throws IOException Description copied from class:AbstractTextTableWriterOutputs a parameter and its value.- Specified by:
printParamin classAbstractTextTableWriter- Parameters:
strm- stream to write intoname- parameter namevalue- formatted parameter valueclazz- type of value- Throws:
IOException
-