Class FixedWidthReader


public class FixedWidthReader extends TextReader
Obtains records from a fixed width stream.
  • Constructor Details

    • FixedWidthReader

      public FixedWidthReader(File file)
    • FixedWidthReader

      public FixedWidthReader(Reader reader)
  • Method Details

    • getFillChar

      public char getFillChar()
      Returns the character trimmed from values in columns without their own fill character (defaults to space).
    • setFillChar

      public FixedWidthReader setFillChar(char fillChar)
      Sets the character trimmed from values in columns without their own fill character (defaults to space).
    • isLastFieldConsumesRemaining

      public boolean isLastFieldConsumesRemaining()
      Indicates if the last field in each record will contain the rest of each line (default is false).
    • setLastFieldConsumesRemaining

      public FixedWidthReader setLastFieldConsumesRemaining(boolean lastFieldConsumesRemaining)
      Set whether the last field in each record will contain the rest of each line. Default is false.
    • addField

      public FixedWidthReader addField(FixedWidthField field)
    • addFields

      public FixedWidthReader addFields(int... width)
      Appends unnamed, left-aligned columns of the given widths that use the reader's fill character.
    • addField

      public FixedWidthReader addField(String name, int width)
      Appends a left-aligned column that uses the reader's fill character.
    • addField

      public FixedWidthReader addField(String name, int width, FixedWidthAlign align, char fillChar)
    • skipField

      public FixedWidthReader skipField(int width)
      Appends a column of the given width whose text is discarded instead of read into a field.
    • setFieldNamesInFirstRow

      public FixedWidthReader setFieldNamesInFirstRow(boolean fieldNamesInFirstRow)
      Description copied from class: AbstractReader
      Indicates if the first row holds the field names instead of data (default is false); must be called before AbstractReader.open().
      Overrides:
      setFieldNamesInFirstRow in class AbstractReader
    • setFieldNames

      public FixedWidthReader setFieldNames(String... fieldNames)
      Description copied from class: AbstractReader
      Sets the names given to each record's fields, taking precedence over names in the first row; must be called before AbstractReader.open().
      Overrides:
      setFieldNames in class AbstractReader
    • setFieldNames

      public FixedWidthReader setFieldNames(Collection<String> fieldNames)
      Description copied from class: AbstractReader
      Sets the names given to each record's fields, taking precedence over names in the first row; must be called before AbstractReader.open().
      Overrides:
      setFieldNames in class AbstractReader
    • setStartingRow

      public FixedWidthReader setStartingRow(int startingRow)
      Description copied from class: AbstractReader
      Sets the 0-based index of the first row to read; earlier rows are skipped when the reader is opened (default is 0).
      Overrides:
      setStartingRow in class AbstractReader
    • setLastRow

      public FixedWidthReader setLastRow(int lastRow)
      Description copied from class: AbstractReader
      Sets the 0-based index of the last row to read or -1 to read to the end (default is -1).
      Overrides:
      setLastRow in class AbstractReader
    • setSkipEmptyRows

      public FixedWidthReader setSkipEmptyRows(boolean skipEmptyRows)
      Description copied from class: AbstractReader
      Indicates that rows with only null values should not be returned by the reader (default is false).
      Overrides:
      setSkipEmptyRows in class AbstractReader
    • setSaveLineage

      public FixedWidthReader setSaveLineage(boolean saveLineage)
      Description copied from class: DataReader
      Indicates if record and field lineage is captured for each record read (default is false); enabling it throws if DataReader.isLineageSupported() is false or the product edition does not include lineage.
      Overrides:
      setSaveLineage in class DataReader
    • setDescription

      public FixedWidthReader setDescription(String description)
      Description copied from class: Endpoint
      Sets the optional text shown for this endpoint in Endpoint.toString() and exception properties.
      Overrides:
      setDescription in class Endpoint
    • addExceptionProperties

      public DataException addExceptionProperties(DataException exception)
      Description copied from class: Endpoint
      Adds this endpoint's current state to a DataException. Since this method is called whenever an exception is thrown, subclasses should override it to add their specific information.
      Overrides:
      addExceptionProperties in class TextReader
    • open

      public void open() throws DataException
      Description copied from class: DataEndpoint
      Makes this endpoint ready for reading or writing.
      Overrides:
      open in class TextReader
      Throws:
      DataException
    • fillRecord

      protected boolean fillRecord(Record record) throws Throwable
      Description copied from class: AbstractReader
      Populates the given record with the next row's values; returns false at the end of the input.
      Specified by:
      fillRecord in class AbstractReader
      Throws:
      Throwable
    • isLineageSupported

      public boolean isLineageSupported()
      Description copied from class: DataReader
      Indicates if this reader can capture record and field lineage (false unless overridden by a reader that supports it).
      Overrides:
      isLineageSupported in class DataReader
    • addLineage

      protected Record addLineage(Record record)
      Description copied from class: DataReader
      Called by DataReader.read() for each record from DataReader.readImpl() while lineage is saved; the default copies recordLineage into every field along with its original index and name. Overrides set their source details on recordLineage first and end with super.addLineage(record).
      Overrides:
      addLineage in class TextReader