# Class ValueParser

java.lang.Object
uk.ac.starlink.ttools.votlint.ValueParser

public abstract class ValueParser extends Object
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 Type
Method
Description
`abstract 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<?>`
`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.
`VotLintContext`
`getContext()`
Returns this parser's context.
`abstract int`
`getElementCount()`
Returns the number of items of class `getContentClass()` 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.

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Method Details

### checkString

public abstract void checkString(String text, long irow)
Checks the value of a string which contains the value. This is presumably either the content of the `value` attribute of a PARAM element or the contents of a TD element.

Parameters:
  `text` - value string
  `irow` - row index at which error occurred, or negative if unknown/inapplicable

### checkStream

public abstract void checkStream(InputStream in, long irow) throws IOException
Checks the value of a table element which is encoded in a BINARY stream.

Parameters:
  `in` - input stream
  `irow` - row index at which error occurred, or negative if unknown/inapplicable
Throws:
  `IOException`

### getContentClass

public abstract Class<?> 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 that `ValueInfo.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 class `getContentClass()` which correspond to values parsed by this parser. This should be the same as the product of shape elements returned by `ValueInfo.getShape()`. If the number is indeterminate, -1 should be returned.

Returns:
  number of elements per value

### setContext

public void setContext(VotLintContext context)
Sets this parser's context. This method should be called shortly after construction.

Parameters:
  `context` - lint context

### getContext

public VotLintContext getContext()
Returns this parser's context.

Returns:
  lint context

### info

public void info(VotLintCode code, String msg, long irow)
Writes an info message to the user.

Parameters:
  `code` - message identifier
  `msg` - message text
  `irow` - row index associated with message, or -1 for unknown/inapplicable

### warning

public void warning(VotLintCode code, String msg, long irow)
Writes a warning message to the user.

Parameters:
  `code` - message identifier
  `msg` - message text
  `irow` - row index associated with message, or -1 for unknown/inapplicable

### error

public void error(VotLintCode code, String msg, long irow)
Writes an error message to the user.

Parameters:
  `code` - message identifier
  `msg` - message text
  `irow` - 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 handler
  `name` - name attribute value
  `datatype` - datatype attribute value
  `arraysize` - arraysize attribute value
  `xtype` - 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 stream
  `nbyte` - number of bytes to read
  `context` - 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 stream
  `nbyte` - number of bytes to read
  `context` - error reporting context
Returns:
  full buffer of size `nbyte`
Throws:
  `IOException` - if read could not complete