Next Previous Up Contents
Next: Read a single VOTable from a file
Up: VOTable Access
Previous: DATA Element Formats

6.2 Reading VOTables

STIL offers a number of options for reading a VOTable document, described below. In all cases they provide you with a way of obtaining the table data (contents of the cells) without having to know how these were encoded. The API defines the contents of a cell only as an Object; the actual type will be determined by the datatype and arraysize attributes of the column. In general, scalars are represented by the corresponding primitive wrapper class (Integer, Double, Boolean etc), and arrays are represented by an array of primitives of the corresponding type (int[], double[], boolean[]). Arrays are only ever one-dimensional - information about any multidimensional shape they may have is supplied separately (use the getShape method on the corresponding ColumnInfo). There are a couple of exceptions to this: arrays with datatype="char" or "unicodeChar" are represented by String objects since that is almost always what is intended (n-dimensional arrays of char are treated as if they were (n-1)-dimensional arrays of Strings), and unsignedByte types are represented as if they were shorts, since in Java bytes are always signed. Complex values are represented as if they were an array of the corresponding type but with an extra dimension of size two (the most rapidly varying).

The following table summarises how all VOTable datatypes are represented:

    datatype        Class for scalar   Class for arraysize>1
    --------        ----------------   ---------------------
    boolean         Boolean            boolean[]
    bit             boolean[]          boolean[]
    unsignedByte    Short              short[]
    short           Short              short[]
    int             Integer            int[]
    long            Long               long[]
    char            Char               String or String[]
    unicodeChar     Char               String or String[]
    float           Float              float[]
    double          Double             double[]
    floatComplex    float[]            float[]
    doubleComplex   double[]           double[]

The application program does not, however, have to investigate the values of the datatype and arraysize attributes to work out what kinds of objects it is going to find as values of cells in a table. Each column of the table object that STIL gives you can report the class of object which will be found in it. In most cases, you will receive a StarTable object which contains the table metadata. To find the class of objects in the fourth column, you can do this:


    Class clazz = starTable.getColumnInfo(3).getContentClass();

Every value obtained from a cell in that column can be cast to the class clazz (though note such a value might be null). Useful tip: for generic processing it is often handy to cast numeric scalar cell contents to type Number.


Next Previous Up Contents
Next: Read a single VOTable from a file
Up: VOTable Access
Previous: DATA Element Formats

STIL - Starlink Tables Infrastructure Library
Starlink User Note 252
STIL web page: http://www.starlink.ac.uk/stil/
Author email: m.b.taylor@bristol.ac.uk
Starlink: http://www.starlink.ac.uk/