org.apache.commons.csv.writer

Class CSVConfigGuesser


public class CSVConfigGuesser
extends java.lang.Object

Tries to guess a config based on an InputStream.
Version:
$Id: $
Author:
Martin van den Bemt

Field Summary

protected CSVConfig
config
The found config
private boolean
hasFieldHeader
if the file has a field header (need this info, to be able to guess better) Defaults to false
private InputStream
in
The stream to read

Constructor Summary

CSVConfigGuesser()
CSVConfigGuesser(InputStream in)

Method Summary

protected void
analyseLines(String[] lines)
protected InputStream
getInputStream()
Allow override.
CSVConfig
guess()
Guess the config based on the first 10 (or less when less available) records of a CSV file.
protected void
guessFieldSeperator(String[] lines)
protected void
guessFixedWidth(String[] lines)
Guess if this file is fixedwidth.
protected void
guessFixedWidthSeperator(String[] lines)
boolean
hasFieldHeader()
void
setHasFieldHeader(boolean hasFieldHeader)
Specify if the CSV file has a field header
void
setInputStream(InputStream in)

Field Details

config

protected CSVConfig config
The found config

hasFieldHeader

private boolean hasFieldHeader
if the file has a field header (need this info, to be able to guess better) Defaults to false

in

private InputStream in
The stream to read

Constructor Details

CSVConfigGuesser

public CSVConfigGuesser()

CSVConfigGuesser

public CSVConfigGuesser(InputStream in)
Parameters:
in - the inputstream to guess from

Method Details

analyseLines

protected void analyseLines(String[] lines)

getInputStream

protected InputStream getInputStream()
Allow override.
Returns:
the inputstream that was set.

guess

public CSVConfig guess()
Guess the config based on the first 10 (or less when less available) records of a CSV file.
Returns:
the guessed config.

guessFieldSeperator

protected void guessFieldSeperator(String[] lines)

guessFixedWidth

protected void guessFixedWidth(String[] lines)
Guess if this file is fixedwidth. Just basing the fact on all lines being of the same length
Parameters:
lines -

guessFixedWidthSeperator

protected void guessFixedWidthSeperator(String[] lines)

hasFieldHeader

public boolean hasFieldHeader()
Returns:
if the field uses a field header. Defaults to false.

setHasFieldHeader

public void setHasFieldHeader(boolean hasFieldHeader)
Specify if the CSV file has a field header
Parameters:
hasFieldHeader - true or false

setInputStream

public void setInputStream(InputStream in)