public abstract class AbstractTextTableWriter extends DocumentedStreamStarTableWriter
Modifier | Constructor and Description |
---|---|
protected |
AbstractTextTableWriter(java.lang.String[] extensions,
boolean writeParams)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected abstract java.lang.String |
formatValue(java.lang.Object val,
ValueInfo vinfo,
int width)
Formats a data value for output.
|
protected byte[] |
getBytes(java.lang.String str)
Returns a byte array corresponding to a given string.
|
java.lang.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.
|
java.lang.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(java.io.OutputStream strm,
int[] colwidths,
ColumnInfo[] cinfos)
Outputs headings for the table columns.
|
protected abstract void |
printLine(java.io.OutputStream strm,
int[] colwidths,
java.lang.String[] data)
Outputs a line of table data.
|
protected abstract 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 abstract 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 |
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,
java.io.OutputStream strm)
Writes a StarTable object to a given output stream.
|
getExtensions, looksLikeFile, writeStarTable
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
docIncludesExample, matchesExtension, readText, toLink
getXmlDescription
protected AbstractTextTableWriter(java.lang.String[] extensions, boolean writeParams)
extensions
- list of lower-cased filename extensions,
excluding the '.' characterwriteParams
- whether parameters will be written by defaultpublic java.lang.String getFormatName()
public java.lang.String getMimeType()
StarTableWriter
application/octet-stream
"
(for binary formats) or "text/plain
" for ASCII ones)
is recommended.public void writeStarTable(StarTable startab, java.io.OutputStream strm) throws java.io.IOException
StarTableWriter
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
streamjava.io.IOException
- 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 java.lang.String formatValue(java.lang.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 formattedprotected abstract void printSeparator(java.io.OutputStream strm, int[] colwidths) throws java.io.IOException
strm
- stream to write intocolwidths
- column widths in charactersjava.io.IOException
protected abstract void printColumnHeads(java.io.OutputStream strm, int[] colwidths, ColumnInfo[] cinfos) throws java.io.IOException
strm
- stream to write intocolwidths
- column widths in characterscinfos
- array of column headingsjava.io.IOException
protected abstract void printLine(java.io.OutputStream strm, int[] colwidths, java.lang.String[] data) throws java.io.IOException
strm
- stream to write intocolwidths
- column widths in charactersdata
- array of strings to be output, one per columnjava.io.IOException
protected abstract void printParam(java.io.OutputStream strm, java.lang.String name, java.lang.String value, java.lang.Class<?> clazz) throws java.io.IOException
strm
- stream to write intoname
- parameter namevalue
- formatted parameter valueclazz
- type of valuejava.io.IOException
protected byte[] getBytes(java.lang.String str)
str
- string to decode