uk.ac.starlink.table.formats
Class CsvTableWriter

java.lang.Object
  extended byuk.ac.starlink.table.StreamStarTableWriter
      extended byuk.ac.starlink.table.formats.CsvTableWriter
All Implemented Interfaces:
StarTableWriter

public class CsvTableWriter
extends StreamStarTableWriter

A StarTableWriter which outputs to Comma-Separated Value format. This format is readable by CsvTableBuilder.

Since:
21 Sep 2004

Constructor Summary
CsvTableWriter()
          Constructs a default CSV table writer.
CsvTableWriter(boolean writeHeader)
          Constructs a CSV table writer which optionally writes headers.
 
Method Summary
 String getFormatName()
          Returns "CSV" or "CSV-noheader".
 String getMimeType()
          Returns a string suitable for use as the value of a MIME Content-Type header.
static StarTableWriter[] getStarTableWriters()
          Returns a selection of useful CsvTableWriters.
 boolean getWriteHeader()
          Indicates whether an initial row containing column names will be written.
 boolean looksLikeFile(String location)
          Returns true for locations ending ".csv" or ".CSV".
 void setWriteHeader(boolean writeHeader)
          Indicate whether an initial row containing column names should be written.
 void writeStarTable(StarTable table, OutputStream ostrm)
          Writes a StarTable object to a given output stream.
 
Methods inherited from class uk.ac.starlink.table.StreamStarTableWriter
writeStarTable
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CsvTableWriter

public CsvTableWriter()
Constructs a default CSV table writer. This doesn't write a header.


CsvTableWriter

public CsvTableWriter(boolean writeHeader)
Constructs a CSV table writer which optionally writes headers.

Parameters:
writeHeader - true iff you want the first output line to contain column names
Method Detail

setWriteHeader

public void setWriteHeader(boolean writeHeader)
Indicate whether an initial row containing column names should be written.

Parameters:
writeHeader - true iff you want the first output line to contain column names

getWriteHeader

public boolean getWriteHeader()
Indicates whether an initial row containing column names will be written.

Returns:
whether the first output line will contain column names

getFormatName

public String getFormatName()
Returns "CSV" or "CSV-noheader".

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.

Returns:
MIME content type

looksLikeFile

public boolean looksLikeFile(String location)
Returns true for locations ending ".csv" or ".CSV".

Parameters:
location - the location name (probably filename)
Returns:
true iff it looks like a file this writer would normally write

writeStarTable

public void writeStarTable(StarTable table,
                           OutputStream ostrm)
                    throws IOException
Description copied from interface: StarTableWriter
Writes a StarTable object to a given output stream. The implementation can assume that out is suitable for direct writing (for instance it should not normally wrap it in a BufferedOutputStream), and should not close it at the end of the call.

Not all table writers are capable of writing to a stream; an implementation may throw a TableFormatException to indicate that it cannot do so.

Parameters:
table - the table to write
ostrm - the output stream to which startab should be written
Throws:
IOException - if there is some I/O error

getStarTableWriters

public static StarTableWriter[] getStarTableWriters()
Returns a selection of useful CsvTableWriters.

Returns:
array containing one writer with headers and one without

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