Top Description Fields Constructors Methods
com.univocity.parsers.csv

public abstract Class CsvFormatDetector

extends Object
implements InputAnalysisProcess
Class Inheritance
All Implemented Interfaces
com.univocity.parsers.common.input.InputAnalysisProcess
Imports
com.univocity.parsers.common.*, com.univocity.parsers.common.input.*, java.util.*, java.util.Map.*

An InputAnalysisProcess to detect column delimiters, quotes and quote escapes in a CSV input.
Author
Univocity Software Pty Ltd - [email protected]

Field Summary

Modifier and TypeField and Description
private char[]
private final char
private char[]
private final int
private final char
private final char
private final char
private final char
private final int

Constructor Summary

AccessConstructor and Description
public
CsvFormatDetector(int
the number of row samples to collect before analyzing the statistics
maxRowSamples
,
CsvParserSettings
the configuration provided by the user with potential defaults in case the detection is unable to discover the proper column delimiter or quote character.
settings
,
int
starting range of characters considered to be whitespace.
whitespaceRangeStart
)

Builds a new CsvFormatDetector

Method Summary

Modifier and TypeMethod and Description
protected abstract void
apply(char
the discovered delimiter character
delimiter
,
char
the discovered quote character
quote
,
char
the discovered quote escape character.
quoteEscape
)

Applies the discovered CSV format elements to the CsvParser

protected Map<Character, Integer>
public void
execute(char[]
the input buffer
characters
,
int
the last character position loaded into the buffer.
length
)

Implements com.univocity.parsers.common.input.InputAnalysisProcess.execute.

A sequence of characters of the input buffer to be analyzed.
protected char

Returns:

the character with the highest/lowest number associated.
getChar
(Map<Character, Integer>
the map of characters and their numbers
map
,
Map<Character, Integer> totals, char
the default character to return in case the map is empty
defaultChar
,
boolean
a flag indicating whether to return the character associated with the lowest number in the map. If false then the character associated with the highest number found will be returned.
min
)

Returns the character with the highest or lowest associated number.

protected void
increment(Map<Character, Integer>
the map of characters and their numbers
map
,
char
the character whose number should be increment
symbol
)

Increments the number associated with a character in a map by 1

protected void
increment(Map<Character, Integer>
the map of characters and their numbers
map
,
char
the character whose number should be increment
symbol
,
int
the size of the increment
incrementSize
)

Increments the number associated with a character in a map

protected boolean
protected boolean
isSymbol(char ch)

protected char

Returns:

the character with the highest number associated.
max
(Map<Character, Integer>
the map of characters and their numbers
map
,
Map<Character, Integer> totals, char
the default character to return in case the map is empty
defaultChar
)

Returns the character with the highest associated number.

protected char

Returns:

the character with the lowest number associated.
min
(Map<Character, Integer>
the map of characters and their numbers
map
,
Map<Character, Integer> totals, char
the default character to return in case the map is empty
defaultChar
)

Returns the character with the lowest associated number.

protected char
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

allowedDelimitersback to summary
private char[] allowedDelimiters
commentback to summary
private final char comment
delimiterPreferenceback to summary
private char[] delimiterPreference
MAX_ROW_SAMPLESback to summary
private final int MAX_ROW_SAMPLES
normalizedNewLineback to summary
private final char normalizedNewLine
suggestedDelimiterback to summary
private final char suggestedDelimiter
suggestedQuoteback to summary
private final char suggestedQuote
suggestedQuoteEscapeback to summary
private final char suggestedQuoteEscape
whitespaceRangeStartback to summary
private final int whitespaceRangeStart

Constructor Detail

CsvFormatDetectorback to summary
public CsvFormatDetector(int maxRowSamples, CsvParserSettings settings, int whitespaceRangeStart)

Builds a new CsvFormatDetector

Parameters
maxRowSamples:int

the number of row samples to collect before analyzing the statistics

settings:CsvParserSettings

the configuration provided by the user with potential defaults in case the detection is unable to discover the proper column delimiter or quote character.

whitespaceRangeStart:int

starting range of characters considered to be whitespace.

Method Detail

applyback to summary
protected abstract void apply(char delimiter, char quote, char quoteEscape)

Applies the discovered CSV format elements to the CsvParser

Parameters
delimiter:char

the discovered delimiter character

quote:char

the discovered quote character

quoteEscape:char

the discovered quote escape character.

calculateTotalsback to summary
protected Map<Character, Integer> calculateTotals(List<Map<Character, Integer>> symbolsPerRow)
executeback to summary
public void execute(char[] characters, int length)

Implements com.univocity.parsers.common.input.InputAnalysisProcess.execute.

Doc from com.univocity.parsers.common.input.InputAnalysisProcess.execute.

A sequence of characters of the input buffer to be analyzed.

Parameters
characters:char[]

the input buffer

length:int

the last character position loaded into the buffer.

Annotations
@Override
getCharback to summary
protected char getChar(Map<Character, Integer> map, Map<Character, Integer> totals, char defaultChar, boolean min)

Returns the character with the highest or lowest associated number.

Parameters
map:Map<Character, Integer>

the map of characters and their numbers

defaultChar:char

the default character to return in case the map is empty

min:boolean

a flag indicating whether to return the character associated with the lowest number in the map. If false then the character associated with the highest number found will be returned.

Returns:char

the character with the highest/lowest number associated.

incrementback to summary
protected void increment(Map<Character, Integer> map, char symbol)

Increments the number associated with a character in a map by 1

Parameters
map:Map<Character, Integer>

the map of characters and their numbers

symbol:char

the character whose number should be increment

incrementback to summary
protected void increment(Map<Character, Integer> map, char symbol, int incrementSize)

Increments the number associated with a character in a map

Parameters
map:Map<Character, Integer>

the map of characters and their numbers

symbol:char

the character whose number should be increment

incrementSize:int

the size of the increment

isAllowedDelimiterback to summary
protected boolean isAllowedDelimiter(char ch)
isSymbolback to summary
protected boolean isSymbol(char ch)
maxback to summary
protected char max(Map<Character, Integer> map, Map<Character, Integer> totals, char defaultChar)

Returns the character with the highest associated number.

Parameters
map:Map<Character, Integer>

the map of characters and their numbers

defaultChar:char

the default character to return in case the map is empty

Returns:char

the character with the highest number associated.

minback to summary
protected char min(Map<Character, Integer> map, Map<Character, Integer> totals, char defaultChar)

Returns the character with the lowest associated number.

Parameters
map:Map<Character, Integer>

the map of characters and their numbers

defaultChar:char

the default character to return in case the map is empty

Returns:char

the character with the lowest number associated.

pickDelimiterback to summary
protected char pickDelimiter(Map<Character, Integer> sums, Map<Character, Integer> totals)