|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.phoenix_int.aserver.util.PHXFileParser
public class PHXFileParser
This is a utility class for loading data files and extracting data. Sample Usage:
PHXFileParser fp;NOTES:try { fp = new PHXFileParser( "myfile.dat" ); } catch ( IOException e ) { System.out.println( e ); }
try { int row = 20; int field = 2; String token = fp.getToken( row, field ); } catch ( PHXNoSuchTokenException e ) { System.out.println( "Error: token not found" ); }
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from interface com.phoenix_int.aserver.util.Parser |
|---|
Parser.Mode |
| Field Summary | |
|---|---|
static int |
AUTOMATIC
Deprecated. in favor of Parser.Mode.AUTOMATIC |
static int |
BUFFERED
Deprecated. in favor of Parser.Mode.BUFFERED |
static long |
FILE_SIZE_LIMIT
Deprecated. in favor of Parser.Mode.FILE_SIZE_LIMIT |
static int |
FIRST
|
static int |
LAST
|
static int |
RANDOM_ACCESS
Deprecated. in favor of Parser.Mode.RANDOM |
static int |
RESIZE_DISALLOW
Don't allow the length of an array to change |
static int |
RESIZE_ROWS
Allow a square matrix to change sizes by adding or deleting rows. |
| Constructor Summary | |
|---|---|
PHXFileParser(java.io.File file,
Parser.Mode mode)
|
|
PHXFileParser(java.io.File file,
Parser.Mode mode,
com.phoenix_int.util.PHXFileUtils.Encoding encoding)
|
|
PHXFileParser(IPHXLineStore store,
java.lang.String fileName)
|
|
PHXFileParser(java.lang.String fileName)
|
|
PHXFileParser(java.lang.String fileName,
int method)
Deprecated. in favor of PHXFileParser(String, Parser.Mode) |
|
PHXFileParser(java.lang.String fileName,
Parser.Mode mode)
|
|
PHXFileParser(java.lang.String fileName,
Parser.Mode mode,
com.phoenix_int.util.PHXFileUtils.Encoding encoding)
|
|
PHXFileParser(java.lang.String fileName,
com.phoenix_int.util.PHXFileUtils.Encoding encoding)
|
|
| Method Summary | |
|---|---|
void |
addLines(int actualIndex,
int count,
java.lang.String line)
|
void |
addLines(int actualIndex,
java.lang.String[] lines)
|
void |
clearMarks()
resets the file to it's whole size by removing the starting and ending marks if they existed |
void |
close()
Close the parser |
void |
closeFile()
close the PHXRandomAccessFileLineStore |
int |
countTokens(int row)
counts the number of tokens on a specified row |
java.lang.String[] |
getColumnArray(int startRow,
int endRow,
int field)
gets an array of tokens for the specified range. |
java.lang.String |
getDelimiters()
|
java.lang.String |
getFileName()
retrieves the name of the file that is being parsed |
IPHXLineStore |
getLineStore()
Gets the underlying line store object for this parser |
java.lang.String[] |
getMatrixArray(int startRow,
int startField,
int endRow,
int endField)
gets an array of tokens for the specified range. |
java.lang.String[] |
getMatrixArray(int startRow,
int startCol,
int endRow,
int endCol,
int fieldWidth)
gets an array of tokens for the specified range. |
java.lang.String[][] |
getMatrixArray2d(int startRow,
int startField,
int endRow,
int endField)
gets an array of tokens for the specified range. |
java.lang.String[] |
getRowArray(int startCol,
int endCol,
int row)
gets an array of tokens for the specified range. |
java.lang.String |
getToken(int row,
int field)
gets the token at the specified row and field. |
java.lang.String |
getToken(int row,
int startCol,
int endCol)
gets the token at the specified row and column. |
java.util.Vector |
getToken(int row,
int startField,
int endField,
java.lang.String delimiter)
gets an array of tokens at the specified row and between start and end fields (all inclusive) Indexing starts at 1. |
java.lang.String |
getToken(java.lang.String string,
int rowOffset,
int field)
gets the token relative to a search string. |
java.lang.String |
getToken(java.lang.String string,
int occurrence,
int rowOffset,
int field)
gets the token relative to a search string. |
static void |
main(java.lang.String[] args)
|
void |
markBeginning(int row)
marks the starting point from which to start counting rows and fields. |
void |
markBeginning(java.lang.String string)
same as markBeginning where the pattern is a regex and ocurence value is 1 |
void |
markBeginning(java.lang.String string,
boolean isRegex)
same as markBeginning with an occurrence value of 1 |
void |
markBeginning(java.lang.String string,
boolean isRegex,
int occurrence)
marks the starting point from which to start counting rows and fields. |
void |
markBeginning(java.lang.String string,
int occurrence)
marks the starting point from which to start counting rows and fields. |
void |
markBeginningFromEnd(java.lang.String string,
boolean isRegex)
marks the starting point from which to start counting rows. |
void |
markBeginningOffset(int offset)
marks the starting point from which to start counting rows and fields. |
void |
markEnd(int row)
marks the ending point of the file. |
void |
markEnd(java.lang.String string,
boolean isRegex)
same as markEnd with an occurrence value of 1 |
void |
markEnd(java.lang.String string,
boolean isRegex,
int occurrence)
marks the ending point from which to start counting rows and fields. |
void |
markEnd(java.lang.String string,
int occurrence)
marks the ending point from which to start counting rows and fields. |
void |
markEndFromEnd(java.lang.String string,
boolean isRegex)
marks the starting point from which to start counting rows and fields. |
void |
markEndOffset(int offset)
marks the ending point from which to start counting rows and fields. |
void |
removeLines(int actualIndex,
int count)
|
void |
resetDelimiters()
resets the delimiters to whitespace |
void |
setDelimiters(java.lang.String delimiters)
sets the current delimiter set |
void |
setMatrixArray(int startRow,
int startCol,
int endRow,
int endCol,
int fieldWidth,
java.lang.String[] array)
sets an array of tokens for the specified range. |
void |
setMatrixArray(int startRow,
int startCol,
int endRow,
int endCol,
int fieldWidth,
java.lang.String[] array,
int resizeStyle)
sets an array of tokens for the specified range. |
void |
setMatrixArray(int startRow,
int startCol,
int endRow,
int endCol,
java.lang.String[] array)
sets an array of tokens for the specified range. |
void |
setMatrixArray(int startRow,
int startCol,
int endRow,
int endCol,
java.lang.String[] array,
int resizeStyle)
sets an array of tokens for the specified range. |
void |
setMatrixArray2d(int startRow,
int startCol,
int endRow,
int endCol,
java.lang.String[][] array,
int resizeStyle)
sets an array of tokens for the specified range. |
void |
setToken(int row,
int startCol,
int endCol,
java.lang.String replacement)
replaces the token at the specified row and column. |
void |
setToken(int row,
int field,
java.lang.String replacement)
replaces the token at the specified row and field. |
void |
setToken(java.lang.String string,
int occurrence,
int rowOffset,
int field,
java.lang.String replacement)
gets the token relative to a search string. |
void |
setToken(java.lang.String string,
int rowOffset,
int field,
java.lang.String replacement)
gets the token relative to a search string. |
void |
writeTo(java.io.OutputStream os)
|
void |
writeTo(java.io.OutputStreamWriter fw)
writes out the data to a file |
void |
writeTo(java.lang.String fileName)
|
void |
writeTo(java.lang.String fileName,
com.phoenix_int.util.PHXFileUtils.Encoding encoding)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int RESIZE_DISALLOW
public static final int RESIZE_ROWS
public static final int FIRST
public static final int LAST
@Deprecated public static final int RANDOM_ACCESS
Parser.Mode.RANDOM@Deprecated public static final int BUFFERED
Parser.Mode.BUFFERED@Deprecated public static final int AUTOMATIC
Parser.Mode.AUTOMATIC@Deprecated public static final long FILE_SIZE_LIMIT
Parser.Mode.FILE_SIZE_LIMIT
| Constructor Detail |
|---|
public PHXFileParser(java.lang.String fileName)
throws java.io.IOException
java.io.IOException
public PHXFileParser(java.lang.String fileName,
com.phoenix_int.util.PHXFileUtils.Encoding encoding)
throws java.io.IOException
fileName - the file to load
java.io.IOException - if there is a problem opening the file
public PHXFileParser(java.io.File file,
Parser.Mode mode)
throws java.io.IOException
java.io.IOException
public PHXFileParser(java.io.File file,
Parser.Mode mode,
com.phoenix_int.util.PHXFileUtils.Encoding encoding)
throws java.io.IOException
java.io.IOException
public PHXFileParser(java.lang.String fileName,
Parser.Mode mode)
throws java.io.IOException
java.io.IOException
public PHXFileParser(java.lang.String fileName,
Parser.Mode mode,
com.phoenix_int.util.PHXFileUtils.Encoding encoding)
throws java.io.IOException
java.io.IOException
@Deprecated
public PHXFileParser(java.lang.String fileName,
int method)
throws java.io.IOException
PHXFileParser(String, Parser.Mode)
fileName - the file to loadmethod - the method used to parse the file. RANDOM_ACCESS
will scan the data file as needed. BUFFERED will read
the file into a buffer prior to parsing. RANDOM_ACCESS
is better for large files, but will be slower for small
(<50k) files. BUFFERED is also preferrable for parsing
many variables from a file or for performing large
numbers of searches.
java.io.IOException - if there is a problem opening the file
public PHXFileParser(IPHXLineStore store,
java.lang.String fileName)
store - The source of lines for the file parser.fileName - The name of the file for errors and advisories.
This parameter is not used for any actual processing| Method Detail |
|---|
public IPHXLineStore getLineStore()
public java.lang.String getFileName()
public void writeTo(java.lang.String fileName)
throws java.io.IOException
java.io.IOException
public void writeTo(java.lang.String fileName,
com.phoenix_int.util.PHXFileUtils.Encoding encoding)
throws java.io.IOException
java.io.IOException
public void writeTo(java.io.OutputStream os)
throws java.io.IOException
java.io.IOException
public void writeTo(java.io.OutputStreamWriter fw)
throws java.io.IOException
writeTo in interface ParserfileName - the file to save to
java.io.IOException - thrown if the file cannot be
written topublic void close()
Parser
close in interface Parserpublic void closeFile()
public void resetDelimiters()
public java.lang.String getDelimiters()
public void setDelimiters(java.lang.String delimiters)
delimiters - the delimiters to use for parsing
public void markBeginning(int row)
throws PHXNoSuchTokenException
row - the row where the new begining will occur. This row
becomes row 1.
PHXNoSuchTokenException - thrown if the token is not found
public void markEnd(int row)
throws PHXNoSuchTokenException
row - the row where the new ending will occur. This row
becomes the last row.
PHXNoSuchTokenException - thrown if the token is not foundpublic void markBeginningOffset(int offset)
offset - the offset from the current starting line
java.lang.IllegalArgumentException - thrown if
the specified offset move past the end or beginning of
the file
public void markBeginning(java.lang.String string,
boolean isRegex)
throws PHXNoSuchTokenException
string - the pattern that marks the new first lineisRegex - if true, the pattern is a regular expression
PHXNoSuchTokenException - thrown if the token is not found
public void markBeginning(java.lang.String string)
throws PHXNoSuchTokenException
string - the pattern that marks the new first line
PHXNoSuchTokenException - thrown if the token is not found
public void markBeginning(java.lang.String string,
boolean isRegex,
int occurrence)
throws PHXNoSuchTokenException
string - the search patternoccurrence - the number of times to search for the pattern.
may be negative to search from endisRegex - if true, the string is a regular expression.
PHXNoSuchTokenException - thrown if the token is not found
public void markBeginning(java.lang.String string,
int occurrence)
throws PHXNoSuchTokenException
string - the search patternoccurrence - the number of times to search for the pattern.
may be negative to search from end
PHXNoSuchTokenException - thrown if the token is not foundpublic void markEndOffset(int offset)
offset - the offset from the current starting line
java.lang.IllegalArgumentException - thrown if
the specified offset move past the end or beginning of
the file
public void markEnd(java.lang.String string,
boolean isRegex)
throws PHXNoSuchTokenException
string - the pattern that marks the new first lineisRegex - if true, the patter is a regular expression
PHXNoSuchTokenException - thrown if the token is not found
public void markEnd(java.lang.String string,
boolean isRegex,
int occurrence)
throws PHXNoSuchTokenException
string - the pattern that marks the new last lineisRegex - if true, the patter is a regular expressionoccurrence - the number of times to search for regex
value may be negative to search from beginning
PHXNoSuchTokenException - thrown if the token is not found
public void markEnd(java.lang.String string,
int occurrence)
throws PHXNoSuchTokenException
string - the pattern that marks the new last lineoccurrence - the number of times to search for regex
value may be negative to search from end
PHXNoSuchTokenException - thrown if the token is not found
public void markBeginningFromEnd(java.lang.String string,
boolean isRegex)
throws PHXNoSuchTokenException
string - the pattern that marks the new first lineisRegex - if true, the patter is a regular expression
PHXNoSuchTokenException - thrown if the token is not found
public void markEndFromEnd(java.lang.String string,
boolean isRegex)
throws PHXNoSuchTokenException
string - the pattern that marks the new first lineisRegex - if true, the patter is a regular expression
PHXNoSuchTokenException - thrown if the token is not foundpublic void clearMarks()
public java.lang.String getToken(java.lang.String string,
int occurrence,
int rowOffset,
int field)
throws PHXNoSuchTokenException
string - the value to search foroccurrence - the number of times to match the searchrowOffset - row relative to the search results where the
token is foundfield - the field in the specified row for the token
PHXNoSuchTokenException - thrown if the token is not found
public java.lang.String getToken(java.lang.String string,
int rowOffset,
int field)
throws PHXNoSuchTokenException
string - the value to search forrowOffset - row relative to the search results where the
token is foundfield - the field in the specified row for the token
PHXNoSuchTokenException - thrown if the token is not found
public java.lang.String getToken(int row,
int field)
throws PHXNoSuchTokenException
row - the row that the token is onfield - the field in the specified row for the token
PHXNoSuchTokenException - thrown if the token is not found
public java.lang.String getToken(int row,
int startCol,
int endCol)
throws PHXNoSuchTokenException
row - the row that the token is onstartCol - the start columnendCol - the end column
PHXNoSuchTokenException - thrown if the token is not found
public java.util.Vector getToken(int row,
int startField,
int endField,
java.lang.String delimiter)
throws PHXNoSuchTokenException
row - the row that the tokens are onstartField - the start field (inclusive)endField - the end field (inclusive)delimiter - the delimiters
PHXNoSuchTokenException - thrown if the token is not found
public void setToken(java.lang.String string,
int occurrence,
int rowOffset,
int field,
java.lang.String replacement)
throws PHXNoSuchTokenException
string - the value to search foroccurrence - the number of times to match the searchrowOffset - row relative to the search results where the
token is foundfield - the field in the specified row for the tokenreplacement - the string to substitute into the field
PHXNoSuchTokenException - thrown if the token is not found
public void setToken(java.lang.String string,
int rowOffset,
int field,
java.lang.String replacement)
throws PHXNoSuchTokenException
string - the value to search forrowOffset - row relative to the search results where the
token is foundfield - the field in the specified row for the tokenreplacement - the string to substitute into the field
PHXNoSuchTokenException - thrown if the token is not found
public void setToken(int row,
int field,
java.lang.String replacement)
throws PHXNoSuchTokenException
row - the row that the token is onfield - the field in the specified row for the tokenreplacement - the string to substitute into the field
PHXNoSuchTokenException - thrown if the token is not found
public void setToken(int row,
int startCol,
int endCol,
java.lang.String replacement)
throws PHXNoSuchTokenException
row - the row that the token is onstartCol - the start columnendCol - the end columnreplacement - the string to substitute into the field
PHXNoSuchTokenException - thrown if the token is not found
public void addLines(int actualIndex,
int count,
java.lang.String line)
public void addLines(int actualIndex,
java.lang.String[] lines)
public void removeLines(int actualIndex,
int count)
public int countTokens(int row)
throws PHXNoSuchTokenException
row - the row to count tokens
PHXNoSuchTokenException - thrown if
the row specified is invalid
public java.lang.String[] getColumnArray(int startRow,
int endRow,
int field)
throws PHXNoSuchTokenException
startRow - the row for the first element in the arrayendRow - the row for the last element in the arrayfield - the field in the specified row for the token
PHXNoSuchTokenException - thrown if a token is not found
public java.lang.String[] getRowArray(int startCol,
int endCol,
int row)
throws PHXNoSuchTokenException
startCol - the field for the first element in the arrayendCol - the field for the last element in the arrayrow - the row to extract tokens from
PHXNoSuchTokenException - thrown if a token is not found
public java.lang.String[] getMatrixArray(int startRow,
int startField,
int endRow,
int endField)
throws PHXNoSuchTokenException
startRow - the row for the first element in the arraystartField - the field for the first element in the arrayendRow - the row for the last element in the arrayendField - the field for the last element in the array
PHXNoSuchTokenException - thrown if a token is not found
public java.lang.String[][] getMatrixArray2d(int startRow,
int startField,
int endRow,
int endField)
throws PHXNoSuchTokenException
startRow - the row for the first element in the arraystartField - the field for the first element in the arrayendRow - the row for the last element in the arrayendField - the field for the last element in the array
PHXNoSuchTokenException - thrown if a token is not found
public java.lang.String[] getMatrixArray(int startRow,
int startCol,
int endRow,
int endCol,
int fieldWidth)
throws PHXNoSuchTokenException
startRow - the row for the first element in the arraystartCol - the column for the first element in the arrayendRow - the row for the last element in the arrayendCol - the column for the last element in the arrayfieldWidth - UNUSED. How wide one field is.
PHXNoSuchTokenException - thrown if a token is not found
public void setMatrixArray(int startRow,
int startCol,
int endRow,
int endCol,
java.lang.String[] array)
throws PHXNoSuchTokenException
startRow - the row for the first element in the arraystartCol - the field for the first element in the arrayendRow - the row for the last element in the arrayendCol - the field for the last element in the arrayarray - the values
PHXNoSuchTokenException - thrown if a token is not found
public void setMatrixArray(int startRow,
int startCol,
int endRow,
int endCol,
java.lang.String[] array,
int resizeStyle)
throws PHXNoSuchTokenException
startRow - the row for the first element in the arraystartCol - the field for the first element in the arrayendRow - the row for the last element in the arrayendCol - the field for the last element in the arrayarray - the valuesresizeStyle - How to resize (RESIZE_DISALLOW, RESIZE_ROWS)
PHXNoSuchTokenException - thrown if a token is not found
public void setMatrixArray2d(int startRow,
int startCol,
int endRow,
int endCol,
java.lang.String[][] array,
int resizeStyle)
throws PHXNoSuchTokenException
startRow - the row for the first element in the arraystartCol - the field for the first element in the arrayendRow - the row for the last element in the arrayendCol - the field for the last element in the arrayarray - the valuesresizeStyle - How to resize (RESIZE_DISALLOW, RESIZE_ROWS)
PHXNoSuchTokenException - thrown if a token is not found
public void setMatrixArray(int startRow,
int startCol,
int endRow,
int endCol,
int fieldWidth,
java.lang.String[] array)
throws PHXNoSuchTokenException
startRow - the row for the first element in the arraystartCol - the field for the first element in the arrayendRow - the row for the last element in the arrayendCol - the field for the last element in the arrayfieldWidth - UNUSED. How wide one field is.array - the values
PHXNoSuchTokenException - thrown if a token is not found
public void setMatrixArray(int startRow,
int startCol,
int endRow,
int endCol,
int fieldWidth,
java.lang.String[] array,
int resizeStyle)
throws PHXNoSuchTokenException
startRow - the row for the first element in the arraystartCol - the field for the first element in the arrayendRow - the row for the last element in the arrayendCol - the field for the last element in the arrayfieldWidth - UNUSED. How wide one field is.array - the valuesresizeStyle - How to resize (RESIZE_DISALLOW, RESIZE_ROWS)
PHXNoSuchTokenException - thrown if a token is not foundpublic static void main(java.lang.String[] args)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||