org.apache.jmeter.report.core

## Class CsvSampleWriter

- java.lang.Object
- - org.apache.jmeter.report.core.SampleWriter
  - - org.apache.jmeter.report.core.AbstractSampleWriter
    - - org.apache.jmeter.report.core.CsvSampleWriter

- All Implemented Interfaces:
    Closeable, AutoCloseable

      public class CsvSampleWriter
      extends AbstractSampleWriter

  Class to be used to write samples to a csv destination (OutputStream, Writer or a File).

  This class handles csv header writing with the `writeHeader` method. This method has to be called by user for the header to be written.

  Since:
    3.0

- - ### Field Summary

    - ### Fields inherited from class org.apache.jmeter.report.core.AbstractSampleWriter

      `writer`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CsvSampleWriter(File output, SampleMetadata metadata)` Constructor for a CsvSampleWriter.
    `CsvSampleWriter(OutputStream output, SampleMetadata metadata)` Constructor for a CsvSampleWriter.
    `CsvSampleWriter(SampleMetadata metadata)` Constructor for a CsvSampleWriter.
    `CsvSampleWriter(Writer output, SampleMetadata metadata)` Constructor for a CsvSampleWriter.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `setSeparator(char separator)` Set the char to use for separation of data in a line.
    `void` | `setWriter(Writer writer)` Set the new writer on which samples will be written by this sample writer.
    `long` | `write(Sample sample)` Write a sample to the underlying destination
    `void` | `writeHeader()` Write the csv header.

    - ### Methods inherited from class org.apache.jmeter.report.core.AbstractSampleWriter

      `close, setOutputFile, setOutputStream`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### CsvSampleWriter

          public CsvSampleWriter(SampleMetadata metadata)

      Constructor for a CsvSampleWriter.
      The newly created instance has to be supplied with a Writer to work properly.
      Parameters:
        `metadata` - the description for data that this writer will write. ( `metadata` must not be `null`.)

    - #### CsvSampleWriter

          public CsvSampleWriter(Writer output,
                                 SampleMetadata metadata)

      Constructor for a CsvSampleWriter.
      Parameters:
        `output` - the writer to write data to. (Must not be `null`)
        `metadata` - the description for data that this writer will write. ( `metadata` must not be `null`.)

    - #### CsvSampleWriter

          public CsvSampleWriter(OutputStream output,
                                 SampleMetadata metadata)

      Constructor for a CsvSampleWriter.
      Parameters:
        `output` - the output stream to write data to. (Must not be `null`)
        `metadata` - the description for data that this writer will write. ( `metadata` must not be `null`.)

    - #### CsvSampleWriter

          public CsvSampleWriter(File output,
                                 SampleMetadata metadata)

      Constructor for a CsvSampleWriter.
      Parameters:
        `output` - the output file to write data to. (Must not be `null`)
        `metadata` - the description for data that this writer will write. ( `metadata` must not be `null`.)

  - ### Method Detail

    - #### setSeparator

          public void setSeparator(char separator)

      Set the char to use for separation of data in a line.
      Parameters:
        `separator` - to use

    - #### setWriter

          public void setWriter(Writer writer)

      Description copied from class: `AbstractSampleWriter`
      Set the new writer on which samples will be written by this sample writer.
      If any writer exists on the sample writer, it is flushed and closed before being replaced by the new one.
      Overrides:
        `setWriter` in class `AbstractSampleWriter`
      Parameters:
        `writer` - The destination writer where samples will be written by this sample writer

    - #### writeHeader

          public void writeHeader()

      Write the csv header. If samples have alredy been written then a row with header information will be written in the middle of the file.

    - #### write

          public long write(Sample sample)

      Description copied from class: `SampleWriter`
      Write a sample to the underlying destination
      Specified by:
        `write` in class `SampleWriter`
      Parameters:
        `sample` - The sample to be written (Must not be `null`)
      Returns:
        The number of samples written at this time to the underlying destination

Copyright © 1998-2017 Apache Software Foundation. All Rights Reserved.