net.sf.jmatchparser.util.csv
Class FixedWidthCSVReader

java.lang.Object
  extended by net.sf.jmatchparser.util.csv.AbstractCSVReader
      extended by net.sf.jmatchparser.util.csv.FixedWidthCSVReader

public class FixedWidthCSVReader
extends AbstractCSVReader

Class to read data from a fixed width CSV (Comma Separated Value) file, where every column has a fixed width and may optionally additionally delimited by separator characters.


Constructor Summary
FixedWidthCSVReader(BufferedReader br, FixedWidthColumn... columns)
          Create a new FixedWidthCSVReader that reads from the given buffered reader using the given columns and no separators.
FixedWidthCSVReader(BufferedReader br, int... widths)
          Create a new FixedWidthCSVReader that reads from the given buffered reader using left-aligned space-padded columns only and no separators.
FixedWidthCSVReader(BufferedReader br, String... columnSpecs)
          Create a new FixedWidthCSVReader that reads from the given buffered reader using columns parsed from the given column specs and no separators.
FixedWidthCSVReader(BufferedReader br, String prefix, String separator, String suffix, FixedWidthColumn... columns)
          Create a new FixedWidthCSVReader that reads from the given buffered reader using the given columns and separators.
FixedWidthCSVReader(InputStream in, String charsetName, FixedWidthColumn... columns)
          Create a new FixedWidthCSVReader that reads from the given stream using the given columns and no separators.
FixedWidthCSVReader(InputStream in, String charsetName, int... widths)
          Create a new FixedWidthCSVReader that reads from the given stream using left-aligned space-padded columns only and no separators.
FixedWidthCSVReader(InputStream in, String charsetName, String... columnSpecs)
          Create a new FixedWidthCSVReader that reads from the given stream using columns parsed from the given column specs and no separators.
FixedWidthCSVReader(InputStream in, String charsetName, String prefix, String separator, String suffix, FixedWidthColumn... columns)
          Create a new FixedWidthCSVReader that reads from the given stream using the given columns and separators.
FixedWidthCSVReader(Reader r, FixedWidthColumn... columns)
          Create a new FixedWidthCSVReader that reads from the given reader using the given columns and no separators.
FixedWidthCSVReader(Reader r, int... widths)
          Create a new FixedWidthCSVReader that reads from the given reader using left-aligned space-padded columns only and no separators.
FixedWidthCSVReader(Reader r, String... columnSpecs)
          Create a new FixedWidthCSVReader that reads from the given reader using columns parsed from the given column specs and no separators.
FixedWidthCSVReader(Reader r, String prefix, String separator, String suffix, FixedWidthColumn... columns)
          Create a new FixedWidthCSVReader that reads from the given reader using the given columns and separators.
 
