// Use the StarJava classes to write the FITS table and then copy the HDUs into the FITS image file
ByteArrayOutputStream os = new ByteArrayOutputStream();
new FitsPlusTableWriter().writeStarTable(table.getStarTable(), os);
ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
Fits tableFits = new Fits(is);
BasicHDU votMetaHdu = tableFits.getHDU(0);
votMetaHdu.getHeader().addValue("EXTNAME", votMetaName, "Table metadata in VOTable format");
TableHDU hdu = (TableHDU) tableFits.getHDU(1);
hdu.getHeader().addValue("EXTNAME", tableName, "Contains saved query results");
is.close();
os.close();
// add the new table (delete existing one, if found)