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)
  • Constructor Details

    • ValueParser

      public ValueParser()
  • Method Details

    • checkString

      public abstract void checkString(String text)
      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
    • checkStream

      public abstract void checkStream(InputStream in) throws IOException
      Checks the value of a table element which is encoded in a BINARY stream.
      Parameters:
      in - input stream
      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)
      Writes an info mesage to the user.
      Parameters:
      code - message identifier
      msg - message text
    • warning

      public void warning(VotLintCode code, String msg)
      Writes a warning mesage to the user.
      Parameters:
      code - message identifier
      msg - message text
    • error

      public void error(VotLintCode code, String msg)
      Writes an error mesage to the user.
      Parameters:
      code - message identifier
      msg - message text
    • makeParser

      public static ValueParser makeParser(ElementHandler handler, String datatype, String arraysize, String xtype)
      Constructs a ValueParsers for a given element.
      Parameters:
      handler - element handler
      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