Commit 25276fce authored by Grégory Mantelet's avatar Grégory Mantelet
Browse files

[TAP] Fix the VOTable's FITS serialization.

Until now, the generated VOTable file was un-readable even by
STIL/STILTS/TOPCAT. To fix this, it was needed to temporary store the table to
format into FITS so that STIL can read it at least 2 times.

_This commit fixes the GitHub issue #43 ._
parent fea5ccf9
Loading
Loading
Loading
Loading
+71 −61
Original line number Original line Diff line number Diff line
@@ -16,7 +16,7 @@ package tap.formatter;
 * You should have received a copy of the GNU Lesser General Public License
 * You should have received a copy of the GNU Lesser General Public License
 * along with TAPLibrary.  If not, see <http://www.gnu.org/licenses/>.
 * along with TAPLibrary.  If not, see <http://www.gnu.org/licenses/>.
 *
 *
 * Copyright 2012-2017 - UDS/Centre de Données astronomiques de Strasbourg (CDS)
 * Copyright 2012-2019 - UDS/Centre de Données astronomiques de Strasbourg (CDS)
 *                       Astronomisches Rechen Institut (ARI)
 *                       Astronomisches Rechen Institut (ARI)
 */
 */


@@ -29,6 +29,9 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Iterator;
import java.util.Map;
import java.util.Map;


import adql.db.DBColumn;
import adql.db.DBType;
import adql.db.DBType.DBDatatype;
import tap.ServiceConnection;
import tap.ServiceConnection;
import tap.TAPException;
import tap.TAPException;
import tap.TAPExecutionReport;
import tap.TAPExecutionReport;
@@ -44,13 +47,11 @@ import uk.ac.starlink.table.ColumnInfo;
import uk.ac.starlink.table.DescribedValue;
import uk.ac.starlink.table.DescribedValue;
import uk.ac.starlink.table.RowSequence;
import uk.ac.starlink.table.RowSequence;
import uk.ac.starlink.table.StarTable;
import uk.ac.starlink.table.StarTable;
import uk.ac.starlink.table.StoragePolicy;
import uk.ac.starlink.votable.DataFormat;
import uk.ac.starlink.votable.DataFormat;
import uk.ac.starlink.votable.VOSerializer;
import uk.ac.starlink.votable.VOSerializer;
import uk.ac.starlink.votable.VOStarTable;
import uk.ac.starlink.votable.VOStarTable;
import uk.ac.starlink.votable.VOTableVersion;
import uk.ac.starlink.votable.VOTableVersion;
import adql.db.DBColumn;
import adql.db.DBType;
import adql.db.DBType.DBDatatype;


/**
/**
 * <p>Format any given query (table) result into VOTable.</p>
 * <p>Format any given query (table) result into VOTable.</p>
@@ -85,7 +86,7 @@ import adql.db.DBType.DBDatatype;
 * </p>
 * </p>
 *
 *
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 2.1 (07/2017)
 * @version 2.2 (03/2019)
 */
 */
public class VOTableFormat implements OutputFormat {
public class VOTableFormat implements OutputFormat {


@@ -336,7 +337,15 @@ public class VOTableFormat implements OutputFormat {
		table.setName("result_" + execReport.jobID);
		table.setName("result_" + execReport.jobID);


		/* Prepares the object that will do the serialization work. */
		/* Prepares the object that will do the serialization work. */
		VOSerializer voser = VOSerializer.makeSerializer(votFormat, votVersion, table);
		VOSerializer voser = null;
		/* if FITS, copy the table on disk (or in memory if the table is short):
		 * (note: this is needed because STIL needs at least 2 passes on this
		 *        table to format it correctly in FITS format) */
		if (votFormat == DataFormat.FITS)
			voser = VOSerializer.makeSerializer(votFormat, votVersion, StoragePolicy.PREFER_DISK.copyTable(table));
		// otherwise, just use the default VOTable serializer:
		else
			voser = VOSerializer.makeSerializer(votFormat, votVersion, table);
		BufferedWriter out = new BufferedWriter(new OutputStreamWriter(output));
		BufferedWriter out = new BufferedWriter(new OutputStreamWriter(output));


		/* Write header. */
		/* Write header. */
@@ -743,7 +752,8 @@ public class VOTableFormat implements OutputFormat {
				}
				}


				@Override
				@Override
				public void close() throws IOException{}
				public void close() throws IOException{
				}
			};
			};
		}
		}
	}
	}