Class Truncate

All Implemented Interfaces:
BoolCellProcessor, CellProcessor, DateCellProcessor, DoubleCellProcessor, LongCellProcessor, StringCellProcessor

Ensure that Strings or String-representations of objects are truncated to a maximum size. If you desire, you can append a String to denote that the data has been truncated (e.g. "...").

As of 2.0.0, this functionality was moved from the Trim processor to this processor, to allow a clear distinction between trimming and truncating.

Author:
Kasper B. Graversen, James Bassett
  • Field Summary

    Fields inherited from class CellProcessorAdaptor

    next
  • Constructor Summary

    Constructors
    Constructor
    Description
    Truncate(int maxSize)
    Constructs a new Truncate processor, which truncates a String to ensure it is no longer than the specified size.
    Truncate(int maxSize, String suffix)
    Constructs a new Truncate processor, which truncates a String to ensure it is no longer than the specified size, then appends the suffix String to indicate that the String has been truncated.
    Truncate(int maxSize, String suffix, StringCellProcessor next)
    Constructs a new Truncate processor, which truncates a String to ensure it is no longer than the specified size, then appends the suffix String to indicate that the String has been truncated and calls the next processor in the chain.
    Truncate(int maxSize, StringCellProcessor next)
    Constructs a new Truncate processor, which truncates a String to ensure it is no longer than the specified size, then calls the next processor in the chain.
  • Method Summary

    Modifier and Type
    Method
    Description
    execute(Object value, CsvContext context)
    This method is invoked by the framework when the processor needs to process data or check constraints.

    Methods inherited from class CellProcessorAdaptor

    toString, validateInputNotNull

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Truncate

      public Truncate(int maxSize)
      Constructs a new Truncate processor, which truncates a String to ensure it is no longer than the specified size.
      Parameters:
      maxSize - the maximum size of the String
      Throws:
      IllegalArgumentException - if maxSize <= 0
    • Truncate

      public Truncate(int maxSize, String suffix)
      Constructs a new Truncate processor, which truncates a String to ensure it is no longer than the specified size, then appends the suffix String to indicate that the String has been truncated.
      Parameters:
      maxSize - the maximum size of the String
      suffix - the String to append if the input is truncated (e.g. "...")
      Throws:
      IllegalArgumentException - if maxSize <= 0
      NullPointerException - if suffix is null
    • Truncate

      public Truncate(int maxSize, String suffix, StringCellProcessor next)
      Constructs a new Truncate processor, which truncates a String to ensure it is no longer than the specified size, then appends the suffix String to indicate that the String has been truncated and calls the next processor in the chain.
      Parameters:
      maxSize - the maximum size of the String
      suffix - the String to append if the input is truncated (e.g. "...")
      next - the next processor in the chain
      Throws:
      IllegalArgumentException - if maxSize <= 0
      NullPointerException - if suffix or next is null
    • Truncate

      public Truncate(int maxSize, StringCellProcessor next)
      Constructs a new Truncate processor, which truncates a String to ensure it is no longer than the specified size, then calls the next processor in the chain.
      Parameters:
      maxSize - the maximum size of the String
      next - the next processor in the chain
      Throws:
      IllegalArgumentException - if maxSize <= 0
      NullPointerException - if next is null
  • Method Details

    • execute

      public Object execute(Object value, CsvContext context)
      This method is invoked by the framework when the processor needs to process data or check constraints.
      Specified by:
      execute in interface CellProcessor
      Parameters:
      value - the value to be processed
      context - the CSV context
      Returns:
      the result of cell processor execution
      Throws:
      SuperCsvCellProcessorException - if value is null