Class CSVGenericFormatter

  • All Implemented Interfaces:
    ResultsFormatter

    public class CSVGenericFormatter
    extends AbstractGenericFormatter
    Alternative to CSVFormatter which is schema-specific and a bit rigid. ResultsFormatter interface assumes an "extraction result"
    Author:
    ubaldino
    • Constructor Detail

      • CSVGenericFormatter

        public CSVGenericFormatter​(Parameters p)
    • Method Detail

      • setDelimiter

        public void setDelimiter​(java.lang.String ch)
      • createOutputStreams

        protected void createOutputStreams()
                                    throws java.lang.Exception
        Description copied from class: AbstractGenericFormatter
        Create the output stream appropriate for the output type. IO is created using the filename represented by getOutputFilepath()
        Specified by:
        createOutputStreams in class AbstractGenericFormatter
        Throws:
        java.lang.Exception - when unable to create output stream
      • writeRow

        public void writeRow​(java.util.Map<java.lang.String,​java.lang.Object> values)
        Write the data to the output stream.
        Specified by:
        writeRow in class AbstractGenericFormatter
        Parameters:
        values - Map of data
      • buildSchema

        protected void buildSchema()
                            throws ConfigException
        Create a schema instance with the fields properly typed and ordered
        Throws:
        ConfigException - schema configuration error
      • canAdd

        protected boolean canAdd​(java.lang.String f)
      • addColumn

        protected void addColumn​(java.util.Map<java.lang.String,​java.lang.String> row,
                                 java.lang.String f,
                                 java.lang.String d)
        Add a column of data to output; Field is validated ; value is not added if null
      • addColumn

        protected void addColumn​(java.util.Map<java.lang.String,​java.lang.String> row,
                                 java.lang.String f,
                                 int d)
      • formatResults

        public java.lang.String formatResults​(ExtractionResult result)
                                       throws ProcessingException
        Not implemented: this formatter is more flexible than requiring you to use it for Extraction output
        Returns:
        A message for the user
        Throws:
        ProcessingException - formatting error