org.dawb.common.util.io
Class TokenFileParser

java.lang.Object
  extended by org.dawb.common.util.io.TokenFileParser

public class TokenFileParser
extends java.lang.Object

Read a tabbed delimited file into columns. Each row must have the same number of entries currently. Assumes that files are small. For larger files use StreamTokenizer(Reader r) which is more efficient.


Constructor Summary
TokenFileParser(java.io.File file)
           
TokenFileParser(java.io.InputStream unbuffered)
          NOTE Does not use StreamTokenizer so files need to be small.
TokenFileParser(java.net.URL url)
           
 
Method Summary
 java.util.List<java.lang.String> getColumn(int icol)
           
 java.lang.Double[] getColumnAsDoubleArray(int i, int... ignoreRows)
          Exceptions can be thrown if the column cannot parse as double
 java.util.List<java.lang.Double> getColumnAsDoubleList(int i, int... ignoreRows)
           
 java.lang.String getCommentChar()
           
 java.lang.String getToken()
           
static void main(java.lang.String[] args)
          Testing only
 void parse()
          Must be called to parse the file.
 void setCommentChar(java.lang.String commentChar)
           
 void setToken(java.lang.String token)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TokenFileParser

public TokenFileParser(java.net.URL url)
                throws java.io.IOException
Parameters:
url -
Throws:
java.io.IOException

TokenFileParser

public TokenFileParser(java.io.File file)
                throws java.io.IOException
Parameters:
file -
Throws:
java.io.IOException

TokenFileParser

public TokenFileParser(java.io.InputStream unbuffered)
                throws java.io.IOException
NOTE Does not use StreamTokenizer so files need to be small.

Parameters:
unbuffered -
Throws:
java.io.IOException
Method Detail

parse

public void parse()
           throws java.io.IOException
Must be called to parse the file.

Throws:
java.io.IOException

getColumn

public java.util.List<java.lang.String> getColumn(int icol)
Parameters:
icol -
Returns:
the exact column, modifying it will change the data

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Testing only

Parameters:
args -
Throws:
java.lang.Exception

getColumnAsDoubleArray

public java.lang.Double[] getColumnAsDoubleArray(int i,
                                                 int... ignoreRows)
Exceptions can be thrown if the column cannot parse as double

Parameters:
i -
Returns:
Double[]

getColumnAsDoubleList

public java.util.List<java.lang.Double> getColumnAsDoubleList(int i,
                                                              int... ignoreRows)
Parameters:
i -
ignoreRows -
Returns:
column as list of Doubles

getToken

public java.lang.String getToken()

setToken

public void setToken(java.lang.String token)

getCommentChar

public java.lang.String getCommentChar()

setCommentChar

public void setCommentChar(java.lang.String commentChar)