Next Previous Up Contents
Next: Specifying I/O Handlers
Up: Table I/O
Previous: Generic Table Streamed Input

### 3.4 Generic Table Output

Generic serialization of tables to external storage is done using a `StarTableOutput` object. This has a similar job to the `StarTableFactory` described in the previous section; it mediates between code which wants to output a table and a set of format-specific output handler objects. The `writeStarTable` method is used to write out a `StarTable` object. When invoking this method, you specify the location to which you want to output the table and a string specifying the format you would like to write in. This is usually a short string like "fits" associated with one of the registered output handlers - a list of known formats can be got using the `getKnownFormats` method.

Use is straightforward:

        void writeTableAsFITS( StarTable table, File file ) throws IOException {
            new StarTableOutput().writeStarTable( table, file.toString(), "fits" );
        }

If, as in this example, you know what format you want to write the table in, you could equally use the relevant `StarTableWriter` object directly (in this case a `FitsTableWriter`).

As implied in the above, the location string is usually a filename. However, it doesn't have to be - it is turned into an output stream by the `StarTableOutput`'s `getOutputStream` method. By default this assumes that the location is a filename except when it has the special value "-" which is interpreted as standard output. However, you can override this method to write to more exotic locations.

Alternatively, you may wish to output to an `OutputStream` of your own. This can be done as follows:

        void writeTableAsFITS( StarTable table, OutputStream out ) throws IOException {
            StarTableOutput sto = new StarTableOutput();
            StarTableWriter outputHandler = sto.getHandler( "fits" );
            sto.writeStarTable( table, out, outputHandler );
        }

Next Previous Up Contents
Next: Specifying I/O Handlers
Up: Table I/O
Previous: Generic Table Streamed Input

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