public class SVFormat extends java.lang.Object implements OutputFormat
Modifier and Type | Field and Description |
---|---|
static char |
COMMA_SEPARATOR
Column separator for CSV format.
|
protected boolean |
delimitStr
Indicate whether String values must be delimited by double quotes (default) or not.
|
protected java.lang.String |
mimeType
MIME type associated with this format.
|
static char |
SEMI_COLON_SEPARATOR
Column separator for sCSV format.
|
protected java.lang.String |
separator
Column separator to use.
|
protected ServiceConnection |
service
The
ServiceConnection to use (for the log and to have some information about the service (particularly: name, description). |
protected java.lang.String |
shortMimeType
Alias of the MIME type associated with this format.
|
static char |
TAB_SEPARATOR
Column separator for TSV format.
|
Constructor and Description |
---|
SVFormat(ServiceConnection service,
char colSeparator)
Build a SVFormat (in which String values are delimited by double quotes).
|
SVFormat(ServiceConnection service,
char colSeparator,
boolean delimitStrings)
Build a SVFormat.
|
SVFormat(ServiceConnection service,
char colSeparator,
boolean delimitStrings,
java.lang.String mime,
java.lang.String shortMime)
Build a SVFormat.
|
SVFormat(ServiceConnection service,
java.lang.String colSeparator)
Build a SVFormat (in which String values are delimited by double quotes).
|
SVFormat(ServiceConnection service,
java.lang.String colSeparator,
boolean delimitStrings)
Build a SVFormat.
|
SVFormat(ServiceConnection service,
java.lang.String colSeparator,
boolean delimitStrings,
java.lang.String mime,
java.lang.String shortMime)
Build a SVFormat.
|
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 java.lang.String |
guessMimeType(java.lang.String separator)
Try to guess the MIME type to associate with this SV format, in function of the column separator.
|
protected java.lang.String |
guessShortMimeType(java.lang.String separator)
Try to guess the short MIME type to associate with this SV format, in function of the column separator.
|
protected void |
writeData(TableIterator result,
DBColumn[] selectedColumns,
java.io.BufferedWriter writer,
TAPExecutionReport execReport,
java.lang.Thread thread)
Write all the data rows.
|
protected void |
writeFieldValue(java.lang.Object value,
DBColumn column,
java.io.BufferedWriter writer)
Writes the given field value in the given Writer.
|
protected DBColumn[] |
writeHeader(TableIterator result,
java.io.BufferedWriter writer,
TAPExecutionReport execReport,
java.lang.Thread thread)
Write the whole header (one row whose columns are just the columns' name).
|
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.
|
public static final char COMMA_SEPARATOR
public static final char SEMI_COLON_SEPARATOR
public static final char TAB_SEPARATOR
protected final ServiceConnection service
ServiceConnection
to use (for the log and to have some information about the service (particularly: name, description).protected final java.lang.String separator
protected final boolean delimitStr
protected final java.lang.String mimeType
protected final java.lang.String shortMimeType
public SVFormat(ServiceConnection service, char colSeparator) throws java.lang.NullPointerException
service
- Description of the TAP service.colSeparator
- Column separator to use.java.lang.NullPointerException
- If the given service connection is null
.public SVFormat(ServiceConnection service, char colSeparator, boolean delimitStrings) throws java.lang.NullPointerException
service
- Description of the TAP service.colSeparator
- Column separator to use.delimitStrings
- true if String values must be delimited by double quotes, false otherwise.java.lang.NullPointerException
- If the given service connection is null
.public SVFormat(ServiceConnection service, char colSeparator, boolean delimitStrings, java.lang.String mime, java.lang.String shortMime) throws java.lang.NullPointerException
service
- Description of the TAP service.colSeparator
- Column separator to use.delimitStrings
- true if String values must be delimited by double quotes, false otherwise.mime
- The MIME type to associate with this format. note: this MIME type is then used by a user to specify the result format he wants.shortMime
- The alias of the MIME type to associate with this format. note: this short MIME type is then used by a user to specify the result format he wants.java.lang.NullPointerException
- If the given service connection is null
.public SVFormat(ServiceConnection service, java.lang.String colSeparator) throws java.lang.NullPointerException
service
- Description of the TAP service.colSeparator
- Column separator to use.java.lang.NullPointerException
- If the given service connection is null
.public SVFormat(ServiceConnection service, java.lang.String colSeparator, boolean delimitStrings) throws java.lang.NullPointerException
service
- Description of the TAP service.colSeparator
- Column separator to use.delimitStrings
- true if String values must be delimited by double quotes, false otherwise.java.lang.NullPointerException
- If the given service connection is null
.public SVFormat(ServiceConnection service, java.lang.String colSeparator, boolean delimitStrings, java.lang.String mime, java.lang.String shortMime) throws java.lang.NullPointerException
service
- Description of the TAP service.colSeparator
- Column separator to use.delimitStrings
- true if String values must be delimited by double quotes, false otherwise.mime
- The MIME type to associate with this format. note: this MIME type is then used by a user to specify the result format he wants.shortMime
- The alias of the MIME type to associate with this format. note: this short MIME type is then used by a user to specify the result format he wants.java.lang.NullPointerException
- If the given service connection is null
.protected java.lang.String guessMimeType(java.lang.String separator)
Try to guess the MIME type to associate with this SV format, in function of the column separator.
By default, only "," or ";" (text/csv) and [TAB] (text/tab-separated-values) are supported. If the separator is unknown, "text/plain" will be returned.
Note: In order to automatically guess more MIME types, you should overwrite this function.
separator
- Column separator of this SV format.protected java.lang.String guessShortMimeType(java.lang.String separator)
Try to guess the short MIME type to associate with this SV format, in function of the column separator.
By default, only "," or ";" (csv) and [TAB] (tsv) are supported. If the separator is unknown, "text" will be returned.
Note: In order to automatically guess more short MIME types, you should overwrite this function.
separator
- Column separator of this SV format.public final java.lang.String getMimeType()
OutputFormat
getMimeType
in interface OutputFormat
public final 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[] writeHeader(TableIterator result, java.io.BufferedWriter writer, TAPExecutionReport execReport, java.lang.Thread thread) throws java.io.IOException, TAPException, java.lang.InterruptedException
result
- Result to write later (but it contains also metadata that was extracted from the result itself).writer
- Output 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.java.lang.InterruptedException
- If the thread has been interrupted.TAPException
- If any other error occurs.protected void writeData(TableIterator result, DBColumn[] selectedColumns, java.io.BufferedWriter writer, TAPExecutionReport execReport, java.lang.Thread thread) throws java.io.IOException, TAPException, java.lang.InterruptedException
result
- Result to write.selectedColumns
- All columns' metadata.writer
- Writer 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 given writer.java.lang.InterruptedException
- If the thread has been interrupted.TAPException
- If any other error occurs.protected void writeFieldValue(java.lang.Object value, DBColumn column, java.io.BufferedWriter writer) throws java.io.IOException, TAPException
Writes the given field value in the given Writer.
A String value will be delimited if delimitStr
is true, otherwise this type of value will
be processed like the other type of values: no delimiter and just transformed into a string.
value
- The value to write.column
- The corresponding column metadata.writer
- 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).