Class 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
    Author:
    Mark Taylor (Starlink)
    • Constructor Summary

      Constructors 
      Constructor Description
      CsvTableWriter()
      Constructs a default CSV table writer.
      CsvTableWriter​(boolean writeHeader)
      Constructs a CSV table writer which optionally writes headers.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getFormatName()
      Returns "CSV" or "CSV-noheader".
      int getMaxFieldChars()
      Returns the limit on the number of characters that will be written in a single field.
      java.lang.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​(java.lang.String location)
      Returns true for locations ending ".csv" or ".CSV".
      void setMaxFieldChars​(int maxFieldChars)
      Sets a limit on the number of characters that will be written in a single field.
      void setWriteHeader​(boolean writeHeader)
      Indicate whether an initial row containing column names should be written.
      void writeStarTable​(StarTable table, java.io.OutputStream ostrm)
      Writes a StarTable object to a given output stream.
      • 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
      • setMaxFieldChars

        public void setMaxFieldChars​(int maxFieldChars)
        Sets a limit on the number of characters that will be written in a single field. Fields beyond this length will be truncated.
        Parameters:
        maxFieldChars - new limit
      • getMaxFieldChars

        public int getMaxFieldChars()
        Returns the limit on the number of characters that will be written in a single field. Fields beyond this length will be truncated.
        Returns:
        current limit
      • getFormatName

        public java.lang.String getFormatName()
        Returns "CSV" or "CSV-noheader".
        Returns:
        a short string identifying the output format of this writer
      • getMimeType

        public java.lang.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​(java.lang.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,
                                   java.io.OutputStream ostrm)
                            throws java.io.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:
        TableFormatException - if this table cannot be written to a stream
        java.io.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