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

      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.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `TextTableWriter()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `docIncludesExample()` Indicates whether the serialization of some (short) example table should be added to the user documentation for this handler.
    `protected java.lang.String` | `formatColumnHeads(int[] colwidths, ColumnInfo[] cinfos)` Returns a string with headings for the table columns.
    `protected java.lang.String` | `formatLine(int[] colwidths, java.lang.String[] data)` Returns a line showing a row of table data.
    `protected java.lang.String` | `formatParam(java.lang.String name, java.lang.String value, java.lang.Class<?> clazz)` Returns a formatted parameter-value pair.
    `protected java.lang.String` | `formatSeparator(int[] colwidths)` Returns a decorative separator line, of the sort you might find between the column headings and the table data.
    `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";
    `java.lang.String` | `getMimeType()` Returns a string suitable for use as the value of a MIME Content-Type header.
    `java.lang.String` | `getXmlDescription()` Returns user-directed documentation in XML format.
    `boolean` | `looksLikeFile(java.lang.String location)` Returns true if the location argument is equal to "-", indicating standard output.
    `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

      `getEncoding, getMaximumParameterLength, getMaxWidth, getMinNameWidth, getSampledRows, getWriteParameters, setEncoding, setMaximumParameterLength, setMaxWidth, setSampledRows, setWriteParameters, writeStarTable`

    - ### Methods inherited from class uk.ac.starlink.table.formats.DocumentedStreamStarTableWriter

      `getExtensions, 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`

    - ### Methods inherited from interface uk.ac.starlink.table.formats.DocumentedIOHandler

      `matchesExtension, readText, toLink`

- - ### Constructor Detail

    - #### TextTableWriter

          public TextTableWriter()

  - ### Method Detail

    - #### getFormatName

          public java.lang.String getFormatName()

      Returns "text";
      Specified by:
        `getFormatName` in interface `StarTableWriter`
      Overrides:
        `getFormatName` in class `AbstractTextTableWriter`
      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 interface `StarTableWriter`
      Overrides:
        `getMimeType` in class `AbstractTextTableWriter`
      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 the `Documented.getXmlDescription()` method already includes some example output, should return false.
      Specified by:
        `docIncludesExample` in interface `DocumentedIOHandler`
      Returns:
        true if the user documentation would benefit from the addition of an example serialization

    - #### getXmlDescription

          public java.lang.String 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.

      Specified by:
        `getXmlDescription` in interface `Documented`
      Returns:
        XML description of this object

    - #### looksLikeFile

          public boolean looksLikeFile(java.lang.String location)

      Returns true if the location argument is equal to "-", indicating standard output.
      Specified by:
        `looksLikeFile` in interface `StarTableWriter`
      Overrides:
        `looksLikeFile` in class `DocumentedStreamStarTableWriter`
      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 a `BufferedOutputStream`), and should not close it at the end of the call.
      Specified by:
        `writeStarTables` in interface `MultiStarTableWriter`
      Parameters:
        `tableSeq` - sequence of tables to write
        `out` - 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 interface `MultiStarTableWriter`
      Parameters:
        `tableSeq` - sequence of tables to write
        `location` - destination for tables
        `sto` - StarTableOutput instance
      Throws:
        `java.io.IOException`

    - #### 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 class `AbstractTextTableWriter`
      Parameters:
        `val` - the value
        `vinfo` - the metadata object describing `val`'s type
        `width` - maximum preferred width into which the value should be formatted
      Returns:
        formatted string meaning `value`, preferably no longer than `width` characters

    - #### formatSeparator

          protected java.lang.String formatSeparator(int[] colwidths)

      Description copied from class: `AbstractTextTableWriter`
      Returns a decorative separator line, of the sort you might find between the column headings and the table data.
      Specified by:
        `formatSeparator` in class `AbstractTextTableWriter`
      Parameters:
        `colwidths` - column widths in characters
      Returns:
        separator line including any line end characters

    - #### formatColumnHeads

          protected java.lang.String formatColumnHeads(int[] colwidths,
                                                       ColumnInfo[] cinfos)

      Description copied from class: `AbstractTextTableWriter`
      Returns a string with headings for the table columns.
      Specified by:
        `formatColumnHeads` in class `AbstractTextTableWriter`
      Parameters:
        `colwidths` - column widths in characters
        `cinfos` - array of column headings
      Returns:
        headings line including any line end characters

    - #### formatLine

          protected java.lang.String formatLine(int[] colwidths,
                                                java.lang.String[] data)

      Description copied from class: `AbstractTextTableWriter`
      Returns a line showing a row of table data.
      Specified by:
        `formatLine` in class `AbstractTextTableWriter`
      Parameters:
        `colwidths` - column widths in characters
        `data` - array of strings to be output, one per column
      Returns:
        data line including any line end characters

    - #### formatParam

          protected java.lang.String formatParam(java.lang.String name,
                                                 java.lang.String value,
                                                 java.lang.Class<?> clazz)

      Description copied from class: `AbstractTextTableWriter`
      Returns a formatted parameter-value pair.
      Specified by:
        `formatParam` in class `AbstractTextTableWriter`
      Parameters:
        `name` - parameter name
        `value` - formatted parameter value
        `clazz` - type of value
      Returns:
        parameter line including any line end characters