public class JSONFormat extends java.lang.Object implements OutputFormat
Modifier and Type | Field and Description |
---|---|
protected ServiceConnection |
service
The
ServiceConnection to use (for the log and to have some information about the service (particularly: name, description). |
Constructor and Description |
---|
JSONFormat(ServiceConnection service)
Build a JSON formatter.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getDescription()
Gets a description of this format.
|
java.lang.String |
getFileExtension()
Gets a file extension for this format.
|
java.lang.String |
getMimeType()
Gets the MIME type corresponding to this format.
|
java.lang.String |
getShortMimeType()
Gets a short expression of its MIME type.
|
protected TAPColumn |
getValidColMeta(DBColumn typeFromQuery,
TAPColumn typeFromResult)
Try to get or otherwise to build appropriate metadata using those extracted from the ADQL query and those extracted from the result.
|
protected void |
writeData(TableIterator result,
DBColumn[] selectedColumns,
org.json.JSONWriter out,
TAPExecutionReport execReport,
java.lang.Thread thread)
Write the whole data part of the JSON file.
|
protected void |
writeFieldMeta(TAPColumn tapCol,
org.json.JSONWriter out)
Formats in JSON and writes the given
TAPColumn in the given output. |
protected void |
writeFieldValue(java.lang.Object value,
DBColumn column,
org.json.JSONWriter out)
Writes the given field value in JSON and into the given output.
|
protected DBColumn[] |
writeMetadata(TableIterator result,
org.json.JSONWriter out,
TAPExecutionReport execReport,
java.lang.Thread thread)
Write the whole metadata part of the JSON file.
|
void |
writeResult(TableIterator result,
java.io.OutputStream output,
TAPExecutionReport execReport,
java.lang.Thread thread)
Formats the given query result and writes it in the given output stream.
|
protected final ServiceConnection service
ServiceConnection
to use (for the log and to have some information about the service (particularly: name, description).public JSONFormat(ServiceConnection service) throws java.lang.NullPointerException
service
- Description of the TAP service.java.lang.NullPointerException
- If the given service connection is null
.public java.lang.String getMimeType()
OutputFormat
getMimeType
in interface OutputFormat
public java.lang.String getShortMimeType()
OutputFormat
getShortMimeType
in interface OutputFormat
public java.lang.String getDescription()
OutputFormat
getDescription
in interface OutputFormat
public java.lang.String getFileExtension()
OutputFormat
getFileExtension
in interface OutputFormat
public void writeResult(TableIterator result, java.io.OutputStream output, TAPExecutionReport execReport, java.lang.Thread thread) throws TAPException, java.io.IOException, java.lang.InterruptedException
OutputFormat
Formats the given query result and writes it in the given output stream.
Note: the given output stream should not be closed at the end of this function. It is up to the called to do it.
writeResult
in interface OutputFormat
result
- The raw (table) result to format.output
- The output stream (a ServletOutputStream or a stream on a file) in which the formatted result must be written.execReport
- The report of the execution of the TAP query whose the result must be now written.thread
- The thread which has asked the result writing.TAPException
- If there is an error while formatting the query result.java.io.IOException
- If any error occurs while writing into the given stream.java.lang.InterruptedException
- If the query has been interrupted/aborted.protected DBColumn[] writeMetadata(TableIterator result, org.json.JSONWriter out, TAPExecutionReport execReport, java.lang.Thread thread) throws java.io.IOException, TAPException, java.lang.InterruptedException, org.json.JSONException
result
- Result to write later (but it contains also metadata that was extracted from the result itself).out
- Output stream in which the metadata must be written.execReport
- Execution report (which contains the metadata extracted/guessed from the ADQL query).thread
- Thread which has asked for this formatting (it must be used in order to test the Thread.isInterrupted()
flag and so interrupt everything if need).java.io.IOException
- If there is an error while writing something in the output stream.java.lang.InterruptedException
- If the thread has been interrupted.org.json.JSONException
- If there is an error while formatting something in JSON.TAPException
- If any other error occurs.getValidColMeta(DBColumn, TAPColumn)
protected TAPColumn getValidColMeta(DBColumn typeFromQuery, TAPColumn typeFromResult)
typeFromQuery
- Metadata extracted/guessed from the ADQL query.typeFromResult
- Metadata extracted/guessed from the result.protected void writeFieldMeta(TAPColumn tapCol, org.json.JSONWriter out) throws java.io.IOException, TAPException, org.json.JSONException
TAPColumn
in the given output.tapCol
- The column metadata to format/write in JSON.out
- The stream in which the formatted column metadata must be written.java.io.IOException
- If there is an error while writing the field metadata.org.json.JSONException
- If there is an error while formatting something in JSON format.TAPException
- If there is any other error (by default: never happen).protected void writeData(TableIterator result, DBColumn[] selectedColumns, org.json.JSONWriter out, TAPExecutionReport execReport, java.lang.Thread thread) throws java.io.IOException, TAPException, java.lang.InterruptedException, org.json.JSONException
result
- Result to write.selectedColumns
- All columns' metadata.out
- Output stream in which the data must be written.execReport
- Execution report (which contains the maximum allowed number of records to output).thread
- Thread which has asked for this formatting (it must be used in order to test the Thread.isInterrupted()
flag and so interrupt everything if need).java.io.IOException
- If there is an error while writing something in the output stream.java.lang.InterruptedException
- If the thread has been interrupted.org.json.JSONException
- If there is an error while formatting something in JSON.TAPException
- If any other error occurs.protected void writeFieldValue(java.lang.Object value, DBColumn column, org.json.JSONWriter out) throws java.io.IOException, TAPException, org.json.JSONException
Writes the given field value in JSON and into the given output.
note: special numeric values NaN and Inf (double or float) will be written as NULL values.
value
- The value to write.column
- The corresponding column metadata.out
- The stream in which the field value must be written.java.io.IOException
- If there is an error while writing the given field value in the given stream.TAPException
- If there is any other error (by default: never happen).org.json.JSONException