uk.ac.starlink.votable
Class VOTableWriter

java.lang.Object
  extended by uk.ac.starlink.votable.VOTableWriter
All Implemented Interfaces:
MultiStarTableWriter, StarTableWriter

public class VOTableWriter
extends Object
implements StarTableWriter, MultiStarTableWriter

Implementation of the StarTableWriter interface for VOTables. The dataFormat and inline attributes can be modified to affect how the bulk cell data are output - this may be in TABLEDATA, FITS or BINARY format, and in the latter two cases may be either inline as base64 encoded CDATA or to a separate stream.


Field Summary
static String DEFAULT_DOCTYPE_DECLARATION
          Default document type declaration in written documents.
static String DEFAULT_VOTABLE_VERSION
          Default VOTABLE version number.
static String DEFAULT_XML_DECLARATION
          Default XML declaration in written documents.
 
Constructor Summary
VOTableWriter()
          Constructs a default VOTableWriter.
VOTableWriter(DataFormat dataFormat, boolean inline)
          Constructs a VOTableWriter with specified output characteristics.
 
Method Summary
 DataFormat getDataFormat()
          Returns the format in which this writer will output the bulk table data.
 String getDoctypeDeclaration()
          Returns the document type declaration which is used by this writer at the head of any document written.
 String getFormatName()
          Gives the name of the format which is written by this writer.
 boolean getInline()
          Indicates whether STREAM elements will be written inline or to an external file in the case of FITS and BINARY encoding.
 String getMimeType()
          Returns a string suitable for use as the value of a MIME Content-Type header.
static StarTableWriter[] getStarTableWriters()
          Returns a list of votable writers with variant values of attributes.
 String getVotableVersion()
          Returns the value of the version attribute of the VOTABLE element written by this writer.
 String getXMLDeclaration()
          Returns the XML declaration which is used by this writer at the head of any document written.
 boolean looksLikeFile(String filename)
          Returns true for filenames with the extension ".xml", ".vot" or ".votable";
 void setDataFormat(DataFormat format)
          Sets the format in which the table data will be output.
 void setDoctypeDeclaration(String doctypeDecl)
          Sets the document type declaration which will be used by this writer at the head of any document written.
 void setInline(boolean inline)
          Sets whether STREAM elements should be written inline or to an external file in the case of FITS and BINARY encoding.
 void setVotableVersion(String votableVersion)
          Sets the version attribtion of the VOTABLE element written by this writer.
 void setXMLDeclaration(String xmlDecl)
          Sets the XML declaration which will be used by this writer at the head of any document written.
 void writeInlineStarTable(StarTable startab, BufferedWriter writer)
          Writes a table directly to a stream.
 void writeInlineStarTables(StarTable[] startabs, BufferedWriter writer)
          Writes multiple tables directly to a stream.
protected  void writePostTableXML(BufferedWriter writer)
          Outputs all the text required after the TABLE element in the output table document.
protected  void writePreTableXML(BufferedWriter writer)
          Outputs all the text required before the TABLE element.
 void writeStarTable(StarTable startab, OutputStream out)
          Writes a StarTable to a given stream; must be inline.
 void writeStarTable(StarTable startab, OutputStream out, File file)
          Writes a StarTable to a given stream.
 void writeStarTable(StarTable startab, String location, StarTableOutput sto)
          Writes a StarTable to a given location.
 void writeStarTables(TableSequence tableSeq, OutputStream out)
          Writes a sequence of tables to a given stream; must be inline.
 void writeStarTables(TableSequence tableSeq, OutputStream out, File file)
          Writes a sequence of tables to a given stream.
 void writeStarTables(TableSequence tableSeq, String location, StarTableOutput sto)
          Writes a sequence of tables to a given location.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_XML_DECLARATION

public static final String DEFAULT_XML_DECLARATION
Default XML declaration in written documents.

See Also:
Constant Field Values

DEFAULT_DOCTYPE_DECLARATION

public static final String DEFAULT_DOCTYPE_DECLARATION
Default document type declaration in written documents.

See Also:
Constant Field Values

DEFAULT_VOTABLE_VERSION

public static final String DEFAULT_VOTABLE_VERSION
Default VOTABLE version number.

See Also:
Constant Field Values
Constructor Detail

VOTableWriter

public VOTableWriter()
Constructs a default VOTableWriter. Output is in TABLEDATA format.


VOTableWriter

public VOTableWriter(DataFormat dataFormat,
                     boolean inline)
Constructs a VOTableWriter with specified output characteristics.

Parameters:
dataFormat - the format in which tables will be written
inline - whether output of streamed formats should be inline and base64-encoded or not
Method Detail

writeStarTable

public void writeStarTable(StarTable startab,
                           String location,
                           StarTableOutput sto)
                    throws IOException
Writes a StarTable to a given location.

Specified by:
writeStarTable in interface StarTableWriter
Parameters:
startab - the table to write
location - the filename to which to write the table
sto - object used for location resolution
Throws:
TableFormatException - if startab cannot be written to location
IOException - if there is some I/O error

writeStarTables

public void writeStarTables(TableSequence tableSeq,
                            String location,
                            StarTableOutput sto)
                     throws IOException
Writes a sequence of tables to a given location. They are written as separate TABLE elements in the same VOTable document.

Specified by:
writeStarTables in interface MultiStarTableWriter
Parameters:
tableSeq - table sequence
location - the filename to which to write the table
sto - object used for location resolution
Throws:
IOException

writeStarTable

public void writeStarTable(StarTable startab,
                           OutputStream out)
                    throws IOException
