Class AbstractGenericFormatter

  • All Implemented Interfaces:
    ResultsFormatter
    Direct Known Subclasses:
    CSVGenericFormatter

    public abstract class AbstractGenericFormatter
    extends java.lang.Object
    implements ResultsFormatter
    Abstract class encapsulating basic results formatter functionality without prescribing schema
    Author:
    Marc Ubaldino, MITRE Corp.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      boolean debug  
      protected java.util.List<java.lang.String> fieldOrder
      The field_order.
      protected java.util.HashSet<java.lang.String> fieldSet
      Distinct set of fields in your output schema.
      protected org.slf4j.Logger log  
      java.lang.String outputExtension
      File extension for callers to know.
      protected Parameters outputParams
      The output params.
      protected java.lang.String outputType
      reflected by extension; an enum in OpenSextant
      boolean overwrite
      The overwrite.
      protected static int TEXT_WIDTH
      Size of text window around matches -- to use as excerpts
    • Method Summary

      Modifier and Type Method Description
      void addField​(java.lang.String f)
      Adds the field.
      protected void checkOverwrite​(java.io.File item)
      uniform helper for overwrite check.
      protected abstract void closeOutputStreams()
      Close output streams.
      protected java.lang.String createOutputFileName()
      Creates the output file name.
      protected abstract void createOutputStreams()
      Create the output stream appropriate for the output type.
      protected void defaultFields()
      Default fields for generic CSV output.
      protected void deleteOutput​(java.io.File prevOutput)
      This is checked only by internal classes as they create output streams.
      abstract void finish()
      Finish.
      java.lang.String getJobName()
      A basic job name that reflects file name.
      java.lang.String getOutputFilepath()
      Gets the output filepath.
      java.lang.String getOutputType()
      Gets the output type.
      void removeField​(java.lang.String f)
      Removes the field.
      void setOutputDir​(java.lang.String path)
      Sets the output dir.
      void setOutputFilename​(java.lang.String fname)
      Sets the output filename.
      void setParameters​(Parameters params)
      Sets the parameters.
      abstract void start​(java.lang.String nm)
      Start.
      abstract void writeRow​(java.util.Map<java.lang.String,​java.lang.Object> values)
      Write the data to the output stream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • outputParams

        protected Parameters outputParams
        The output params.
      • overwrite

        public boolean overwrite
        The overwrite.
      • log

        protected final org.slf4j.Logger log
      • outputExtension

        public java.lang.String outputExtension
        File extension for callers to know.
      • outputType

        protected java.lang.String outputType
        reflected by extension; an enum in OpenSextant
      • TEXT_WIDTH

        protected static int TEXT_WIDTH
        Size of text window around matches -- to use as excerpts
      • debug

        public boolean debug
      • fieldSet

        protected java.util.HashSet<java.lang.String> fieldSet
        Distinct set of fields in your output schema.
      • fieldOrder

        protected java.util.List<java.lang.String> fieldOrder
        The field_order.
    • Constructor Detail

      • AbstractGenericFormatter

        public AbstractGenericFormatter()
    • Method Detail

      • defaultFields

        protected final void defaultFields()
        Default fields for generic CSV output. If GIS output is desired, then use GeoCSV formatter.
      • getJobName

        public java.lang.String getJobName()
        A basic job name that reflects file name.
        Specified by:
        getJobName in interface ResultsFormatter
        Returns:
        the job name
      • setOutputFilename

        public void setOutputFilename​(java.lang.String fname)
        Sets the output filename.
        Specified by:
        setOutputFilename in interface ResultsFormatter
        Parameters:
        fname - the new output filename
      • setOutputDir

        public void setOutputDir​(java.lang.String path)
        Sets the output dir.
        Specified by:
        setOutputDir in interface ResultsFormatter
        Parameters:
        path - the new output dir
      • getOutputFilepath

        public java.lang.String getOutputFilepath()
        Gets the output filepath.
        Specified by:
        getOutputFilepath in interface ResultsFormatter
        Returns:
        the output filepath
      • createOutputFileName

        protected java.lang.String createOutputFileName()
        Creates the output file name.
        Returns:
        the string
      • getOutputType

        public java.lang.String getOutputType()
        Gets the output type.
        Specified by:
        getOutputType in interface ResultsFormatter
        Returns:
        the output type
      • deleteOutput

        protected void deleteOutput​(java.io.File prevOutput)
        This is checked only by internal classes as they create output streams.
        Parameters:
        prevOutput - file path of previous output
      • checkOverwrite

        protected void checkOverwrite​(java.io.File item)
                               throws ProcessingException
        uniform helper for overwrite check.
        Parameters:
        item - target output file
        Throws:
        ProcessingException - if unable to overwrite file
      • writeRow

        public abstract void writeRow​(java.util.Map<java.lang.String,​java.lang.Object> values)
        Write the data to the output stream.
        Parameters:
        values - Map of data
      • createOutputStreams

        protected abstract void createOutputStreams()
                                             throws java.lang.Exception
        Create the output stream appropriate for the output type. IO is created using the filename represented by getOutputFilepath()
        Throws:
        java.lang.Exception - when unable to create output stream
      • closeOutputStreams

        protected abstract void closeOutputStreams()
                                            throws java.lang.Exception
        Close output streams.
        Throws:
        java.lang.Exception