public class TextFormat extends java.lang.Object implements OutputFormat
Modifier and Type | Class and Description |
---|---|
protected static class |
TextFormat.LineFormatter
Lets format a line and then write it in the given
BufferedWriter . |
Modifier and Type | Field and Description |
---|---|
protected int[] |
alignment
How all columns must be aligned.
|
protected static char |
COL_SEP
Internal column separator.
|
protected ServiceConnection |
service
The
ServiceConnection to use (for the log and to have some
information about the service (particularly: name, description). |
Constructor and Description |
---|
TextFormat(ServiceConnection service)
Build a
TextFormat . |
TextFormat(ServiceConnection service,
int[] customAlignment)
Build a
TextFormat . |
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.
|
protected java.lang.String |
getHeader(TableIterator result,
TAPExecutionReport execReport,
java.lang.Thread thread)
Get the whole header (one row whose columns are just the columns' name).
|
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 boolean |
writeData(TableIterator queryResult,
LargeAsciiTable asciiTable,
TAPExecutionReport execReport,
java.lang.Thread thread)
Write all the data rows into the given
LargeAsciiTable object. |
protected void |
writeFieldValue(java.lang.Object value,
DBColumn tapCol,
java.lang.StringBuffer line)
Writes the given field value in the given buffer.
|
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 static final char COL_SEP
protected int[] alignment
LargeAsciiTable.streamAligned(LineProcessor, int[])
protected final ServiceConnection service
ServiceConnection
to use (for the log and to have some
information about the service (particularly: name, description).public TextFormat(ServiceConnection service) throws java.lang.NullPointerException
TextFormat
.
Note:
All columns values will be aligned on the left.
To change this default alignment, use
TextFormat(ServiceConnection, int[])
instead.
service
- Description of the TAP service.java.lang.NullPointerException
- If the given service connection is NULL.public TextFormat(ServiceConnection service, int[] customAlignment) throws java.lang.NullPointerException
TextFormat
.service
- Description of the TAP service.customAlignment
- How columns must be aligned.
(see LargeAsciiTable.streamAligned(LineProcessor, int[])
to know the rules about this array)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 java.lang.String getHeader(TableIterator result, TAPExecutionReport execReport, java.lang.Thread thread) throws TAPException
result
- Result to write later (but it contains also metadata
that was extracted from the result itself).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).TAPException
- If any other error occurs.protected boolean writeData(TableIterator queryResult, LargeAsciiTable asciiTable, TAPExecutionReport execReport, java.lang.Thread thread) throws java.io.IOException, TAPException, java.lang.InterruptedException
LargeAsciiTable
object.queryResult
- Result to write.asciiTable
- Output in which the rows (as string) 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.lang.InterruptedException
- If the thread has been interrupted.TAPException
- If any other error occurs.java.io.IOException
protected void writeFieldValue(java.lang.Object value, DBColumn tapCol, java.lang.StringBuffer line)
value
- The value to write.tapCol
- The corresponding column metadata.line
- The buffer in which the field value must be written.