public class TableParser
extends java.lang.Object
Listrecs = TableParser.readTable(is, "3,15,46,54,60d,67d,73d", 50000); for (TableParser.Record record : recs) { Station s = new Station(); s.id = "K" + record.get(0); s.name = record.get(2) + " " + record.get(3); s.lat = (Double) record.get(4) * .01; s.lon = (Double) record.get(5) * .01; s.elev = (Double) record.get(6); stationTableHash.put(s.id, s); if (showStations) System.out.println(" station= " + s); } Example Table: TLX 000001 OKLAHOMA_CITY/Norman OK US 3532 -9727 370 0 NWS AMA 000313 AMARILLO/Amarillo TX US 3523 -10170 1093 0 NWS HGX 000378 HOUSTON/GALVESTON/Dickinson TX US 2947 -9507 5 0 NWS MLB 000302 MELBOURNE/Melbourne FL US 2810 -8065 11 0 NWS format: "3,15,54,60d,67d,73d" grammer: format = {field,} field = endPos type endPos = ending pos in the line, 0 based, exclusive, ie [start, end) type = i=integer, d=double, L=long else String field[0] goes from [0, endPos[0]) field[i] goes from [endPos[i-1] to endPos[i])
Modifier and Type | Class and Description |
---|---|
static class |
TableParser.DerivedField |
static class |
TableParser.Field
Describes one field in the record.
|
static class |
TableParser.Record
A set of values for one line.
|
static interface |
TableParser.Transform |
Constructor and Description |
---|
TableParser(java.lang.String format) |
Modifier and Type | Method and Description |
---|---|
TableParser.DerivedField |
addDerivedField(TableParser.Field from,
TableParser.Transform transform,
java.lang.Class type) |
TableParser.Field |
getField(int fldno) |
int |
getNumberOfFields() |
java.util.List<TableParser.Record> |
readAllRecords(java.io.InputStream ios,
int maxLines) |
static java.util.List<TableParser.Record> |
readTable(java.io.InputStream ios,
java.lang.String format,
int maxLines)
Reads an input stream, containing lines of ascii in fixed width format.
|
static java.util.List<TableParser.Record> |
readTable(java.lang.String urlString,
java.lang.String format,
int maxLines)
Reads a URL or file in as a table.
|
void |
setComment(java.lang.String comment) |
public TableParser(java.lang.String format) throws java.io.IOException, java.lang.NumberFormatException
java.io.IOException
java.lang.NumberFormatException
public static java.util.List<TableParser.Record> readTable(java.lang.String urlString, java.lang.String format, int maxLines) throws java.io.IOException, java.lang.NumberFormatException
urlString
- starts with http, read URL contenets, else read file.format
- describe format of each line.maxLines
- maximum number of lines to parse, set to < 0 to read alljava.io.IOException
- on read errorjava.lang.NumberFormatException
- on parse number errorreadTable(InputStream ios, String format, int maxLines)
public static java.util.List<TableParser.Record> readTable(java.io.InputStream ios, java.lang.String format, int maxLines) throws java.io.IOException, java.lang.NumberFormatException
ios
- the input stream, will be closedformat
- describe format of each line.maxLines
- maximum number of lines to parse, set to < 0 to read alljava.io.IOException
- on read errorjava.lang.NumberFormatException
- on parse number errorpublic void setComment(java.lang.String comment)
public java.util.List<TableParser.Record> readAllRecords(java.io.InputStream ios, int maxLines) throws java.io.IOException, java.lang.NumberFormatException
java.io.IOException
java.lang.NumberFormatException
public TableParser.Field getField(int fldno)
public int getNumberOfFields()
public TableParser.DerivedField addDerivedField(TableParser.Field from, TableParser.Transform transform, java.lang.Class type)