Class TableReader

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable
    Direct Known Subclasses:
    RawTableReader

    public class TableReader
    extends java.lang.Object
    implements java.io.Closeable
    The TableReader class defines methods for reading table records.
    • Constructor Detail

      • TableReader

        public TableReader​(java.lang.Object table,
                           java.io.File dataFile)
                    throws java.lang.Exception
        Throws:
        java.lang.Exception
      • TableReader

        public TableReader​(java.lang.Object table,
                           java.net.URL dataFile)
                    throws java.lang.Exception
        Constructs a TableReader instance for reading records from a data file associated with a table object.
        Parameters:
        table - a table object
        dataFile - an input data file
        Throws:
        java.lang.NullPointerException - if table offset is null
        java.lang.Exception
      • TableReader

        public TableReader​(java.lang.Object table,
                           java.net.URL dataFile,
                           boolean checkSize,
                           boolean readEntireFile)
                    throws InvalidTableException,
                           java.lang.Exception
        Throws:
        InvalidTableException
        java.lang.Exception
      • TableReader

        public TableReader​(java.lang.Object table,
                           java.net.URL dataFile,
                           DataObjectLocation location,
                           boolean checkSize,
                           boolean readEntireFile,
                           boolean keepQuotationsFlag,
                           java.io.RandomAccessFile raf,
                           java.io.InputStream inputStream)
                    throws InvalidTableException,
                           java.lang.Exception
        Constructs a TableReader instance for reading records from a data file associated with a table object.
        Parameters:
        table - a table object
        dataFile - an input data file
        checkSize - check that the size of the data file is equal to the size of the table (length * records) + offset.
        readEntireFile - flag to read an entire file
        keepQuotationsFlag - flag to keep the starting/ending quotes
        Throws:
        java.lang.NullPointerException - if table offset is null
        InvalidTableException
        java.lang.Exception
    • Method Detail

      • getFields

        public FieldDescription[] getFields()
        Gets the field descriptions for fields in the table.
        Returns:
        an array of field descriptions
      • getFieldMap

        public java.util.Map<java.lang.String,​java.lang.Integer> getFieldMap()
        Returns:
        the field map.
      • readNext

        public TableRecord readNext()
                             throws java.io.IOException,
                                    com.opencsv.exceptions.CsvValidationException
        Reads the next record from the data file.
        Returns:
        the next record, or null if no further records.
        Throws:
        com.opencsv.exceptions.CsvValidationException
        java.io.IOException
      • getRecord

        public TableRecord getRecord​(int index)
                              throws java.lang.IllegalArgumentException,
                                     java.io.IOException,
                                     com.opencsv.exceptions.CsvValidationException
        Gets access to the table record given the index. The current row is set to this index, thus, subsequent call to readNext() gets the next record from this position.
        Parameters:
        index - the record index (1-relative)
        Returns:
        an instance of TableRecord
        Throws:
        java.lang.IllegalArgumentException - if index is greater than the record number
        com.opencsv.exceptions.CsvValidationException
        java.io.IOException
      • getRecord

        public TableRecord getRecord​(long index,
                                     boolean keepQuotationsFlag)
                              throws java.lang.IllegalArgumentException,
                                     java.io.IOException,
                                     com.opencsv.exceptions.CsvValidationException
        Gets access to the table record given the index. The current row is set to this index, thus, subsequent call to readNext() gets the next record from this position.
        Parameters:
        index - the record index (1-relative)
        keepQuotationsFlag - flag to keep the starting/ending quotes or not.
        Returns:
        an instance of TableRecord
        Throws:
        java.lang.IllegalArgumentException - if index is greater than the record number
        com.opencsv.exceptions.CsvValidationException
        java.io.IOException
      • setCurrentRow

        public void setCurrentRow​(int row)
        Sets the current row.
        Parameters:
        row - The row to set.
      • setCurrentRow

        public void setCurrentRow​(long row)
        Sets the current row.
        Parameters:
        row - The row to set.
      • getCurrentRow

        public long getCurrentRow()
        Returns:
        the current row.
      • getInputStream

        public java.io.InputStream getInputStream()
      • getRecordSize

        public long getRecordSize​(java.net.URL dataFile,
                                  java.lang.Object table)
                           throws java.lang.Exception
        Returns:
        the size of record (i.e. number of lines)
        Throws:
        java.lang.Exception
      • getOffset

        public long getOffset()
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException
      • setDataObjectLocation

        public void setDataObjectLocation​(DataObjectLocation dataObjectLocation)