uk.ac.starlink.ecsv

## Class EcsvEncoder

- java.lang.Object
- - uk.ac.starlink.ecsv.EcsvEncoder

-     public abstract class EcsvEncoder
      extends java.lang.Object

  Converts values for a given column into strings suitable for inclusion in the body of an ECSV file.
  Since:
    28 Apr 2020

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `EcsvEncoder(java.lang.String datatype, java.lang.String subtype)` Constructor.

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static EcsvEncoder` | `createEncoder(ColumnInfo info, char delimiter)` Returns an encoder suitable for encoding data from a column with given metadata.
    `abstract java.lang.String` | `encode(java.lang.Object value)` Formats a value of this encoder's datatype for insertion into the body of an ECSV file.
    `java.lang.String` | `getDatatype()` Returns the ECSV datatype handled by this encoder.
    `java.lang.String` | `getSubtype()` Returns the ECSV subtype for this decoder.
    `static java.lang.String` | `quoteString(java.lang.String txt, char delimiter)` Returns a suitably escaped value of a string, ensuring that no ECSV control characters are present in the result.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### EcsvEncoder

          protected EcsvEncoder(java.lang.String datatype,
                                java.lang.String subtype)

      Constructor.
      Parameters:
        `datatype` - datatype name as declared by ECSV
        `subtype` - subtype string as declared by ECSV, may be null

  - ### Method Detail

    - #### encode

          public abstract java.lang.String encode(java.lang.Object value)

      Formats a value of this encoder's datatype for insertion into the body of an ECSV file. The output string must include any required quoting, for instance it may not include unescaped delimiters, newlines or double quote characters. As a special case, null may be returned instead if no conversion can be performed.
      Parameters:
        `value` - typed value to encode
      Returns:
        formatted string representation, or null

    - #### getDatatype

          public java.lang.String getDatatype()

      Returns the ECSV datatype handled by this encoder.
      Returns:
        datatype string

    - #### getSubtype

          public java.lang.String getSubtype()

      Returns the ECSV subtype for this decoder.
      Returns:
        subtype, may be null

    - #### createEncoder

          public static EcsvEncoder createEncoder(ColumnInfo info,
                                                  char delimiter)

      Returns an encoder suitable for encoding data from a column with given metadata.
      Parameters:
        `info` - column metadata
        `delimiter` - delimiter value, must be comma or space, required to determine quoting details
      Returns:
        encoder, or null for unknown or unsupported data type

    - #### quoteString

          public static java.lang.String quoteString(java.lang.String txt,
                                                     char delimiter)

      Returns a suitably escaped value of a string, ensuring that no ECSV control characters are present in the result.
      Parameters:
        `txt` - raw string
        `delimiter` - delimiter character to be avoided, must be comma or space
      Returns:
        sanitised version of the string