|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object edu.umd.cfar.lamp.viper.util.reader.VReader
This class offers a "Preprocessor" to ViPER data files, removing comments and expanding #includes. It also contains some knowledge of the gtf data format, so it should be checked for accuracy if the descriptor format is changed greatly.
Nested Class Summary | |
protected class |
VReader.TextLine
This class is used to represent a line of text or a sequence of lines connected by '\' characters. |
Constructor Summary | |
VReader(java.util.List paths)
Creates a new VReader that is block-type agnostic. |
|
VReader(java.util.List paths,
java.lang.String returnAs)
Opens a new VReader looking for the specified block type. |
|
VReader(java.lang.String pathName)
Initializes a new VReader with the file specified. |
|
VReader(java.lang.String directory,
java.lang.String fileName)
Initializes a new VReader with the file specified by directory and file name. |
Method Summary | |
java.lang.String |
advanceToBeginDirective()
Advances to next begin directive; noop if current line is a begin directive. |
boolean |
advanceToBeginDirective(java.lang.String name)
Advance to the first occurance of the begin directive for section name .
|
java.lang.String |
advanceToNextRealLine()
like gotoNextRealLine, but also returns the line. |
void |
changeSwitches(boolean all,
boolean err,
boolean warn,
boolean bad,
boolean totals)
Change the error switches. |
void |
close()
closes the input file |
boolean |
currentLineIsAttribute()
Checks to see if the line at which the VReader is pointing contains well-formed Attribute data. |
boolean |
currentLineIsAttribute(boolean val)
Checks to see if the line at which the VReader is pointing contains well-formed Attribute data. |
boolean |
currentLineIsBeginDirective()
Checks to see if the current line contains a #BEGIN_ directive |
boolean |
currentLineIsDescriptor()
Tests to see if the cursor is on a descriptor line |
boolean |
currentLineIsEndDirective()
Checks to see if the current line contains an #END_ directive |
boolean |
fileHandleSet()
Checks to see if any file handles remain |
protected void |
finalize()
|
java.lang.String |
getCurrentLine()
Get the current line as a String. |
int |
getCurrentLineNumber()
Gets the current line number of the cursor. |
void |
gotoNextRealLine()
Advances the cursor to the next line. |
boolean |
isAttributeLine(java.lang.String line,
boolean printErr)
Checks attribute by looking for colon, and making sure attribute name is not a descriptor type. |
static boolean |
isBeginDirective(VReader.TextLine line)
Checks to see if the specified line contains a #BEGIN_ directive |
static boolean |
isDescriptorLine(VReader.TextLine line)
Tests to see if the line starts with a descriptor type keyword, such as CONTENT or OBJECT. |
static boolean |
isEndDirective(VReader.TextLine line)
Checks to see if the specified line contains an #END_ directive |
static boolean |
isKeyword(java.lang.String name)
Returns true if this is one of the Descriptor keywords. |
void |
payAttentionTo(java.lang.String name)
The block type to look for. |
void |
printError(java.lang.String message)
Print an error. |
void |
printError(java.lang.String message,
int start,
int stop)
Print an error at a specific place inside the current line. |
void |
printErrorAtLineNumber(java.lang.String message,
int lineNum)
Print an error at a a specific line number. |
void |
printErrorTotals()
Print out the error count totals, usually in the form x Errors, y Warnings, z General Errors |
void |
printGeneralError(java.lang.String message)
Prints an error that is unconnected to a line number. |
void |
printWarning(java.lang.String message)
Print an warning. |
void |
printWarning(java.lang.String message,
int start,
int stop)
Print an warning at a specific place inside the current line. |
void |
printWarningAtLineNumber(java.lang.String message,
int lineNum)
Print an warning at a a specific line number. |
void |
resetTotals()
Reset the count of warning and errors. |
void |
setOutput(java.io.PrintStream ps)
Sets the output stream. |
void |
setOutput(java.io.PrintWriter pw)
Sets the output stream. |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public VReader(java.lang.String pathName) throws java.io.IOException
pathName
- the file to open
java.io.IOException
- if there is an error while opening/reading the filepublic VReader(java.lang.String directory, java.lang.String fileName) throws java.io.IOException
directory
- the directory namefileName
- the file name
java.io.IOException
public VReader(java.util.List paths)
paths
- List of files to search in order (as if they were a single file)public VReader(java.util.List paths, java.lang.String returnAs)
paths
- List of files to search in order (as if they were a single file)returnAs
- block type to pay attention to, e.g. EVALUATIONMethod Detail |
public void setOutput(java.io.PrintWriter pw)
setOutput
in interface ErrorWriter
pw
- the new output streampublic void setOutput(java.io.PrintStream ps)
ps
- the new output streampublic void close() throws java.io.IOException
java.io.IOException
protected void finalize() throws java.io.IOException
java.io.IOException
public void changeSwitches(boolean all, boolean err, boolean warn, boolean bad, boolean totals)
all
- report all lines as they are parsederr
- report errorswarn
- report warningsbad
- report the bad stufftotals
- print warning and error totals at the endpublic boolean fileHandleSet()
public void resetTotals()
public int getCurrentLineNumber()
public java.lang.String getCurrentLine()
public java.lang.String advanceToNextRealLine() throws java.io.IOException, java.io.EOFException
java.io.IOException
java.io.EOFException
public void gotoNextRealLine() throws java.io.IOException, java.io.EOFException
java.io.IOException
java.io.EOFException
public boolean advanceToBeginDirective(java.lang.String name)
name
.
Does nothing if the current line is the requested begin directive.
Therefore, to go to the third #BEGIN_ALPHA in a file, make sure to call
gotoNextLine() after each call to this method.
name
- Case-sensitive begin directive name - usually all-caps.
true
if the directive was found. Otherwise, the
reader has advanced to the end of the file.public void payAttentionTo(java.lang.String name)
name
- the block to look for.public java.lang.String advanceToBeginDirective()
null
public boolean currentLineIsBeginDirective()
#BEGIN_
directive
public static boolean isBeginDirective(VReader.TextLine line)
#BEGIN_
directive
line
- the line to check
public boolean currentLineIsEndDirective()
#END_
directive
public static boolean isEndDirective(VReader.TextLine line)
#END_
directive
line
- the line to check
public boolean currentLineIsDescriptor()
public static boolean isDescriptorLine(VReader.TextLine line)
line
- the line to check
true
if the line starts
with a descriptor keywordpublic boolean currentLineIsAttribute()
true
if the current line looks like Attribute
data.public boolean currentLineIsAttribute(boolean val)
val
- if you want to print errors if it is not an Attribute line.
true
if the current line looks like Attribute
data.public boolean isAttributeLine(java.lang.String line, boolean printErr)
line
- The line to checkprintErr
- Set if you want to print errors if it is not an Attribute
line.
true
if it looks like an attribute.public static boolean isKeyword(java.lang.String name)
name
- A string to check against the list of keywords.
true
if name is a Descriptor keyword (category).public void printError(java.lang.String message)
ErrorWriter
printError
in interface ErrorWriter
message
- the message to print with the errorErrorWriter.printError(String)
public void printErrorAtLineNumber(java.lang.String message, int lineNum)
ErrorWriter
printErrorAtLineNumber
in interface ErrorWriter
message
- The message to print with the error.lineNum
- The line where the error occured.ErrorWriter.printErrorAtLineNumber(String, int)
public void printWarning(java.lang.String message)
ErrorWriter
printWarning
in interface ErrorWriter
message
- the message to print with the warningErrorWriter.printWarning(String)
public void printWarningAtLineNumber(java.lang.String message, int lineNum)
ErrorWriter
printWarningAtLineNumber
in interface ErrorWriter
message
- the message to print with the warninglineNum
- The line where the error occured.ErrorWriter.printWarningAtLineNumber(String, int)
public void printError(java.lang.String message, int start, int stop)
ErrorWriter
printError
in interface ErrorWriter
message
- the message to print with the errorstart
- the column where the error beginsstop
- the column where the error endsErrorWriter.printError(String, int, int)
public void printWarning(java.lang.String message, int start, int stop)
ErrorWriter
printWarning
in interface ErrorWriter
message
- the message to print with the warningstart
- the column where the questionable part beginsstop
- the column where the questionable part endsErrorWriter.printWarning(String, int, int)
public void printGeneralError(java.lang.String message)
ErrorWriter
printGeneralError
in interface ErrorWriter
message
- the message to print with the warningErrorWriter.printGeneralError(String)
public void printErrorTotals()
ErrorWriter
x Errors, y Warnings, z General Errors
printErrorTotals
in interface ErrorWriter
ErrorWriter.printErrorTotals()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |