public abstract class AbstractTextTableWriter extends DocumentedStreamStarTableWriter
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.| Modifier | Constructor and Description |
|---|---|
protected |
AbstractTextTableWriter(String[] extensions,
boolean writeParams)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
protected abstract String |
formatValue(Object val,
ValueInfo vinfo,
int width)
Formats a data value for output.
|
protected byte[] |
getBytes(String str)
Returns a byte array corresponding to a given string.
|
String |
getFormatName()
Returns "text";
|
int |
getMaximumParameterLength()
Returns the maximum length for the value of a parameter as passed to
printParam(java.io.OutputStream, java.lang.String, java.lang.String, java.lang.Class<?>). |
int |
getMaxWidth()
Returns the maximum width for any output column.
|
String |
getMimeType()
Returns a string suitable for use as the value of a MIME
Content-Type header.
|
int |
getMinNameWidth(ColumnInfo info)
Returns the minimum width required to output the actual characters
of the name for a given column.
|
int |
getSampledRows()
Returns the number of rows which will be sampled to
work out the column width.
|
boolean |
getWriteParameters()
Finds out whether the output will include table parameters.
|
protected abstract void |
printColumnHeads(OutputStream strm,
int[] colwidths,
ColumnInfo[] cinfos)
Outputs headings for the table columns.
|
protected abstract void |
printLine(OutputStream strm,
int[] colwidths,
String[] data)
Outputs a line of table data.
|
protected abstract void |
printParam(OutputStream strm,
String name,
String value,
Class<?> clazz)
Outputs a parameter and its value.
|
protected abstract void |
printSeparator(OutputStream strm,
int[] colwidths)
Outputs a decorative separator line, of the sort you might find
between the column headings and the table data.
|
void |
setMaximumParameterLength(int maxParamLength)
Sets the maximum length for the value of a parameter that will be output.
|
void |
setMaxWidth(int maxWidth)
Sets the maximum width in characters for any output column.
|
void |
setSampledRows(int sampledRows)
Sets the number of rows which will be sampled before output is
commenced to work out the column widths.
|
void |
setWriteParameters(boolean writeParams)
Set whether the output should include table parameters.
|
void |
writeStarTable(StarTable startab,
OutputStream strm)
Writes a
StarTable object to a given output stream. |
getExtensions, looksLikeFile, writeStarTableclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitdocIncludesExample, matchesExtension, readText, toLinkgetXmlDescriptionprotected AbstractTextTableWriter(String[] extensions, boolean writeParams)
extensions - list of lower-cased filename extensions,
excluding the '.' characterwriteParams - whether parameters will be written by defaultpublic String getFormatName()
public String getMimeType()
StarTableWriterapplication/octet-stream"
(for binary formats) or "text/plain" for ASCII ones)
is recommended.public void writeStarTable(StarTable startab, OutputStream strm) throws IOException
StarTableWriterStarTable object to a given output stream.
The implementation can assume that out is suitable for
direct writing (for instance it should not normally wrap it in a
BufferedOutputStream), 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.
startab - the table to writestrm - the output stream to which startab should be
writtenTableFormatException - if this table cannot be written to a
streamIOException - if there is some I/O error@ConfigMethod(property="maxParam", doc="<p>Maximum width in characters of an output table parameter. Parameters with values longer than this will be truncated.</p>") public void setMaximumParameterLength(int maxParamLength)
maxParamLength - maximum printable parameter lengthpublic int getMaximumParameterLength()
printParam(java.io.OutputStream, java.lang.String, java.lang.String, java.lang.Class<?>). The default implementation currently returns 160.@ConfigMethod(property="params", doc="<p>Whether to output table parameters as well as row data.</p>") public void setWriteParameters(boolean writeParams)
writeParams - true iff you want table parameters to be output as
well as the table datapublic boolean getWriteParameters()
@ConfigMethod(property="maxCell", doc="<p>Maximum width in characters of an output table cell. Cells longer than this will be truncated.</p>") public void setMaxWidth(int maxWidth)
maxWidth - maximum column value width in characterspublic int getMaxWidth()
public int getMinNameWidth(ColumnInfo info)
printColumnHeads(java.io.OutputStream, int[], uk.ac.starlink.table.ColumnInfo[]) method does not need
to be included.info - column metadata@ConfigMethod(property="sampledRows", doc="<p>The number of rows examined on a first pass of the table to determine the width of each column. Only a representative number of rows needs to be examined, but if a formatted cell value after this limit is wider than the cells up to it, then such later wide cells may get truncated. If the value is <=0, all rows are examined in the first pass; this is the default, but it can be configured to some other value if that takes too long.</p>") public void setSampledRows(int sampledRows)
sampledRows - number of rows to be sampledpublic int getSampledRows()
protected abstract String formatValue(Object val, ValueInfo vinfo, int width)
val - the valuevinfo - the metadata object describing val's typewidth - maximum preferred width into which the value should
be formattedvalue,
preferably no longer than width charactersprotected abstract void printSeparator(OutputStream strm, int[] colwidths) throws IOException
strm - stream to write intocolwidths - column widths in charactersIOExceptionprotected abstract void printColumnHeads(OutputStream strm, int[] colwidths, ColumnInfo[] cinfos) throws IOException
strm - stream to write intocolwidths - column widths in characterscinfos - array of column headingsIOExceptionprotected abstract void printLine(OutputStream strm, int[] colwidths, String[] data) throws IOException
strm - stream to write intocolwidths - column widths in charactersdata - array of strings to be output, one per columnIOExceptionprotected abstract void printParam(OutputStream strm, String name, String value, Class<?> clazz) throws IOException
strm - stream to write intoname - parameter namevalue - formatted parameter valueclazz - type of valueIOExceptionprotected byte[] getBytes(String str)
str - string to decodeCopyright © 2025 Central Laboratory of the Research Councils. All Rights Reserved.