ariba.ui.aribaweb.util
Class CSVReader

java.lang.Object
  extended by ariba.ui.aribaweb.util.CSVReader

public final class CSVReader
extends java.lang.Object

CSVReader parses files in CSV (comma separated values) format. Subclassers should implement the consumeLineOfTokens method.


Constructor Summary
CSVReader(CSVConsumer csvConsumer)
          Create a new CSVReader using a specific CSVConsumer to handle the rows.
 
Method Summary
 java.lang.String getEncoding()
          Return the encoding used for the last read operation.
 boolean isEncodingExplicitlySet()
          Returns true if the file had the encoding as the first line in the file, e.g.
 void read(java.io.File file, java.lang.String encoding)
          Reads the specified file, using the character encoding for the default locale.
 void read(java.io.Reader reader, java.lang.String location)
          The primitive read entry point.
 void read(java.net.URL url, java.lang.String defaultEncoding)
          Reads the specified URL, using the character encoding for the default locale.
 void readForSpecifiedEncoding(java.io.File file)
          Will read from the specified stream in the encoding specified on the first line of the stream.
 void readForSpecifiedEncoding(java.io.InputStream inputStream, java.lang.String location)
          Will read from the specified stream in the encoding specified on the first line of the stream.
 void readForSpecifiedEncoding(java.net.URL url)
          Will read from the specified stream in the encoding specified on the first line of the stream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CSVReader

public CSVReader(CSVConsumer csvConsumer)
Create a new CSVReader using a specific CSVConsumer to handle the rows. After reading has been performed, the CSVReader can be asked what the encoding was used.

Method Detail

getEncoding

public java.lang.String getEncoding()
Return the encoding used for the last read operation. May be null if a Reader was passed in so we never know the underlying encoding if any.

Returns:
The value of the content-encoding header field.

isEncodingExplicitlySet

public boolean isEncodingExplicitlySet()
Returns true if the file had the encoding as the first line in the file, e.g. 8859_1 or 8859_1,,

Returns:
boolean indicating if the file has the encoding in the first line

read

public void read(java.net.URL url,
                 java.lang.String defaultEncoding)
          throws java.io.IOException
Reads the specified URL, using the character encoding for the default locale.

Parameters:
url - the URL to read the data from
defaultEncoding - the encoding to use to read the data if none can be determined from the URLConnection
Throws:
java.io.IOException - any IOException reading from the URL

read

public void read(java.io.File file,
                 java.lang.String encoding)
          throws java.io.IOException
Reads the specified file, using the character encoding for the default locale.

Parameters:
file - a path to the file to read
encoding - The encoding used for reading the file
Throws:
java.io.IOException - any IOException reading from the file could not be read.

readForSpecifiedEncoding

public void readForSpecifiedEncoding(java.net.URL url)
                              throws java.io.IOException
Will read from the specified stream in the encoding specified on the first line of the stream. For instance, the first line of the file may be "8859_1", or may be "8859_1,,,". The "8859_1" will be passed into read(inputStream, encoding, path) as the encoding.

Parameters:
url - the URL to read the data from
Throws:
java.io.IOException - any IOException reading from the URL

readForSpecifiedEncoding

public final void readForSpecifiedEncoding(java.io.File file)
                                    throws java.io.IOException
Will read from the specified stream in the encoding specified on the first line of the stream. For instance, the first line of the file may be "8859_1", or may be "8859_1,,,". The "8859_1" will be passed into read(inputStream, encoding, path) as the encoding.

Parameters:
file - the path to the file to read
Throws:
java.io.IOException - if an IOException occurs while reading the file
See Also:
read(Reader, String)

readForSpecifiedEncoding

public final void readForSpecifiedEncoding(java.io.InputStream inputStream,
                                           java.lang.String location)
                                    throws java.io.IOException
Will read from the specified stream in the encoding specified on the first line of the stream. For instance, the first line of the file may be "8859_1", or may be "8859_1,,,". The "8859_1" will be passed into read(inputStream, encoding, path) as the encoding.

Parameters:
inputStream - the InputStream to read the data from
location - the path to the data source for debugging messages
Throws:
java.io.IOException - if an IOException occurs while reading the file
See Also:
read(Reader, String)

read

public final void read(java.io.Reader reader,
                       java.lang.String location)
                throws java.io.IOException
The primitive read entry point. This method calls the CSVConsumer callback for each line read.

Parameters:
reader - the data source as passed in by one of the higher level read methods
location - the path for debugging messages
Throws:
java.io.IOException - if an IOException occurs while reading from reader
See Also:
CSVConsumer.consumeLineOfTokens(java.lang.String, int, java.util.List)


AribaWeb User Interface Development Framework
Copyright © 2000-2014 Ariba, Inc. All Rights Reserved.