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 (usually, but not necessarily, a filename)
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, but can be other things
(see the javadocs for details).
Use is very 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 just as easily use the relevant
StarTableWriter
object directly
(in this case FitsTableWriter
).
However, doing it with a StarTableOutput
allows users to be offered the choice of which format to use.