Class CSVWriter

  • All Implemented Interfaces:
    java.lang.Cloneable, Actor, Executable, FiringsRecordable, Initializable, TypedActor, Changeable, Debuggable, DebugListener, Derivable, Instantiable, ModelErrorHandler, MoMLExportable, Moveable, Nameable

    public class CSVWriter
    extends LineWriter

    This actor reads record-valued input tokens and writes them, one line at a time, to a specified file, as comma-separated list (or separated by some other delimiter given by the separator parameter). The first line contains the names of the fields of the input record, separated by the same delimiter.

    The file is specified by the fileName attribute using any form acceptable to FileParameter.

    If the append attribute has value true, then the file will be appended to. If it has value false, then if the file exists, the user will be queried for permission to overwrite, and if granted, the file will be overwritten.

    If the confirmOverwrite parameter has value false, then this actor will overwrite the specified file if it exists without asking. If true (the default), then if the file exists, then this actor will ask for confirmation before overwriting.

    Since:
    Ptolemy II 10.0
    Version:
    $Id$
    Author:
    Edward A. Lee
    See Also:
    FileParameter, ExpressionWriter
    Pt.AcceptedRating:
    Red (cxh)
    Pt.ProposedRating:
    Yellow (eal)
    • Field Detail

      • separator

        public StringParameter separator
        A specification of the separator between items in the table. The default is "comma", which results in assuming that fields are separated by commas. If the value is changed to "tab", then a tab separator will be used. If the value is "semicolon", then a semicolon separator will be used. If the value is anything else, then the value of the parameter, whatever it is, will be the separator.
    • Method Detail

      • attributeChanged

        public void attributeChanged​(Attribute attribute)
                              throws IllegalActionException
        If the specified attribute is separator then set a local variable with the value of the separator.
        Overrides:
        attributeChanged in class LineWriter
        Parameters:
        attribute - The attribute that has changed.
        Throws:
        IllegalActionException - If the specified attribute is fileOrURL and the file cannot be opened, or the previously opened file cannot be closed; or if the attribute is numberOfLinesToSkip and its value is negative.
      • clone

        public java.lang.Object clone​(Workspace workspace)
                               throws java.lang.CloneNotSupportedException
        Clone the actor into the specified workspace. This calls the base class and then sets the type constraints on the input.
        Overrides:
        clone in class LineWriter
        Parameters:
        workspace - The workspace for the new object.
        Returns:
        A new actor.
        Throws:
        java.lang.CloneNotSupportedException - If a derived class contains an attribute that cannot be cloned.
        See Also:
        NamedObj.exportMoML(Writer, int, String), NamedObj.setDeferringChangeRequests(boolean)