Header header = hdu.getHeader();
String name = header.getStringValue("EXTNAME");
if (name != null) {
// Check for a stored StarTable, which has a corresponding VOTMETA HDU with more info
String votMetaName = VOTMETA + name.replace(TABLE_SUFFIX, "");
BasicHDU votMetaHdu = findHDU(fits, votMetaName);
if (votMetaHdu != null) {
Fits tmpFits = new Fits();
tmpFits.addHDU(votMetaHdu);
tmpFits.addHDU(hdu);
votMetaHdu.getHeader().removeCard("EXTNAME"); // not expected by FitsPlusTableBuilder
votMetaHdu.getHeader().removeCard("EXTEND"); // not expected by FitsPlusTableBuilder
ByteArrayOutputStream os = new ByteArrayOutputStream();
BufferedDataOutputStream bos = new BufferedDataOutputStream(os);
tmpFits.write(bos);
bos.flush();
// Restore the name that was removed above
votMetaHdu.getHeader().addValue("EXTNAME", votMetaName, "Table metadata in VOTable format");
ByteArrayDataSource dataSrc = new ByteArrayDataSource(filename, os.toByteArray());
bos.close();
StarTable starTable = new FitsPlusTableBuilder().makeStarTable(dataSrc, true,
StoragePolicy.getDefaultPolicy());
dataSrc.close();