org.das2.dataset.parser
Class VectorDataSetParser

java.lang.Object
  extended by org.das2.dataset.parser.VectorDataSetParser

public class VectorDataSetParser
extends java.lang.Object

Class for reading ascii tables into a VectorDataSet. This parses a file by looking at each line to see if it matches one of two Patterns: one for properties and one for records. If a record matched, then the record is matched and fields pulled out, parsed and insered a VectorDataSetBuilder. If a property is matched, then the builder property is set. Two Patterns are provided NAME_COLON_VALUE_PATTERN and NAME_EQUAL_VALUE_PATTERN for convenience. The record pattern is currently the number of fields identified with whitespace in between. Note the X tags are just the record numbers.


Field Summary
static java.util.regex.Pattern NAME_COLON_VALUE_PATTERN
           
static java.util.regex.Pattern NAME_EQUAL_VALUE_PATTERN
           
 
Method Summary
static int guessFieldCount(java.lang.String filename)
          return the field count that would result in the largest number of records parsed.
static void main(java.lang.String[] args)
           
static VectorDataSetParser newParser(int fieldCount)
          creates a parser with @param fieldCount fields, named "field0,...,fieldN"
static VectorDataSetParser newParser(java.lang.String[] fieldNames)
          creates a parser with the named fields.
 VectorDataSet readFile(java.lang.String filename)
          Parse the file using the current settings.
 VectorDataSet readStream(java.io.InputStream in)
          Parse the stream using the current settings.
 void setPropertyPattern(java.util.regex.Pattern propertyPattern)
          specify the Pattern used to recognize properties.
 void setRecordCountLimit(int recordCountLimit)
          limit the number of records read.
 void setSkipLines(int skipLines)
          skip a number of lines before trying to parse anything.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAME_COLON_VALUE_PATTERN

public static final java.util.regex.Pattern NAME_COLON_VALUE_PATTERN

NAME_EQUAL_VALUE_PATTERN

public static final java.util.regex.Pattern NAME_EQUAL_VALUE_PATTERN
Method Detail

guessFieldCount

public static int guessFieldCount(java.lang.String filename)
                           throws java.io.FileNotFoundException,
                                  java.io.IOException
return the field count that would result in the largest number of records parsed. The entire file is scanned, and for each line the number of decimal fields is counted. At the end of the scan, the fieldCount with the highest record count is returned.

Throws:
java.io.FileNotFoundException
java.io.IOException

newParser

public static VectorDataSetParser newParser(int fieldCount)
creates a parser with @param fieldCount fields, named "field0,...,fieldN"


newParser

public static VectorDataSetParser newParser(java.lang.String[] fieldNames)
creates a parser with the named fields.


setSkipLines

public void setSkipLines(int skipLines)
skip a number of lines before trying to parse anything.


setRecordCountLimit

public void setRecordCountLimit(int recordCountLimit)
limit the number of records read. parsing will stop at this limit.


setPropertyPattern

public void setPropertyPattern(java.util.regex.Pattern propertyPattern)
specify the Pattern used to recognize properties. Note property values are not parsed, they are provided as Strings.


readStream

public VectorDataSet readStream(java.io.InputStream in)
                         throws java.io.IOException
Parse the stream using the current settings.

Throws:
java.io.IOException

readFile

public VectorDataSet readFile(java.lang.String filename)
                       throws java.io.IOException
Parse the file using the current settings.

Throws:
java.io.IOException

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Throws:
java.lang.Exception