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
UnifiedFitsTableWriter
).
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 ); }