Writes a StarTable to a given stream; must be inline. Same as writeStarTable(startab,out,(File)null).

Specified by:
writeStarTable in interface StarTableWriter
Parameters:
startab - the table to write
out - the stream down which to write the table
Throws:
TableFormatException - if this table cannot be written to a stream
IOException - if there is some I/O error

writeStarTables

public void writeStarTables(TableSequence tableSeq,
                            OutputStream out)
                     throws IOException
Writes a sequence of tables to a given stream; must be inline. Same as writeStarTables(tableSeq,out,null).

Specified by:
writeStarTables in interface MultiStarTableWriter
Parameters:
tableSeq - tables to write
out - destination stream
Throws:
IOException

writeStarTable

public void writeStarTable(StarTable startab,
                           OutputStream out,
                           File file)
                    throws IOException
Writes a StarTable to a given stream.

Parameters:
startab - the table to write
out - the stream down which to write the table
file - the filename to which out refers; this is used if necessary to come up with a suitable filename for related files which need to be written. May be null.
Throws:
IOException

writeStarTables

public void writeStarTables(TableSequence tableSeq,
                            OutputStream out,
                            File file)
                     throws IOException
Writes a sequence of tables to a given stream.

Parameters:
tableSeq - table sequence to write
out - destination stream
file - the filename to which out refers; this is used if necessary to come up with a suitable filename for related files which need to be written. May be null.
Throws:
IOException

writeInlineStarTable

public void writeInlineStarTable(StarTable startab,
                                 BufferedWriter writer)
                          throws IOException
Writes a table directly to a stream.

Parameters:
startab - table to write
writer - destination stream
Throws:
IOException

writeInlineStarTables

public void writeInlineStarTables(StarTable[] startabs,
                                  BufferedWriter writer)
                           throws IOException
Writes multiple tables directly to a stream.

Parameters:
startabs - tables
writer - destination stream
Throws:
IOException

writePreTableXML

protected void writePreTableXML(BufferedWriter writer)
                         throws IOException
Outputs all the text required before the TABLE element. This method can be overridden to alter the behaviour of the writer if required.

Parameters:
writer - destination stream
Throws:
IOException
See Also:
writePostTableXML(java.io.BufferedWriter)

writePostTableXML

protected void writePostTableXML(BufferedWriter writer)
                          throws IOException
Outputs all the text required after the TABLE element in the output table document. This method can be overridden to alter the behaviour of this writer if required.

Parameters:
writer - destination stream
Throws:
IOException
See Also:
writePreTableXML(java.io.BufferedWriter)

looksLikeFile

public boolean looksLikeFile(String filename)
Returns true for filenames with the extension ".xml", ".vot" or ".votable";

Specified by:
looksLikeFile in interface StarTableWriter
Parameters:
filename - name of the file
Returns:
true if filename looks like the home of a VOTable

getFormatName

public String getFormatName()
Description copied from interface: StarTableWriter
Gives the name of the format which is written by this writer. Matching against this string may be used by callers to identify or select this writer from a list.

Specified by:
getFormatName in interface StarTableWriter
Returns:
a short string identifying the output format of this writer

getMimeType

public String getMimeType()
Description copied from interface: StarTableWriter
Returns a string suitable for use as the value of a MIME Content-Type header. If no suitable MIME type is available or known, one of "application/octet-stream" (for binary formats) or "text/plain" for ASCII ones) is recommended.

Specified by:
getMimeType in interface StarTableWriter
Returns:
MIME content type

setDataFormat

public void setDataFormat(DataFormat format)
Sets the format in which the table data will be output.

Parameters:
format - bulk data format

getDataFormat

public DataFormat getDataFormat()
Returns the format in which this writer will output the bulk table data.

Returns:
bulk data format

setInline

public void setInline(boolean inline)
Sets whether STREAM elements should be written inline or to an external file in the case of FITS and BINARY encoding.

Parameters:
inline - true iff streamed data will be encoded inline in the STREAM element

getInline

public boolean getInline()
Indicates whether STREAM elements will be written inline or to an external file in the case of FITS and BINARY encoding.

Returns:
true iff streamed data will be encoded inline in the STREAM element

setXMLDeclaration

public void setXMLDeclaration(String xmlDecl)
Sets the XML declaration which will be used by this writer at the head of any document written. By default this is the value of DEFAULT_XML_DECLARATION.

Parameters:
xmlDecl - new XML declaration

getXMLDeclaration

public String getXMLDeclaration()
Returns the XML declaration which is used by this writer at the head of any document written.


setDoctypeDeclaration

public void setDoctypeDeclaration(String doctypeDecl)
Sets the document type declaration which will be used by this writer at the head of any document written. By default this is the value of DEFAULT_DOCTYPE_DECLARATION.

Parameters:
doctypeDecl - new declaration

getDoctypeDeclaration

public String getDoctypeDeclaration()
Returns the document type declaration which is used by this writer at the head of any document written.

Returns:
doctypeDecl

setVotableVersion

public void setVotableVersion(String votableVersion)
Sets the version attribtion of the VOTABLE element written by this writer. Note this does not necessarily change the formatting behaviour to match the stated version.

Parameters:
votableVersion - version to declare

getVotableVersion

public String getVotableVersion()
Returns the value of the version attribute of the VOTABLE element written by this writer.

Returns:
declared votable version

getStarTableWriters

public static StarTableWriter[] getStarTableWriters()
Returns a list of votable writers with variant values of attributes.

Returns:
non-standard VOTableWriters.

Copyright © 2004 CLRC: Central Laboratory of the Research Councils. All rights reserved.