Package uk.ac.starlink.ecsv
Class EcsvEncoder
java.lang.Object
uk.ac.starlink.ecsv.EcsvEncoder
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
ConstructorsModifierConstructorDescriptionprotected
EcsvEncoder
(String datatype, String subtype) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionstatic EcsvEncoder
createEncoder
(uk.ac.starlink.table.ColumnInfo info, char delimiter) Returns an encoder suitable for encoding data from a column with given metadata.abstract String
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.
-
Constructor Details
-
EcsvEncoder
Constructor.- Parameters:
datatype
- datatype name as declared by ECSVsubtype
- subtype string as declared by ECSV, may be null
-
-
Method Details
-
encode
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
Returns the ECSV datatype handled by this encoder.- Returns:
- datatype string
-
getSubtype
Returns the ECSV subtype for this decoder.- Returns:
- subtype, may be null
-
createEncoder
Returns an encoder suitable for encoding data from a column with given metadata.- Parameters:
info
- column metadatadelimiter
- delimiter value, must be comma or space, required to determine quoting details- Returns:
- encoder, or null for unknown or unsupported data type
-
quoteString
Returns a suitably escaped value of a string, ensuring that no ECSV control characters are present in the result.- Parameters:
txt
- raw stringdelimiter
- delimiter character to be avoided, must be comma or space- Returns:
- sanitised version of the string
-