Class FixedWidthWriter


public class FixedWidthWriter extends LinedTextWriter
Writes records to a fixed width stream.
  • Constructor Details

    • FixedWidthWriter

      public FixedWidthWriter(File file, boolean append)
      Parameters:
      file -
      append - Indicates if writing should start at the end of the file (if it exists). If the specified file exists and has contents (more than 0 bytes), then the fieldNamesInFirstRow property will be set to false.
    • FixedWidthWriter

      public FixedWidthWriter(File file)
    • FixedWidthWriter

      public FixedWidthWriter(Writer writer)
  • Method Details

    • getFillChar

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

      public FixedWidthWriter setFillChar(char fillChar)
      Sets the character used to pad values in columns without their own fill character (defaults to space).
    • isTruncateFields

      public boolean isTruncateFields()
      Indicates if values longer than their column are cut to fit instead of failing the write (default is true).
    • setTruncateFields

      public FixedWidthWriter setTruncateFields(boolean truncateFields)
      Indicates if values longer than their column are cut to fit instead of failing the write (default is true).
    • addField

      public FixedWidthWriter addField(FixedWidthField field)
      Appends a column; each record written must have exactly one field per column, matched by position.
    • addFields

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

      public FixedWidthWriter addField(int width, FixedWidthAlign align, char fillChar)
    • setFieldNamesInFirstRow

      public FixedWidthWriter setFieldNamesInFirstRow(boolean fieldNamesInFirstRow)
      Description copied from class: AbstractWriter
      Indicates if a header row of field names is written before the first record (default is true); must be called before AbstractWriter.open().
      Overrides:
      setFieldNamesInFirstRow in class AbstractWriter
    • setDescription

      public FixedWidthWriter 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
    • setNewLine

      public FixedWidthWriter setNewLine(String newLine)
      Description copied from class: LinedTextWriter
      Assigns the string used between each line (defaults to "\n" on Linux and "\r\n" on Windows).
      Overrides:
      setNewLine in class LinedTextWriter
    • setAutoCloseWriter

      public FixedWidthWriter setAutoCloseWriter(boolean autoCloseWriter)
      Description copied from class: TextWriter
      Indicates if the underlying java.io.BufferedWriter should be closed when this stream closes (defaults to true).
      Overrides:
      setAutoCloseWriter in class TextWriter
    • setFlushOnWrite

      public FixedWidthWriter setFlushOnWrite(boolean flushOnWrite)
      Description copied from class: TextWriter
      Indicates if the underlying java.io.BufferedWriter should be flushed after each record is written (defaults to false).
      Overrides:
      setFlushOnWrite in class TextWriter
    • 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 LinedTextWriter
    • assembleLine

      protected void assembleLine(Record record, StringBuilder lineBuffer) throws Throwable
      Description copied from class: LinedTextWriter
      Appends the record's output line, without a line terminator, to the empty buffer; also called for the header row (see AbstractWriter.isHeaderRow()).
      Specified by:
      assembleLine in class LinedTextWriter
      Throws:
      Throwable