Class FixedWidthTextReader

java.lang.Object
com.aquima.interactions.framework.util.textdata.AbstractTextDataReader
com.aquima.interactions.framework.util.textdata.FixedWidthTextReader

public class FixedWidthTextReader extends AbstractTextDataReader
This class can be used to read a fixed width text resource.

Fixed width text files are special cases of text files where the format is specified by column widths, pad character and left/right alignment. Column widths are in units of characters. So if you have data in a text file where the first column always has exactly 10 characters, and the second column has exactly 5, the third has exactly 12 (and so on), then you have a fixed width text file.

Each row (line) contains one record of information; each record can contain multiple pieces of data (fields), each data field (column) has a precise number of characters. The data is padded with spaces (or any character you specify) if it does not completely use all the characters allotted to it. Further, each piece of data can be left, right or center justified, meaning the padding of characters can occur on either side (or both, for center).

Since:
6.3
Author:
Jon van Leuven
  • Field Details

    • ALIGNMENT_LEFT

      public static final int ALIGNMENT_LEFT
      Left alignment
      See Also:
    • ALIGNMENT_RIGHT

      public static final int ALIGNMENT_RIGHT
      Right alignment
      See Also:
    • ALIGNMENT_CENTER

      public static final int ALIGNMENT_CENTER
      Center alignment
      See Also:
    • DEFAULT_ALIGNMENT

      public static final int DEFAULT_ALIGNMENT
      Default alignment: left
      See Also:
    • DEFAULT_PADDING_CHARACTER

      public static final char DEFAULT_PADDING_CHARACTER
      Default padding character: space character
      See Also:
  • Constructor Details

    • FixedWidthTextReader

      public FixedWidthTextReader(IResource resource, int[] columnWidths)
      Constructs FixedWidthTextReader with supplied column widths.
      Parameters:
      resource - the resource to an underlying text source.
      columnWidths - an array of the column widths.
      Throws:
      ResourceException - Occurs when problem reading the text source.
    • FixedWidthTextReader

      public FixedWidthTextReader(IResource resource, int[] columnWidths, char paddingCharacter)
      Constructs FixedWidthTextReader with supplied column widths and padding character.
      Parameters:
      resource - the resource to an underlying text source.
      columnWidths - an array of the column widths.
      paddingCharacter - the padding character used to trim the columns.
      Throws:
      ResourceException - Occurs when problem reading the text source.
    • FixedWidthTextReader

      public FixedWidthTextReader(IResource resource, int[] columnWidths, char paddingCharacter, int alignment, String charset)
      Constructs FixedWidthTextReader with supplied column widths, padding character, alignment and charset.
      Parameters:
      resource - the resource to an underlying text source.
      columnWidths - an array of the column widths.
      paddingCharacter - the padding character used to trim the columns.
      alignment - The alignment to use (left/right or center).
      charset - the charset to use for decoding
      Throws:
      ResourceException - Occurs when problem reading the text source.
      See Also:
    • FixedWidthTextReader

      public FixedWidthTextReader(IResource resource, int[] columnWidths, char paddingCharacter, int alignment, int skipLines)
      Constructs FixedWidthTextReader with supplied column widths, padding character and alignment.
      Parameters:
      resource - the resource to an underlying text source.
      columnWidths - an array of the column widths.
      paddingCharacter - the padding character used to trim the columns.
      alignment - The alignment to use (left/right or center).
      skipLines - the number of lines to skip
      Throws:
      ResourceException - Occurs when problem reading the text source.
      See Also:
    • FixedWidthTextReader

      public FixedWidthTextReader(IResource resource, int[] columnWidths, char paddingCharacter, int alignment, int skipLines, String charset)
      Constructs FixedWidthTextReader with supplied column widths, padding character, alignment, number of lines to skip and charset.
      Parameters:
      resource - the resource to an underlying text source.
      columnWidths - an array of the column widths.
      paddingCharacter - the padding character used to trim the columns.
      alignment - the alignment to use (left/right or center).
      skipLines - the line number to skip for start reading.
      charset - the charset used for decoding.
      Throws:
      ResourceException - Occurs when problem reading the text source.
      See Also:
  • Method Details