org.apache.commons.csv.writer
Class CSVConfigGuesser

java.lang.Object
  extended by org.apache.commons.csv.writer.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  java.io.InputStream in
          The stream to read
 
Constructor Summary
CSVConfigGuesser()
           
CSVConfigGuesser(java.io.InputStream in)
           
 
Method Summary
protected  void analyseLines(java.lang.String[] lines)
           
protected  java.io.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(java.lang.String[] lines)
           
protected  void guessFixedWidth(java.lang.String[] lines)
          Guess if this file is fixedwidth.
protected  void guessFixedWidthSeperator(java.lang.String[] lines)
           
 boolean hasFieldHeader()
           
 void setHasFieldHeader(boolean hasFieldHeader)
          Specify if the CSV file has a field header
 void setInputStream(java.io.InputStream in)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

in

private java.io.InputStream in
The stream to read


hasFieldHeader

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


config

protected CSVConfig config
The found config

Constructor Detail

CSVConfigGuesser

public CSVConfigGuesser()

CSVConfigGuesser

public CSVConfigGuesser(java.io.InputStream in)
Parameters:
in - the inputstream to guess from
Method Detail

setInputStream

public void setInputStream(java.io.InputStream in)

getInputStream

protected java.io.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.

analyseLines

protected void analyseLines(java.lang.String[] lines)

guessFixedWidth

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

Parameters:
lines -

guessFieldSeperator

protected void guessFieldSeperator(java.lang.String[] lines)

guessFixedWidthSeperator

protected void guessFixedWidthSeperator(java.lang.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