|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.virbo.dsutil.AsciiParser
public class AsciiParser
Class for reading ascii tables into a QDataSet. This parses a file by breaking it up into records, and passing the record off to a delegate record parser. The record parser then breaks up the record into fields, and each field is parser by a delegate field parser. Each column of the table as a Unit and a field name associated with it. Examples of record parsers include DelimParser, which splits the record by a delimiter such as a tab or comma, and FixedColumnsParser, which splits the record by character positions. Example of field parsers include DOUBLE_PARSER which parses the value as a double, and UNITS_PARSER, which uses the Unit attached to the column to interpret the value. The skipLines property tells the parser to skip a given number of header lines before attempting to parse the record. Also, commentPrefix identifies lines to be ignored. In either the header or in comments, we look for propertyPattern, and 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. Adapted to v3.0 QDataSet model, Jeremy, May 2007.
Nested Class Summary | |
---|---|
class |
AsciiParser.DelimParser
DelimParser splits the line on a regex (like "," or "\\s+") to create the fields. |
static interface |
AsciiParser.FieldParser
|
class |
AsciiParser.FixedColumnsParser
|
static interface |
AsciiParser.RecordParser
|
class |
AsciiParser.RegexParser
|
Field Summary | |
---|---|
static java.util.regex.Pattern |
COLUMN_HEADER_PATTERN
|
static java.lang.String |
DELIM_COMMA
|
static java.lang.String |
DELIM_TAB
|
static java.lang.String |
DELIM_WHITESPACE
|
static AsciiParser.FieldParser |
DOUBLE_PARSER
parses the field using Double.parseDouble, java's double parser. |
static java.util.regex.Pattern |
NAME_COLON_VALUE_PATTERN
|
static java.util.regex.Pattern |
NAME_EQUAL_VALUE_PATTERN
|
static java.lang.String |
PROP_VALIDMAX
|
static java.lang.String |
PROP_VALIDMIN
|
static java.lang.String |
PROPERTY_FIELD_NAMES
|
static java.lang.String |
PROPERTY_FIELD_PARSER
|
static java.lang.String |
PROPERTY_FILE_HEADER
|
static java.lang.String |
PROPERTY_FIRST_RECORD
|
AsciiParser.FieldParser |
UNITS_PARSER
delegates to the unit object set for this field to parse the data. |
protected double |
validMax
|
protected double |
validMin
|
Constructor Summary | |
---|---|
AsciiParser()
Creates a new instance of AsciiParser |
Method Summary | |
---|---|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener l)
Adds a PropertyChangeListener to the listener list. |
int |
getFieldIndex(java.lang.String string)
returns the index of the field |
java.lang.String[] |
getFieldNames()
return the name of each field. |
double |
getFillValue()
Getter for property fillValue. |
AsciiParser.RecordParser |
getRecordParser()
Getter for property recordParser. |
org.das2.datum.Units |
getUnits(int index)
Indexed getter for property units. |
double |
getValidMax()
|
double |
getValidMin()
|
AsciiParser.DelimParser |
guessDelimParser(java.lang.String line)
read in the first record, then guess the delimiter and possibly the column headers. |
static int |
guessFieldCount(java.lang.String filename)
return the field count that would result in the largest number of records parsed. |
boolean |
isKeepFileHeader()
Getter for property keepHeader. |
static void |
main(java.lang.String[] args)
|
static AsciiParser |
newParser(int fieldCount)
creates a parser with @param fieldCount fields, named "field0,...,fieldN" |
static AsciiParser |
newParser(java.lang.String[] fieldNames)
creates a parser with the named fields. |
WritableDataSet |
readFile(java.lang.String filename,
org.das2.util.monitor.ProgressMonitor mon)
Parse the file using the current settings. |
java.lang.String |
readFirstParseableRecord(java.lang.String filename)
returns the first record that the record parser parses successfully. |
java.lang.String |
readFirstRecord(java.lang.String filename)
return the first record that the parser would parse. |
WritableDataSet |
readStream(java.io.Reader in,
org.das2.util.monitor.ProgressMonitor mon)
Parse the stream using the current settings. |
void |
removePropertyChangeListener(java.beans.PropertyChangeListener l)
Removes a PropertyChangeListener from the listener list. |
void |
setCommentPrefix(java.lang.String comment)
Records starting with this are not processed as data, for example "#". |
AsciiParser.DelimParser |
setDelimParser(java.io.Reader in,
java.lang.String delimRegex)
The DelimParser splits each record into fields using a delimiter like "," or "\\s+". |
AsciiParser.RecordParser |
setDelimParser(java.lang.String filename,
java.lang.String delimRegex)
configure the parser to split on a delimRegex. |
void |
setFieldParser(int field,
AsciiParser.FieldParser fp)
|
void |
setFillValue(double fillValue)
numbers that parse to this value are considered to be fill. |
AsciiParser.FixedColumnsParser |
setFixedColumnsParser(int[] columnOffsets,
int[] columnWidths,
AsciiParser.FieldParser[] parsers)
|
AsciiParser.FixedColumnsParser |
setFixedColumnsParser(java.io.Reader in,
java.lang.String delim)
looks at the first line after skipping, and splits it to calculate where the columns are. |
AsciiParser.FixedColumnsParser |
setFixedColumnsParser(java.lang.String filename,
java.lang.String delim)
looks at the first line after skipping, and splits it to calculate where the columns are. |
void |
setKeepFileHeader(boolean keepHeader)
Setter for property keepHeader. |
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 |
setRecordParser(AsciiParser.RecordParser recordParser)
Setter for property recordParser. |
AsciiParser.RecordParser |
setRegexParser(java.lang.String[] fieldNames)
The regex parser is a slow parser, but gives precise control. |
void |
setSkipLines(int skipLines)
skip a number of lines before trying to parse anything. |
void |
setUnits(int index,
org.das2.datum.Units units)
Indexed setter for property units. |
void |
setValidMax(double validMax)
|
void |
setValidMin(double validMin)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.util.regex.Pattern NAME_COLON_VALUE_PATTERN
public static final java.util.regex.Pattern NAME_EQUAL_VALUE_PATTERN
public static final java.util.regex.Pattern COLUMN_HEADER_PATTERN
public static final java.lang.String PROPERTY_FIELD_NAMES
public static final java.lang.String PROPERTY_FILE_HEADER
public static final java.lang.String PROPERTY_FIRST_RECORD
public static final java.lang.String PROPERTY_FIELD_PARSER
public static final java.lang.String DELIM_COMMA
public static final java.lang.String DELIM_TAB
public static final java.lang.String DELIM_WHITESPACE
public static final AsciiParser.FieldParser DOUBLE_PARSER
public final AsciiParser.FieldParser UNITS_PARSER
protected double validMin
public static final java.lang.String PROP_VALIDMIN
protected double validMax
public static final java.lang.String PROP_VALIDMAX
Constructor Detail |
---|
public AsciiParser()
Method Detail |
---|
public AsciiParser.RecordParser setDelimParser(java.lang.String filename, java.lang.String delimRegex) throws java.io.IOException
java.io.IOException
public java.lang.String readFirstRecord(java.lang.String filename) throws java.io.IOException
filename
-
java.io.IOException
public java.lang.String readFirstParseableRecord(java.lang.String filename) throws java.io.IOException
filename
-
java.io.IOException
public AsciiParser.DelimParser guessDelimParser(java.lang.String line) throws java.io.IOException
Reader
- pointed to the beginning of the file.
java.io.IOException
public AsciiParser.DelimParser setDelimParser(java.io.Reader in, java.lang.String delimRegex) throws java.io.IOException
in
- delimRegex
-
java.io.IOException
public AsciiParser.RecordParser setRegexParser(java.lang.String[] fieldNames)
public AsciiParser.FixedColumnsParser setFixedColumnsParser(java.lang.String filename, java.lang.String delim) throws java.io.IOException
filename
- filename to read in.delim
- regex to split the initial line into the fixed columns.
java.io.IOException
public AsciiParser.FixedColumnsParser setFixedColumnsParser(java.io.Reader in, java.lang.String delim) throws java.io.IOException
in
- the Reader to get lines from.delim
- regex to split the initial line into the fixed columns.
java.io.IOException
public static int guessFieldCount(java.lang.String filename) throws java.io.FileNotFoundException, java.io.IOException
java.io.FileNotFoundException
java.io.IOException
public void setFieldParser(int field, AsciiParser.FieldParser fp)
public static AsciiParser newParser(int fieldCount)
public static AsciiParser newParser(java.lang.String[] fieldNames)
public void setSkipLines(int skipLines)
public void setRecordCountLimit(int recordCountLimit)
public void setPropertyPattern(java.util.regex.Pattern propertyPattern)
public void setCommentPrefix(java.lang.String comment)
comment
- public WritableDataSet readStream(java.io.Reader in, org.das2.util.monitor.ProgressMonitor mon) throws java.io.IOException
java.io.IOException
public AsciiParser.FixedColumnsParser setFixedColumnsParser(int[] columnOffsets, int[] columnWidths, AsciiParser.FieldParser[] parsers)
public java.lang.String[] getFieldNames()
public WritableDataSet readFile(java.lang.String filename, org.das2.util.monitor.ProgressMonitor mon) throws java.io.IOException
java.io.IOException
public static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception
public void addPropertyChangeListener(java.beans.PropertyChangeListener l)
l
- The listener to add.public void removePropertyChangeListener(java.beans.PropertyChangeListener l)
l
- The listener to remove.public boolean isKeepFileHeader()
public void setKeepFileHeader(boolean keepHeader)
keepHeader
- New value of property keepHeader.public AsciiParser.RecordParser getRecordParser()
public void setRecordParser(AsciiParser.RecordParser recordParser)
recordParser
- New value of property recordParser.public org.das2.datum.Units getUnits(int index)
index
- Index of the property.
index
.public void setUnits(int index, org.das2.datum.Units units)
index
- Index of the property.units
- New value of the property at index
.public int getFieldIndex(java.lang.String string)
public double getFillValue()
public void setFillValue(double fillValue)
fillValue
- New value of property fillValue.public double getValidMin()
public void setValidMin(double validMin)
public double getValidMax()
public void setValidMax(double validMax)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |