Class EcsvEncoder

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

public abstract class EcsvEncoder extends Object
Converts values for a given column into strings suitable for inclusion in the body of an ECSV file.
Since:
28 Apr 2020
Author:
Mark Taylor
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    EcsvEncoder(String datatype, String subtype)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    createEncoder(uk.ac.starlink.table.ColumnInfo info, char delimiter)
    Returns an encoder suitable for encoding data from a column with given metadata.
    abstract String
    encode(Object value)
    Formats a value of this encoder's datatype for insertion into the body of an ECSV file.
    Returns the ECSV datatype handled by this encoder.
    Returns the ECSV subtype for this decoder.
    static String
    quoteString(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 Details

    • EcsvEncoder

      protected EcsvEncoder(String datatype, String subtype)
      Constructor.
      Parameters:
      datatype - datatype name as declared by ECSV
      subtype - subtype string as declared by ECSV, may be null
  • Method Details

    • encode

      public abstract String encode(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 String getDatatype()
      Returns the ECSV datatype handled by this encoder.
      Returns:
      datatype string
    • getSubtype

      public String getSubtype()
      Returns the ECSV subtype for this decoder.
      Returns:
      subtype, may be null
    • createEncoder

      public static EcsvEncoder createEncoder(uk.ac.starlink.table.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 String quoteString(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