Method Summary
 void close()
          Close this reader.
 String[] read()
          Read a line from the fixed width CSV file.
 void setStripComments(boolean stripComments)
          Set whether comments (lines starting with # or empty lines) should be stripped.
 
Methods inherited from class net.sf.jmatchparser.util.csv.AbstractCSVReader
read, read, writeTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FixedWidthCSVReader

public FixedWidthCSVReader(BufferedReader br,
                           int... widths)
Create a new FixedWidthCSVReader that reads from the given buffered reader using left-aligned space-padded columns only and no separators.

Parameters:
br - The buffered reader to read from
widths - The width of each column

FixedWidthCSVReader

public FixedWidthCSVReader(BufferedReader br,
                           String... columnSpecs)
                    throws IOException
Create a new FixedWidthCSVReader that reads from the given buffered reader using columns parsed from the given column specs and no separators.

Parameters:
br - The buffered reader to read from
columnSpecs - The format specification of each column
Throws:
IOException

FixedWidthCSVReader

public FixedWidthCSVReader(BufferedReader br,
                           FixedWidthColumn... columns)
Create a new FixedWidthCSVReader that reads from the given buffered reader using the given columns and no separators.

Parameters:
br - The buffered reader to read from
columns - The format of each column

FixedWidthCSVReader

public FixedWidthCSVReader(BufferedReader br,
                           String prefix,
                           String separator,
                           String suffix,
                           FixedWidthColumn... columns)
Create a new FixedWidthCSVReader that reads from the given buffered reader using the given columns and separators.

Parameters:
br - The buffered reader to read from
prefix - The prefix to add to each line
separator - The separator to add between each field
suffix - The suffix to add to each line
columns - The format of each column

FixedWidthCSVReader

public FixedWidthCSVReader(Reader r,
                           int... widths)
Create a new FixedWidthCSVReader that reads from the given reader using left-aligned space-padded columns only and no separators.

Parameters:
r - The reader to read from
widths - The width of each column

FixedWidthCSVReader

public FixedWidthCSVReader(Reader r,
                           String... columnSpecs)
                    throws IOException
Create a new FixedWidthCSVReader that reads from the given reader using columns parsed from the given column specs and no separators.

Parameters:
r - The reader to read from
columnSpecs - The format specification of each column
Throws:
IOException

FixedWidthCSVReader

public FixedWidthCSVReader(Reader r,
                           FixedWidthColumn... columns)
Create a new FixedWidthCSVReader that reads from the given reader using the given columns and no separators.

Parameters:
r - The reader to read from
columns - The format of each column

FixedWidthCSVReader

public FixedWidthCSVReader(Reader r,
                           String prefix,
                           String separator,
                           String suffix,
                           FixedWidthColumn... columns)
Create a new FixedWidthCSVReader that reads from the given reader using the given columns and separators.

Parameters:
r - The reader to read from
prefix - The prefix to add to each line
separator - The separator to add between each field
suffix - The suffix to add to each line
columns - The format of each column

FixedWidthCSVReader

public FixedWidthCSVReader(InputStream in,
                           String charsetName,
                           int... widths)
                    throws UnsupportedEncodingException
Create a new FixedWidthCSVReader that reads from the given stream using left-aligned space-padded columns only and no separators.

Parameters:
in - The input stream to read from
charsetName - Name of the charset to be used
widths - The width of each column
Throws:
UnsupportedEncodingException

FixedWidthCSVReader

public FixedWidthCSVReader(InputStream in,
                           String charsetName,
                           String... columnSpecs)
                    throws IOException
Create a new FixedWidthCSVReader that reads from the given stream using columns parsed from the given column specs and no separators.

Parameters:
in - The input stream to read from
charsetName - Name of the charset to be used
columnSpecs - The format specification of each column
Throws:
IOException

FixedWidthCSVReader

public FixedWidthCSVReader(InputStream in,
                           String charsetName,
                           FixedWidthColumn... columns)
                    throws UnsupportedEncodingException
Create a new FixedWidthCSVReader that reads from the given stream using the given columns and no separators.

Parameters:
in - The input stream to read from
charsetName - Name of the charset to be used
columns - The format of each column
Throws:
UnsupportedEncodingException

FixedWidthCSVReader

public FixedWidthCSVReader(InputStream in,
                           String charsetName,
                           String prefix,
                           String separator,
                           String suffix,
                           FixedWidthColumn... columns)
                    throws UnsupportedEncodingException
Create a new FixedWidthCSVReader that reads from the given stream using the given columns and separators.

Parameters:
in - The input stream to read from
charsetName - Name of the charset to be used
prefix - The prefix to add to each line
separator - The separator to add between each field
suffix - The suffix to add to each line
columns - The format of each column
Throws:
UnsupportedEncodingException
Method Detail

close

public void close()
           throws IOException
Description copied from class: AbstractCSVReader
Close this reader.

Specified by:
close in class AbstractCSVReader
Throws:
IOException

setStripComments

public void setStripComments(boolean stripComments)
Set whether comments (lines starting with # or empty lines) should be stripped.


read

public String[] read()
              throws IOException
Read a line from the fixed width CSV file.

Specified by:
read in class AbstractCSVReader
Throws:
IOException


Copyright © 2011. All Rights Reserved.