org.apache.jmeter.save

## Class CSVSaveService

- java.lang.Object
- - org.apache.jmeter.save.CSVSaveService

-     public final class CSVSaveService
      extends java.lang.Object

  This class provides a means for saving/reading test results as CSV files.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `CSV_BYTES`
    `static java.lang.String` | `CSV_CONNECT_TIME`
    `static java.lang.String` | `CSV_ELAPSED`
    `static java.lang.String` | `CSV_ENCODING`
    `static java.lang.String` | `CSV_ERROR_COUNT`
    `static java.lang.String` | `CSV_FILENAME`
    `static java.lang.String` | `CSV_HOSTNAME`
    `static java.lang.String` | `CSV_IDLETIME`
    `static java.lang.String` | `CSV_LATENCY`
    `static java.lang.String` | `CSV_SAMPLE_COUNT`
    `static java.lang.String` | `CSV_SENT_BYTES`
    `static java.lang.String` | `CSV_THREAD_COUNT1`
    `static java.lang.String` | `CSV_THREAD_COUNT2`
    `static java.lang.String` | `CSV_URL`
    `static java.lang.String` | `DATA_TYPE`
    `static java.lang.String` | `FAILURE_MESSAGE`
    `static java.lang.String` | `LABEL`
    `static char` | `QUOTING_CHAR`
    `static java.lang.String` | `RESPONSE_CODE`
    `static java.lang.String` | `RESPONSE_MESSAGE`
    `static java.lang.String` | `SUCCESSFUL`
    `static java.lang.String` | `THREAD_NAME`
    `static java.lang.String` | `TIME_STAMP`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static java.lang.String[]` | `csvReadFile(java.io.BufferedReader infile, char delim)` Reads from file and splits input into strings according to the delimiter, taking note of quoted strings.
    `static java.lang.String[]` | `csvSplitString(java.lang.String line, char delim)` Reads from String and splits into strings according to the delimiter, taking note of quoted strings.
    `static SampleSaveConfiguration` | `getSampleSaveConfiguration(java.lang.String headerLine, java.lang.String filename)` Parse a CSV header line
    `static java.lang.String` | `printableFieldNamesToString()` Generates the field names for the output file
    `static java.lang.String` | `printableFieldNamesToString(SampleSaveConfiguration saveConfig)` Generates the field names for the output file
    `static void` | `processSamples(java.lang.String filename, Visualizer visualizer, ResultCollector resultCollector)` Read Samples from a file; handles quoted strings.
    `static java.lang.String` | `quoteDelimiters(java.lang.String input, char[] specialChars)` Returns a `String` value for a character-delimited column value enclosed in the quote character, if required.
    `static java.lang.String` | `resultToDelimitedString(SampleEvent event)` Convert a result into a string, where the fields of the result are separated by the default delimiter.
    `static java.lang.String` | `resultToDelimitedString(SampleEvent event, java.lang.String delimiter)` Convert a result into a string, where the fields of the result are separated by a specified String.
    `static void` | `saveCSVStats(javax.swing.table.DefaultTableModel model, java.io.FileWriter writer)` Method saves aggregate statistics (with header names) as CSV from a table model.
    `static void` | `saveCSVStats(javax.swing.table.DefaultTableModel model, java.io.FileWriter writer, boolean saveHeaders)` Method saves aggregate statistics as CSV from a table model.
    `static void` | `saveCSVStats(java.util.List<?> data, java.io.Writer writer)` Method will save aggregate statistics as CSV.
    `static void` | `saveCSVStats(java.util.List<?> data, java.io.Writer writer, java.lang.String[] headers)` Method will save aggregate statistics as CSV.

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

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

- - ### Field Detail

    - #### DATA_TYPE

          public static final java.lang.String DATA_TYPE

      See Also:
        Constant Field Values

    - #### FAILURE_MESSAGE

          public static final java.lang.String FAILURE_MESSAGE

      See Also:
        Constant Field Values

    - #### LABEL

          public static final java.lang.String LABEL

      See Also:
        Constant Field Values

    - #### RESPONSE_CODE

          public static final java.lang.String RESPONSE_CODE

      See Also:
        Constant Field Values

    - #### RESPONSE_MESSAGE

          public static final java.lang.String RESPONSE_MESSAGE

      See Also:
        Constant Field Values

    - #### SUCCESSFUL

          public static final java.lang.String SUCCESSFUL

      See Also:
        Constant Field Values

    - #### THREAD_NAME

          public static final java.lang.String THREAD_NAME

      See Also:
        Constant Field Values

    - #### TIME_STAMP

          public static final java.lang.String TIME_STAMP

      See Also:
        Constant Field Values

    - #### CSV_ELAPSED

          public static final java.lang.String CSV_ELAPSED

      See Also:
        Constant Field Values

    - #### CSV_BYTES

          public static final java.lang.String CSV_BYTES

      See Also:
        Constant Field Values

    - #### CSV_SENT_BYTES

          public static final java.lang.String CSV_SENT_BYTES

      See Also:
        Constant Field Values

    - #### CSV_THREAD_COUNT1

          public static final java.lang.String CSV_THREAD_COUNT1

      See Also:
        Constant Field Values

    - #### CSV_THREAD_COUNT2

          public static final java.lang.String CSV_THREAD_COUNT2

      See Also:
        Constant Field Values

    - #### CSV_SAMPLE_COUNT

          public static final java.lang.String CSV_SAMPLE_COUNT

      See Also:
        Constant Field Values

    - #### CSV_ERROR_COUNT

          public static final java.lang.String CSV_ERROR_COUNT

      See Also:
        Constant Field Values

    - #### CSV_URL

          public static final java.lang.String CSV_URL

      See Also:
        Constant Field Values

    - #### CSV_FILENAME

          public static final java.lang.String CSV_FILENAME

      See Also:
        Constant Field Values

    - #### CSV_LATENCY

          public static final java.lang.String CSV_LATENCY

      See Also:
        Constant Field Values

    - #### CSV_CONNECT_TIME

          public static final java.lang.String CSV_CONNECT_TIME

      See Also:
        Constant Field Values

    - #### CSV_ENCODING

          public static final java.lang.String CSV_ENCODING

      See Also:
        Constant Field Values

    - #### CSV_HOSTNAME

          public static final java.lang.String CSV_HOSTNAME

      See Also:
        Constant Field Values

    - #### CSV_IDLETIME

          public static final java.lang.String CSV_IDLETIME

      See Also:
        Constant Field Values

    - #### QUOTING_CHAR

          public static final char QUOTING_CHAR

      See Also:
        Constant Field Values

  - ### Method Detail

    - #### processSamples

          public static void processSamples(java.lang.String filename,
                                            Visualizer visualizer,
                                            ResultCollector resultCollector)
                                     throws java.io.IOException

      Read Samples from a file; handles quoted strings.
      Parameters:
        `filename` - input file
        `visualizer` - where to send the results
        `resultCollector` - the parent collector
      Throws:
        `java.io.IOException` - when the file referenced by `filename` can't be read correctly

    - #### printableFieldNamesToString

          public static java.lang.String printableFieldNamesToString()

      Generates the field names for the output file
      Returns:
        the field names as a string

    - #### printableFieldNamesToString

          public static java.lang.String printableFieldNamesToString(SampleSaveConfiguration saveConfig)

      Generates the field names for the output file
      Parameters:
        `saveConfig` - the configuration of what is to be saved
      Returns:
        the field names as a string

    - #### getSampleSaveConfiguration

          public static SampleSaveConfiguration getSampleSaveConfiguration(java.lang.String headerLine,
                                                                           java.lang.String filename)

      Parse a CSV header line
      Parameters:
        `headerLine` - from CSV file
        `filename` - name of file (for log message only)
      Returns:
        config corresponding to the header items found or null if not a header line

    - #### saveCSVStats

          public static void saveCSVStats(java.util.List<?> data,
                                          java.io.Writer writer)
                                   throws java.io.IOException

      Method will save aggregate statistics as CSV. For now I put it here. Not sure if it should go in the newer SaveService instead of here. if we ever decide to get rid of this class, we'll need to move this method to the new save service.
      Parameters:
        `data` - List of data rows
        `writer` - output writer
      Throws:
        `java.io.IOException` - when writing to `writer` fails

    - #### saveCSVStats

          public static void saveCSVStats(java.util.List<?> data,
                                          java.io.Writer writer,
                                          java.lang.String[] headers)
                                   throws java.io.IOException

      Method will save aggregate statistics as CSV. For now I put it here. Not sure if it should go in the newer SaveService instead of here. if we ever decide to get rid of this class, we'll need to move this method to the new save service.
      Parameters:
        `data` - List of data rows
        `writer` - output file
        `headers` - header names (if non-null)
      Throws:
        `java.io.IOException` - when writing to `writer` fails

    - #### saveCSVStats

          public static void saveCSVStats(javax.swing.table.DefaultTableModel model,
                                          java.io.FileWriter writer)
                                   throws java.io.IOException

      Method saves aggregate statistics (with header names) as CSV from a table model. Same as `saveCSVStats(List, Writer, String[])` except that there is no need to create a List containing the data.
      Parameters:
        `model` - table model containing the data
        `writer` - output file
      Throws:
        `java.io.IOException` - when writing to `writer` fails

    - #### saveCSVStats

          public static void saveCSVStats(javax.swing.table.DefaultTableModel model,
                                          java.io.FileWriter writer,
                                          boolean saveHeaders)
                                   throws java.io.IOException

      Method saves aggregate statistics as CSV from a table model. Same as `saveCSVStats(List, Writer, String[])` except that there is no need to create a List containing the data.
      Parameters:
        `model` - table model containing the data
        `writer` - output file
        `saveHeaders` - whether or not to save headers
      Throws:
        `java.io.IOException` - when writing to `writer` fails

    - #### resultToDelimitedString

          public static java.lang.String resultToDelimitedString(SampleEvent event)

      Convert a result into a string, where the fields of the result are separated by the default delimiter.
      Parameters:
        `event` - the sample event to be converted
      Returns:
        the separated value representation of the result

    - #### resultToDelimitedString

          public static java.lang.String resultToDelimitedString(SampleEvent event,
                                                                 java.lang.String delimiter)

      Convert a result into a string, where the fields of the result are separated by a specified String.
      Parameters:
        `event` - the sample event to be converted
        `delimiter` - the separation string
      Returns:
        the separated value representation of the result

    - #### quoteDelimiters

          public static java.lang.String quoteDelimiters(java.lang.String input,
                                                         char[] specialChars)

      Returns a `String` value for a character-delimited column value enclosed in the quote character, if required.

      If the value contains a special character, then the String value is returned enclosed in the quote character.

      Any quote characters in the value are doubled up.

      If the value does not contain any special characters, then the String value is returned unchanged.

      N.B. The list of special characters includes the quote character.

      Parameters:
        `input` - the input column String, may be null (without enclosing delimiters)
        `specialChars` - special characters; second one must be the quote character
      Returns:
        the input String, enclosed in quote characters if the value contains a special character, `null` for null string input

    - #### csvReadFile

          public static java.lang.String[] csvReadFile(java.io.BufferedReader infile,
                                                       char delim)
                                                throws java.io.IOException

      Reads from file and splits input into strings according to the delimiter, taking note of quoted strings.

      Handles DOS (CRLF), Unix (LF), and Mac (CR) line-endings equally.

      A blank line - or a quoted blank line - both return an array containing a single empty String.

      Parameters:
        `infile` - input file - must support mark(1)
        `delim` - delimiter (e.g. comma)
      Returns:
        array of strings, will be empty if there is no data, i.e. if the input is at EOF.
      Throws:
        `java.io.IOException` - also for unexpected quote characters

    - #### csvSplitString

          public static java.lang.String[] csvSplitString(java.lang.String line,
                                                          char delim)
                                                   throws java.io.IOException

      Reads from String and splits into strings according to the delimiter, taking note of quoted strings. Handles DOS (CRLF), Unix (LF), and Mac (CR) line-endings equally.
      Parameters:
        `line` - input line - not `null`
        `delim` - delimiter (e.g. comma)
      Returns:
        array of strings
      Throws:
        `java.io.IOException` - also for unexpected quote characters

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