|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectdatabionics.io.BaseFile
public abstract class BaseFile
Base class for all filetypes. Parsing of the lines when loading and construction of the lines when saving is delegated to subclasses. Headers starting with % and comments starting with # are handled here, globally. Many methods are implemented empty instead of declared abstract so they don't have to be implemented by subclasses if they are not needed.
Field Summary | |
---|---|
protected boolean |
allowEmptyLines
Flag whether to allow empty lines, usually false, except rules files |
protected StringList |
comment
Comment of file. |
protected java.lang.String |
commentPrefix
Comment prefix. |
protected java.lang.String |
delimiter
Default saving delimiter character. |
protected java.lang.String |
delimiters
Default parsing delimiter characters. |
protected java.io.File |
file
Path of file. |
protected StringList |
header
Header of file. |
protected java.lang.String |
headerPrefix
Header prefix. |
protected java.util.Locale |
loc
Current locale. |
protected static org.apache.log4j.Logger |
log
Log4j logging. |
protected java.text.NumberFormat |
nf
Current number format. |
Constructor Summary | |
---|---|
BaseFile()
Standard constructor |
|
BaseFile(java.lang.String filename)
Constructor with a filename |
Method Summary | |
---|---|
protected void |
buildHeader()
Generate a fresh header based on the data structure for saving. |
protected java.lang.String |
buildLine(int row)
Construct a line in subclasses for saving the data to a file. |
protected void |
checkHeader()
Check consistency of header information with data structure in subclasses. |
protected void |
checkHeaderAgainstSize(int row)
Check consistency of header line with size information. |
StringList |
getComment()
Get the comment of file. |
java.io.File |
getFile()
Get the file. |
java.lang.String |
getFilename()
Get the name of file. |
StringList |
getHeader()
Get the header of file. |
java.util.Locale |
getLocale()
Get the current locale. |
java.text.NumberFormat |
getNumberFormat()
Get the current number format. |
int |
getSize()
Get the number of lines in file. |
protected void |
init(int rows,
int cols)
Init data structures in subclasses given the number of lines in the file and the number of tokens in the first line after header and comments. |
protected boolean |
isHeader(java.lang.String line)
Determine if a line still contains header information or whether the data lines started |
protected static boolean |
isNaN(java.lang.String s)
Check if a string represents a NaN. |
protected boolean |
isNumber(java.lang.String s)
Check if a string represents a number |
void |
load()
Load data. |
void |
load(java.lang.String filename)
Load data from this file |
protected static void |
parseError(int row,
int col,
java.lang.String msg)
Report a parsing error |
protected void |
parseHeader()
Parse the header in subclasses. |
protected void |
parseLine(int row,
java.lang.String line)
Parse a line in subclasses to fill the data structures with values. |
void |
save()
Save the data to a file. |
void |
save(java.lang.String filename)
Save data to this file. |
void |
setComment(StringList comment)
Change the comment of file. |
void |
setFilename(java.lang.String filename)
Change the name of the file. |
void |
setLocale(java.util.Locale loc)
Change the current locale. |
protected static void |
writeStringList(java.io.BufferedWriter w,
StringList l)
Write a StringList to a writer. |
protected static void |
writeStringList(java.io.BufferedWriter w,
StringList l,
java.lang.String prefix)
Write a StringList to a writer. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static org.apache.log4j.Logger log
protected StringList comment
protected StringList header
protected java.io.File file
protected java.util.Locale loc
protected java.text.NumberFormat nf
protected java.lang.String commentPrefix
protected java.lang.String headerPrefix
protected java.lang.String delimiters
protected java.lang.String delimiter
protected boolean allowEmptyLines
Constructor Detail |
---|
public BaseFile()
public BaseFile(java.lang.String filename)
filename
- Name of the fileMethod Detail |
---|
protected static boolean isNaN(java.lang.String s)
s
- String to checkprotected boolean isNumber(java.lang.String s)
s
- String to checkprotected static void writeStringList(java.io.BufferedWriter w, StringList l, java.lang.String prefix) throws java.io.IOException
w
- Writer to save data tol
- List of strings to saveprefix
- Prefix to add in front of each line
java.io.IOException
protected static void parseError(int row, int col, java.lang.String msg)
row
- line numbercoll
- token numbermsg
- error messageprotected static void writeStringList(java.io.BufferedWriter w, StringList l) throws java.io.IOException
w
- Writer to save data tol
- List of strings to save
java.io.IOException
protected boolean isHeader(java.lang.String line)
line
- Line to checkprotected void parseHeader()
protected void init(int rows, int cols)
rows
- Number of lines in file.cols
- Number of tokens in first data line.protected void parseLine(int row, java.lang.String line)
row
- Number of current line.line
- Current line.protected void checkHeaderAgainstSize(int row)
row
- Row of header where size is stored (starting with 0)protected void checkHeader()
public void load() throws java.io.IOException
java.io.IOException
public void load(java.lang.String filename) throws java.io.IOException
java.io.IOException
protected void buildHeader()
protected java.lang.String buildLine(int row)
row
- Number of current line.
public void save() throws java.io.IOException
java.io.IOException
public void save(java.lang.String filename) throws java.io.IOException
java.io.IOException
public int getSize()
public StringList getComment()
public void setComment(StringList comment)
public java.lang.String getFilename()
public void setFilename(java.lang.String filename)
public java.io.File getFile()
public StringList getHeader()
public java.util.Locale getLocale()
public void setLocale(java.util.Locale loc)
public java.text.NumberFormat getNumberFormat()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |