Class NetricsCSVRecSrc

  • All Implemented Interfaces:
    NetricsBaseRecSrc, NetricsRecSrc, java.lang.AutoCloseable

    public class NetricsCSVRecSrc
    extends java.lang.Object
    implements NetricsRecSrc, java.lang.AutoCloseable
    NetricsRecSrc implementation for CSV file records. This reads CSV format records and converts them into NetricsRecord objects. It handles the same CSV format, including various varieties of header records and record keys, as the server side read of CSV record data. I.E. Microsoft Excel format CSV files where fields containing commas or new-lines are contained in double quotes and a double quote within a quoted field is represented by two contiguous double quotes.
    See Also:
    NetricsRecFile
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String DFLT_CHARSET
      Default file character set encoding (latin-1).
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Closes files opened by this object.
      java.lang.Integer getCount()
      Get the count of records that have been retrieved from the record source.
      int getCurLine()
      Return the line number of the last line read.
      java.lang.String[] getFieldNames()
      Return the record field names.
      int[] getFieldTypes()
      Return the record field types.
      NetricsRecord getNext()
      Return the next valid CSV record.
      int getRecLine()
      Return the line number the last record returned started on.
      boolean hasNext()
      Return true if there is another record to be read.
      void loggingOff()
      Turn logging of Ignored records off.
      void loggingOn​(java.io.Writer log_file)
      Turn logging of Ignored bad records on.
      void reset()
      Reset the file to the first record.
      • Methods inherited from class java.lang.Object

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

      • DFLT_CHARSET

        public static final java.lang.String DFLT_CHARSET
        Default file character set encoding (latin-1).
        See Also:
        Constant Field Values
    • Constructor Detail

      • NetricsCSVRecSrc

        public NetricsCSVRecSrc​(NetricsRecFile file_spec)
                         throws java.io.FileNotFoundException,
                                NetricsFileFormatException
        Create a record reader for a CSV file. This creates a CSV file reader for a CSV file specified by the given NetricsRecFile object. Fixed width files are not supported.
        Parameters:
        file_spec - The definition of the location and format of the CSV file containing the records to be read.
        Throws:
        java.io.FileNotFoundException - if the file specified in file_spec does not exist.
        NetricsFileFormatException - if the file specified in file_spec has improperly formatted data.
        See Also:
        NetricsRecFile
      • NetricsCSVRecSrc

        public NetricsCSVRecSrc​(java.io.BufferedReader in_stream,
                                NetricsRecFile file_spec)
                         throws NetricsFileFormatException
        Create a record reader for a CSV file read from a stream. This creates a CSV file reader for a CSV file to be read from an opened stream. The format of the stream is defined by the given NetricsRecFile object, but the file name is ignored. Fixed width files are not supported.
        Parameters:
        in_stream - The input stream the CSV data is to be read from.
        file_spec - The definition of the format of the CSV file containing the records to be read.
        Throws:
        NetricsFileFormatException - if the input stream has improperly formatted data.
        See Also:
        NetricsRecFile
    • Method Detail

      • getFieldNames

        public java.lang.String[] getFieldNames()
        Return the record field names. This returns the field names for the records in the CSV file as defined in any header information. It does not include the key field if it is present.
        Returns:
        an array of the field names, or null if field names were not defined in the header.
      • getFieldTypes

        public int[] getFieldTypes()
        Return the record field types. This returns the field types for the records in the CSV file as defined in any header information. It does not include the key field if it is present. The integer values returned are the field type integer ID as defined in NetricsTable.
        Returns:
        an array of the field types, or null if field types were not defined in the header.
        See Also:
        NetricsTable
      • getCurLine

        public int getCurLine()
        Return the line number of the last line read.
        Returns:
        the line number of the last line read.
      • getRecLine

        public int getRecLine()
        Return the line number the last record returned started on.
        Returns:
        the line number the last record returned started on.
      • getCount

        public java.lang.Integer getCount()
        Description copied from interface: NetricsBaseRecSrc
        Get the count of records that have been retrieved from the record source.
        Sources that don't support a count will return null.
        Specified by:
        getCount in interface NetricsBaseRecSrc
        Returns:
        The number of records that have been retrieved from the record source.
      • loggingOn

        public void loggingOn​(java.io.Writer log_file)
        Turn logging of Ignored bad records on. This turns on logging of bad records that were ignored. This is only relavent if the Do Max Work flag is set. If logging is already on this call will change the log file.
        Parameters:
        log_file - a line is written to this file for each bad record that is ignored.
      • loggingOff

        public void loggingOff()
        Turn logging of Ignored records off. This does not close the log file, the caller is responsble for managing the log file.
      • hasNext

        public boolean hasNext()
                        throws NetricsFileFormatException
        Return true if there is another record to be read.

        If Do Max Work is specified invalid records are quietly skipped. If Do Max Work is not specified invalid records throw an exception.
        Specified by:
        hasNext in interface NetricsBaseRecSrc
        Returns:
        True if there is another record, false otherwise
        Throws:
        NetricsFileFormatException
      • reset

        public void reset()
                   throws NetricsFileFormatException
        Reset the file to the first record. This resets reading of the file to the first record in the file so they can be read again. This can only be used if the file was opened by this object, if the CSV data is being read from a passed in stream this will throw an exception.
        Specified by:
        reset in interface NetricsBaseRecSrc
        Throws:
        NetricsFileFormatException
      • close

        public void close()
                   throws NetricsFileFormatException
        Closes files opened by this object. This closes any files opened by this object. If records are being read from a stream that was passed into this object calling this will do nothing.
        Specified by:
        close in interface java.lang.AutoCloseable
        Throws:
        NetricsFileFormatException - if there was an error closing the underlying stream.