Package uk.ac.starlink.ttools.votlint
Class ValueParser
java.lang.Object
uk.ac.starlink.ttools.votlint.ValueParser
Object which knows how to interpret the values associated with a
FIELD or PARAM object. This interpretation takes the form only of
checking whether it is encoded legally, writing some message to the
context if it is not, and throwing away the result
(if it was ever calculated in the first place).
- Since:
- 7 Apr 2005
- Author:
- Mark Taylor (Starlink)
-
Method Summary
Modifier and TypeMethodDescriptionabstract void
checkStream
(InputStream in, long irow) Checks the value of a table element which is encoded in a BINARY stream.abstract void
checkString
(String text, long irow) Checks the value of a string which contains the value.void
error
(VotLintCode code, String msg, long irow) Writes an error message to the user.abstract Class
<?> Returns the class of values which would be used in Java to represent an object parsed by this parser, although this class does not actually return such values.Returns this parser's context.abstract int
Returns the number of items of classgetContentClass()
which correspond to values parsed by this parser.void
info
(VotLintCode code, String msg, long irow) Writes an info message to the user.static ValueParser
makeParser
(ElementHandler handler, String name, String datatype, String arraysize, String xtype) Constructs a ValueParsers for a given element.static byte[]
readStreamBytes
(InputStream in, int nbyte, VotLintContext context) Reads and returns a fixed number of bytes from a stream.void
setContext
(VotLintContext context) Sets this parser's context.static void
slurpStream
(InputStream in, int nbyte, VotLintContext context) Uncritically reads in a fixed number of bytes from a stream.void
warning
(VotLintCode code, String msg, long irow) Writes a warning message to the user.
-
Method Details
-
checkString
Checks the value of a string which contains the value. This is presumably either the content of thevalue
attribute of a PARAM element or the contents of a TD element.- Parameters:
text
- value stringirow
- row index at which error occurred, or negative if unknown/inapplicable
-
checkStream
Checks the value of a table element which is encoded in a BINARY stream.- Parameters:
in
- input streamirow
- row index at which error occurred, or negative if unknown/inapplicable- Throws:
IOException
-
getContentClass
Returns the class of values which would be used in Java to represent an object parsed by this parser, although this class does not actually return such values. This should be the same class thatValueInfo.getContentClass()
would return for this object if a StarTable was being built.- Returns:
- value class
-
getElementCount
public abstract int getElementCount()Returns the number of items of classgetContentClass()
which correspond to values parsed by this parser. This should be the same as the product of shape elements returned byValueInfo.getShape()
. If the number is indeterminate, -1 should be returned.- Returns:
- number of elements per value
-
setContext
Sets this parser's context. This method should be called shortly after construction.- Parameters:
context
- lint context
-
getContext
Returns this parser's context.- Returns:
- lint context
-
info
Writes an info message to the user.- Parameters:
code
- message identifiermsg
- message textirow
- row index associated with message, or -1 for unknown/inapplicable
-
warning
Writes a warning message to the user.- Parameters:
code
- message identifiermsg
- message textirow
- row index associated with message, or -1 for unknown/inapplicable
-
error
Writes an error message to the user.- Parameters:
code
- message identifiermsg
- message textirow
- row index associated with message, or -1 for unknown/inapplicable
-
makeParser
public static ValueParser makeParser(ElementHandler handler, String name, String datatype, String arraysize, String xtype) Constructs a ValueParsers for a given element.- Parameters:
handler
- element handlername
- name attribute valuedatatype
- datatype attribute valuearraysize
- arraysize attribute valuextype
- xtype (extended type) attribute value- Returns:
- a suitable ValueParser, or
null
if one can't be constructed
-
slurpStream
public static void slurpStream(InputStream in, int nbyte, VotLintContext context) throws IOException Uncritically reads in a fixed number of bytes from a stream. An error is reported if the stream ends mid-read.- Parameters:
in
- input streamnbyte
- number of bytes to readcontext
- error reporting context- Throws:
IOException
-
readStreamBytes
public static byte[] readStreamBytes(InputStream in, int nbyte, VotLintContext context) throws IOException Reads and returns a fixed number of bytes from a stream. An error is reported if the stream ends mid-read.- Parameters:
in
- input streamnbyte
- number of bytes to readcontext
- error reporting context- Returns:
- full buffer of size
nbyte
- Throws:
IOException
- if read could not complete
-