Package uk.ac.starlink.table.formats
Class TextTableWriter
- java.lang.Object
-
- uk.ac.starlink.table.StreamStarTableWriter
-
- uk.ac.starlink.table.formats.AbstractTextTableWriter
-
- uk.ac.starlink.table.formats.TextTableWriter
-
- All Implemented Interfaces:
MultiStarTableWriter
,StarTableWriter
public class TextTableWriter extends AbstractTextTableWriter implements MultiStarTableWriter
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 Constructor Description TextTableWriter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.String
formatValue(java.lang.Object val, ValueInfo vinfo, int width)
Formats a data value for output.java.lang.String
getFormatName()
Returns "text";int
getMaxWidth()
Returns the maximum width for a given column.java.lang.String
getMimeType()
Returns a string suitable for use as the value of a MIME Content-Type header.boolean
looksLikeFile(java.lang.String location)
Returns true if the location argument is equal to "-", indicating standard output.protected void
printColumnHeads(java.io.OutputStream strm, int[] colwidths, ColumnInfo[] cinfos)
Outputs headings for the table columns.protected void
printLine(java.io.OutputStream strm, int[] colwidths, java.lang.String[] data)
Outputs a line of table data.protected void
printParam(java.io.OutputStream strm, java.lang.String name, java.lang.String value, java.lang.Class clazz)
Outputs a parameter and its value.protected void
printSeparator(java.io.OutputStream strm, int[] colwidths)
Outputs a decorative separator line, of the sort you might find between the column headings and the table data.void
writeStarTables(TableSequence tableSeq, java.io.OutputStream out)
Writes an array of StarTable objects to a given output stream.void
writeStarTables(TableSequence tableSeq, java.lang.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, getMinNameWidth, getSampledRows, getWriteParameters, setWriteParameters, writeStarTable
-
Methods inherited from class uk.ac.starlink.table.StreamStarTableWriter
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.StarTableWriter
writeStarTable, writeStarTable
-
-
-
-
Method Detail
-
getFormatName
public java.lang.String getFormatName()
Returns "text";- Specified by:
getFormatName
in interfaceStarTableWriter
- Overrides:
getFormatName
in classAbstractTextTableWriter
- Returns:
- "text"
-
getMimeType
public java.lang.String 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.- Specified by:
getMimeType
in interfaceStarTableWriter
- Overrides:
getMimeType
in classAbstractTextTableWriter
- Returns:
- MIME content type
-
looksLikeFile
public boolean looksLikeFile(java.lang.String location)
Returns true if the location argument is equal to "-", indicating standard output.- Specified by:
looksLikeFile
in interfaceStarTableWriter
- Parameters:
location
- the location name (probably filename)- Returns:
- true iff it looks like a file this writer would normally write
-
writeStarTables
public void writeStarTables(TableSequence tableSeq, java.io.OutputStream out) throws java.io.IOException
Description copied from interface:MultiStarTableWriter
Writes 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:
writeStarTables
in interfaceMultiStarTableWriter
- Parameters:
tableSeq
- sequence of tables to writeout
- destination stream- Throws:
java.io.IOException
-
writeStarTables
public void writeStarTables(TableSequence tableSeq, java.lang.String location, StarTableOutput sto) throws java.io.IOException
Description copied from interface:MultiStarTableWriter
Writes 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:
writeStarTables
in interfaceMultiStarTableWriter
- Parameters:
tableSeq
- sequence of tables to writelocation
- destination for tablessto
- StarTableOutput instance- Throws:
java.io.IOException
-
getMaxWidth
public int getMaxWidth()
Description copied from class:AbstractTextTableWriter
Returns the maximum width for a given column. Values longer than this may be truncated.- Specified by:
getMaxWidth
in classAbstractTextTableWriter
- Returns:
- maximum permitted column width in characters
-
formatValue
protected java.lang.String formatValue(java.lang.Object val, ValueInfo vinfo, int width)
Description copied from class:AbstractTextTableWriter
Formats a data value for output.- Specified by:
formatValue
in 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
protected void printSeparator(java.io.OutputStream strm, int[] colwidths) throws java.io.IOException
Description copied from class:AbstractTextTableWriter
Outputs a decorative separator line, of the sort you might find between the column headings and the table data.- Specified by:
printSeparator
in classAbstractTextTableWriter
- Parameters:
strm
- stream to write intocolwidths
- column widths in characters- Throws:
java.io.IOException
-
printColumnHeads
protected void printColumnHeads(java.io.OutputStream strm, int[] colwidths, ColumnInfo[] cinfos) throws java.io.IOException
Description copied from class:AbstractTextTableWriter
Outputs headings for the table columns.- Specified by:
printColumnHeads
in classAbstractTextTableWriter
- Parameters:
strm
- stream to write intocolwidths
- column widths in characterscinfos
- array of column headings- Throws:
java.io.IOException
-
printLine
protected void printLine(java.io.OutputStream strm, int[] colwidths, java.lang.String[] data) throws java.io.IOException
Description copied from class:AbstractTextTableWriter
Outputs a line of table data.- Specified by:
printLine
in classAbstractTextTableWriter
- Parameters:
strm
- stream to write intocolwidths
- column widths in charactersdata
- array of strings to be output, one per column- Throws:
java.io.IOException
-
printParam
protected void printParam(java.io.OutputStream strm, java.lang.String name, java.lang.String value, java.lang.Class clazz) throws java.io.IOException
Description copied from class:AbstractTextTableWriter
Outputs a parameter and its value.- Specified by:
printParam
in classAbstractTextTableWriter
- Parameters:
strm
- stream to write intoname
- parameter namevalue
- formatted parameter valueclazz
- type of value- Throws:
java.io.IOException
-
-