Package org.supercsv.cellprocessor
Class Truncate
java.lang.Object
org.supercsv.cellprocessor.CellProcessorAdaptor
org.supercsv.cellprocessor.Truncate
- All Implemented Interfaces:
BoolCellProcessor
,CellProcessor
,DateCellProcessor
,DoubleCellProcessor
,LongCellProcessor
,StringCellProcessor
public class Truncate
extends CellProcessorAdaptor
implements BoolCellProcessor, 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.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String
private final int
private final String
Fields inherited from class org.supercsv.cellprocessor.CellProcessorAdaptor
next
-
Constructor Summary
ConstructorsConstructorDescriptionTruncate
(int maxSize) Constructs a new Truncate processor, which truncates a String to ensure it is no longer than the specified size.Constructs a new Truncate processor, which truncates a String to ensure it is no longer than the specified size, then appends thesuffix
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 thesuffix
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 TypeMethodDescriptionprivate static void
checkPreconditions
(int maxSize, String suffix) Checks the preconditions for creating a new Truncate processor.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 org.supercsv.cellprocessor.CellProcessorAdaptor
toString, validateInputNotNull
-
Field Details
-
EMPTY_STRING
- See Also:
-
maxSize
private final int maxSize -
suffix
-
-
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
- ifmaxSize <= 0
-
Truncate
Constructs a new Truncate processor, which truncates a String to ensure it is no longer than the specified size, then appends thesuffix
String to indicate that the String has been truncated.- Parameters:
maxSize
- the maximum size of the Stringsuffix
- the String to append if the input is truncated (e.g. "...")- Throws:
IllegalArgumentException
- ifmaxSize <= 0
NullPointerException
- if suffix is null
-
Truncate
Constructs a new Truncate processor, which truncates a String to ensure it is no longer than the specified size, then appends thesuffix
String to indicate that the String has been truncated and calls the next processor in the chain.- Parameters:
maxSize
- the maximum size of the Stringsuffix
- the String to append if the input is truncated (e.g. "...")next
- the next processor in the chain- Throws:
IllegalArgumentException
- ifmaxSize <= 0
NullPointerException
- if suffix or next is null
-
Truncate
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 Stringnext
- the next processor in the chain- Throws:
IllegalArgumentException
- ifmaxSize <= 0
NullPointerException
- if next is null
-
-
Method Details
-
checkPreconditions
Checks the preconditions for creating a new Truncate processor.- Parameters:
maxSize
- the maximum size of the Stringsuffix
- the String to append if the input is truncated (e.g. "...")- Throws:
IllegalArgumentException
- ifmaxSize <= 0
NullPointerException
- if suffix is null
-
execute
This method is invoked by the framework when the processor needs to process data or check constraints.- Specified by:
execute
in interfaceCellProcessor
- Parameters:
value
- the value to be processedcontext
- the CSV context- Returns:
- the result of cell processor execution
- Throws:
SuperCsvCellProcessorException
- if value is null
-