Class TabularOutputFile


  • public class TabularOutputFile
    extends TabularFile
    An abstraction for writing rows of tabular data. Columns of the tabular data can be of numeric or text. Using this sub-class of TabularFile users can write rows of data. The user is responsible for filling rows with data of the appropriate type for the column and writing the row to the file. Use the static methods of TabularFile to create and define the columns of the file. Use the methods of this class to write rows. After writing the rows, it is important to call the flush() method to ensure that all buffered rows are committed to the file.
    See Also:
    TabularFile, For example code
    • Constructor Detail

      • TabularOutputFile

        public TabularOutputFile​(java.util.LinkedHashMap<java.lang.String,​DataType> columnTypes,
                                 java.nio.file.Path path)
    • Method Detail

      • getDefaultTextSize

        public static int getDefaultTextSize()
        Returns:
        the assumed default length of the longest text column
      • setDefaultTextSize

        public static void setDefaultTextSize​(int defaultTextSize)
        The assumed length of the longest text column. For performance optimization purposes only.
        Parameters:
        defaultTextSize - must be 0 or more
      • getNumRowBytes

        public static int getNumRowBytes​(int numNumericColumns,
                                         int numTextColumns,
                                         int maxTextLength)
        Parameters:
        numNumericColumns - the number of numeric columns
        numTextColumns - the number of text columns
        maxTextLength - the length of the longest text column
        Returns:
        the number of bytes on such a row
      • getRecommendedRowBatchSize

        public static final int getRecommendedRowBatchSize​(int rowByteSize)
        Parameters:
        rowByteSize - the number of bytes in a row, must be greater than 0
        Returns:
        the recommended number of rows in a batch, given the row byte size
      • setMaxRowsInBatch

        public final void setMaxRowsInBatch​(int numRows)
        Allows the user to configure the size of the batch writing if performance becomes an issue. This may or may not provide any benefit. The static methods related to this functionality can be used to recommend a reasonable batch size.
        Parameters:
        numRows - the number of rows to use when writing a batch to disk, must be greater than 0
      • getRow

        public final RowSetterIfc getRow()
        Provides a row that can be used to set individual columns before writing the row to the file
        Returns:
        a RowSetterIfc
      • writeNumeric

        public final void writeNumeric​(double[] data)
        A convenience method. This writes the values in the array to the numeric columns in the file in the order of their appearance. Any text columns will have the value null and cannot be unwritten.

        The recommended use is for files that have all numeric columns.

        If you have mixed column types, then use getRow() to first set the appropriate columns before writing them.

        Parameters:
        data - the data to write
      • writeText

        public final void writeText​(java.lang.String[] data)
        A convenience method. This writes the values in the array to the text columns in the file in the order of their appearance. Any numeric columns will have the value Double.NaN and cannot be unwritten.

        The recommended use is for files that have all text columns.

        If you have mixed column types, then use getRow() to first set the appropriate columns before writing them.

        Parameters:
        data - the data to write
      • writeRow

        public final void writeRow​(RowSetterIfc rowSetter)
        Writes the data currently in the row to the file. Once written, the write cannot be undone.
        Parameters:
        rowSetter - a rowSetter, provided by getRow()
      • writeRows

        public final void writeRows​(java.util.List<RowSetterIfc> rows)
        A convenience method if the user has a list of rows to write. All rows in the list are written to the file.
        Parameters:
        rows - the rows to write, must not be null
      • flushRows

        public final void flushRows()
        After writing all rows, you must call flushRows() to ensure that all buffered row data is committed to the file.